OpenCV
Z Varhoo
(Rozdíly mezi verzemi)
m (→Vytvoření výřezu obrázku) |
|||
| (Není zobrazena 1 mezilehlá verze od 1 uživatele.) | |||
| Řá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; |
||
| + | } |
||
| + | |||
| + | /* 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; |
||
| + | } |
||
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;
}