OpenCV
Z Varhoo
(Rozdíly mezi verzemi)
m |
|||
Řádka 11: | Řádka 11: | ||
IplImage * img = cvCreateImage(cvSize(640480),IPL_DEPTH_8U,1); |
IplImage * img = cvCreateImage(cvSize(640480),IPL_DEPTH_8U,1); |
||
+ | |||
+ | |||
+ | ==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; |
||
+ | } |
||
+ | |||
+ | //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 */ |
||
+ | 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; |
||
+ | } |
Verze z 19. 5. 2011, 00:30
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);
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;
}
//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 */ 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; }