opencv支持对图像中ROI的内容进行单独操作,利用cvSetImageROI和cvResetImageROI,用法如下:
roi_add <image> <x> <y> <width> <height> <add>
示例代码如下:
#include <cv.h> #include <highgui.h> int main(int argc, char** argv){ IplImage* src; if (argc == 7 && ((src = cvLoadImage(argv[1],CV_LOAD_IMAGE_ANYCOLOR)) != 0)){ int x = atoi(argv[2]); int y = atoi(argv[3]); int width = atoi(argv[4]); int height = atoi(argv[5]); int add = atoi(argv[6]); cvSetImageROI(src, cvRect(x, y, width, height)); cvAddS(src, cvScalar(add,add,add,add), src,NULL); cvResetImageROI(src); cvNamedWindow("roi_add", 1); cvShowImage("roi_add", src); cvWaitKey(0); } return 0; }