0

我正在尝试用另一个图像更改图像的一部分我找不到合并功能所以我只是发生了我可以更改我想用其他图像更改的部分的 rgb 值 RGB 值是否可能

感谢您的建议

4

2 回答 2

3

如果通过更改您的意思是替换,那么您可以使用图像 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);
于 2009-10-19T14:14:35.933 回答
0

你可以尝试这样的事情:

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
于 2009-10-19T09:38:27.687 回答