OpenCV学习笔记8_ShowROI_显示感兴趣区域
ShowROI_显示感兴趣区域
ShowROI.c 用复制替换图层,替换出自己感兴趣的ROI
#include "stdafx.h" #include "cv.h" #include "highgui.h" #include "cxcore.h" int main() { IplImage* img; img = cvLoadImage("E:\\TempDataForDebug\\tomato1.jpg"); IplImage* sub_image = cvLoadImage("E:\\TempDataForDebug\\bee.jpg"); CvRect rect; rect.x = 400; rect.y = 23; rect.width = sub_image->width; rect.height = sub_image->height; cvSetImageROI(img, rect); cvCopy(sub_image, img); cvResetImageROI(img);
cvNamedWindow("sub"); cvShowImage("sub",sub_image);
cvNamedWindow("1");
cvShowImage("1",img);
cvWaitKey(0);
return 0;
}
ShowROI.c 改进版,用指针偏移,像素替换
#include "stdafx.h" #include "cv.h" #include "highgui.h" #include "cxcore.h" int main() { IplImage* img; img = cvLoadImage("E:\\TempDataForDebug\\tomato1.jpg"); IplImage* sub_image = cvLoadImage("E:\\TempDataForDebug\\bee.jpg"); CvRect rect; rect.x = 400; rect.y = 23; rect.width = sub_image->width; rect.height = sub_image->height; int y,x; for (y = 0; y<sub_image->height; y++) { unsigned char* subImgData = (unsigned char*)(sub_image->imageData+y*sub_image->widthStep); unsigned char* bigImgData = (unsigned char*)(img->imageData+(y+rect.y)*img->widthStep); for (x = 0; x<sub_image->width; x++) { bigImgData[3*(x+rect.x) + 0] = subImgData[3*x + 0]; bigImgData[3*(x+rect.x) + 1] = subImgData[3*x + 1]; bigImgData[3*(x+rect.x) + 2] = subImgData[3*x + 2]; } } cvNamedWindow("sub"); cvShowImage("sub",sub_image); cvNamedWindow("1"); cvShowImage("1",img); cvWaitKey(0); return 0; }
Best Regards To Reader:
==============================================
Royal Kao(高全宁)
Mob: 13771921045
Mail: gaoquanning@163.com
Blog: http://www.cnblogs.com/gaoquanning/
==============================================