【发布时间】:2010-12-07 22:40:37
【问题描述】:
我正在尝试用另一个图像更改图像的一部分 我找不到合并功能 所以我只是发现我可以改变我想用其他图像改变的部分的 rgb 值 RGB 值是否可能
感谢您的建议
【问题讨论】:
标签: c++ c opencv image-manipulation
我正在尝试用另一个图像更改图像的一部分 我找不到合并功能 所以我只是发现我可以改变我想用其他图像改变的部分的 rgb 值 RGB 值是否可能
感谢您的建议
【问题讨论】:
标签: c++ c opencv image-manipulation
如果change你的意思是replace,那么你可以使用图像ROI(感兴趣区域)函数直接替换一个矩形区域您的原始图像与另一个图像的矩形区域非常有效。
假设您的原始图像存储在A 中,并且您想使用图像B 中的像素更改其中的一部分(矩形区域)。
更新:这是 C 中的代码
/**** C ****/
// Acquire Image A and B (here as an example, I'm reading from disk)
IplImage* A = cvLoadImage("image_A.jpg");
IplImage* B = cvLoadImage("image_B.jpg");
// Set the region-of-interest (ROI) for the two images
// such that only the ROI of A and B will be handled
cvSetImageROI(A,cvRect(200,200,128,128));
cvSetImageROI(B,cvRect(0,0,128,128));
// Copy the ROI in B to the ROI in A
cvCopy(B,A);
// Reset the ROI (now the entire image will be handled)
cvResetImageROI(A);
cvResetImageROI(B);
// Display A
cvNamedWindow("Modified A");
cvShowImage("Modified A",A);
cvWaitKey();
// Release the images
cvReleaseImage(&A);
cvReleaseImage(&B);
使用 OpenCV 2.0:
// C++ //
// Images A and B have already been loaded .....
// Region in image A starting from (100,100) of width 200 and height 200
Rect RegionA(100,100,200,200);
// Region in image B starting from (50,50) of width 200 and height 200
Rect RegionB(50,50,200,200);
// No copying, just a reference to the ROI of the image
Mat A_ROI(A,RegionA);
Mar B_ROI(B,RegionB);
// Copy all the pixels in RegionB in B to RegionA to A
B.copyTo(A);
【讨论】:
你可以试试这样的:
CvScalar s = cvGet2D(original_cvimage, x, y); // get the (x,y) pixel value
cvSet2D(new_cvimage, x, y, s); // set the (x,y) pixel value
【讨论】: