OpenCV
Z Varhoo
(Rozdíly mezi verzemi)
m |
m (→Vytvoření výřezu obrázku) |
||
Řádka 21: | Řádka 21: | ||
//kontrola delky vyrezu |
//kontrola delky vyrezu |
||
if(src->width < interest_rect.width + interest_rect.x) { |
if(src->width < interest_rect.width + interest_rect.x) { |
||
− | width = src->width - interest_rect.x; |
+ | width = src->width - interest_rect.x; |
} else { |
} else { |
||
width = interest_rect.width; |
width = interest_rect.width; |
||
− | } |
+ | } |
if(src->height < interest_rect.height + interest_rect.y) { |
if(src->height < interest_rect.height + interest_rect.y) { |
||
− | height = src->height - interest_rect.y; |
+ | height = src->height - interest_rect.y; |
} else { |
} else { |
||
− | height = interest_rect.height; |
+ | height = interest_rect.height; |
− | } |
+ | } |
− | |||
− | //printf("\n%d %d\n",width,height); |
||
− | /*printf("rect: %d %d %d %d | %d %d\n",interest_rect.width,interest_rect.height, |
||
− | interest_rect.x,interest_rect.y, src->height, src->width |
||
− | );*/ |
||
/* Create a new image header */ |
/* Create a new image header */ |
||
IplImage* subimg = cvCreateImageHeader( |
IplImage* subimg = cvCreateImageHeader( |
||
cvSize( |
cvSize( |
||
− | width, height |
+ | width, height |
), |
), |
||
src->depth, |
src->depth, |
Aktuální verze z 19. 5. 2011, 00:32
Při překladu je nutné použít v makefilu
`pkg-config opencv --libs` `pkg-config opencv --cflags --libs`
Do hlaviček je pak potřeba knihovny
#include <cv.h> #include <highgui.h>
Vytvoření obrázku
IplImage * img = cvCreateImage(cvSize(640480),IPL_DEPTH_8U,1);
[editovat] Vytvoření výřezu obrázku
IplImage* get_subimage(IplImage* src, CvRect interest_rect) { int width, height; //kontrola delky vyrezu if(src->width < interest_rect.width + interest_rect.x) { width = src->width - interest_rect.x; } else { width = interest_rect.width; } if(src->height < interest_rect.height + interest_rect.y) { height = src->height - interest_rect.y; } else { height = interest_rect.height; } /* Create a new image header */ IplImage* subimg = cvCreateImageHeader( cvSize( width, height ), src->depth, src->nChannels ); /* Mimic the input image */ subimg->origin = src->origin; subimg->widthStep = src->widthStep; /* Points to the interest rectangle */ subimg->imageData = src->imageData + src->widthStep * interest_rect.y + interest_rect.x * src->nChannels; /* And we've got a subimage */ return subimg; }