opencv---感兴趣区域(ROI)
程序员文章站
2023-12-25 11:05:45
...
#include "stdafx.h"
#include <opencv.hpp>
using namespace cv;
int _tmain(int argc, _TCHAR* argv[])
{
Mat srcImage1 = imread("pens.bmp",IMREAD_UNCHANGED);
if (!srcImage1.data)
{
printf("Load Image Failed.\n");
return -1;
}
Mat srcImage2;
srcImage2.create(Size(200,200),CV_8UC3);
srcImage2 = Scalar(100,25,225);
//定义Mat类型,并给其设置srcImage1的ROI区域
Mat imageROI = srcImage1(Rect(100,150,srcImage2.cols,srcImage2.rows));
Mat_<Vec3b>::iterator it1 = srcImage2.begin<Vec3b>();
Mat_<Vec3b>::iterator it1end = srcImage2.end<Vec3b>();
Mat_<Vec3b>::iterator it = imageROI.begin<Vec3b>();
Mat_<Vec3b>::iterator itend = imageROI.end<Vec3b>();
for (;it != itend,it1 != it1end;++it,++it1)
{
(*it)[0] = (*it1)[0];
(*it)[1] = (*it1)[1];
(*it)[2] = (*it1)[2];
}
namedWindow("测试窗口");
imshow("测试窗口",srcImage1);
waitKey(0);
return 0;
}