-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtRoi.cpp
More file actions
28 lines (26 loc) · 1.1 KB
/
tRoi.cpp
File metadata and controls
28 lines (26 loc) · 1.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
// Show how to operate on ROI.
// Note: cvSetImageROI can only be done serially and must be set and reset constantly. So createSubImage is defined.
// cook, 9/4 2009.
#include <opencv/highgui.h>
IplImage* createSubImage(CvSize size, IplImage* image) {
IplImage *sub_img = cvCreateImageHeader(cvSize(image->width/3, image->height/3), image->depth, image->nChannels);
sub_img->origin = image->origin;
sub_img->widthStep = image->widthStep;
sub_img->imageData = image->imageData +
(image->height - image->height/3) * image->widthStep +
(image->width - image->width/3) * image->nChannels;
return sub_img;
}
int main(int argc, char** argv) {
IplImage* image = cvLoadImage(argv[1]);
IplImage* another_sub_img = createSubImage(cvSize(image->width/3, image->height/3), image);
cvSetImageROI(image, cvRect(0, 0, image->width / 3, image->height / 3));
cvAddS(image, cvScalar(50), image); // add scalar
cvAddS(another_sub_img, cvScalar(100), another_sub_img);
cvResetImageROI(image);
cvNamedWindow("ROI Example", CV_WINDOW_AUTOSIZE);
cvShowImage("ROI Example", image);
cvWaitKey();
cvReleaseImage(&image);
return 0;
}