0

问题解决了......我使用了cvGet2D,下面是示例代码

        CvScalar s;
        s=cvGet2D(src_Image,pixel[i].x,pixel[i].y);         
        cvSet2D(dst_Image,pixel[i].x,pixel[i].y,s);

其中 src_Iamge 和 dst_Image 分别是源图像和目标图像,而 pixel[i] 是我想在 dst 图像中绘制的选定像素。我在下面包含了真实的图像。

有一个源 Ipl 图像,我想将图像的某些部分逐个像素复制到新的目标图像。任何人都可以告诉我怎么做吗?我在opencv中使用c,c ++。例如,如果下面的图像是源图像, 在此处输入图像描述

真实输出图像在此处输入图像描述

4

2 回答 2

1

EDIT:

I can see the comments suggesting cvGet2d. I think, if you just want to show "points", it is best to show them with a small neighbourhood so they can be seen where they are. For that you can draw white filled circles with origins at (x,y), on a mask, then you do the copyTo.

using namespace cv;

Mat m(input_iplimage);
Mat mask=Mat::zeros(m.size(), CV_8UC1);

p1 = Point(x,y); 
r = 3;
circle(mask,p1,r, 1); // draws the circle around your point.
floodFill(mask, p1, 1); // fills the circle.

//p2, p3, ...

Mat output = Mat::zeros(m.size(),m.type()); // output starts with a black background.
m.copyTo(output, mask); // copies the selected parts of m to output     

OLD post:

Create a mask and copy those pixels:

#include<opencv2/opencv.hpp>
using namespace cv;

Mat m(input_iplimage);
Mat mask=Mat::zeros(m.size(), CV_8UC1); // set mask 1 for every pixel you wanna copy.
Rect roi=Rect(x,y,width,height);  // create a rectangle
mask(roi) = 1;   // set it to 0.
roi = Rect(x2,y2,w2,h2);
mask(roi)=1;     // set the second rectangular area for copying...

Mat output = 100*Mat::ones(m.size(),m.type()); // output with a gray background.
m.copyTo(output, mask); // copy selected areas of m to output

Alternatively you can copy Rect-by-Rect:

Mat m(input_iplimage);
Mat output = 100*Mat::ones(m.size(),m.type()); // output with a gray background.

Rect roi=Rect(x,y,width,height);
Mat m_temp, out_temp;
m_temp=m(roi);
out_temp = output(roi);
m_temp.copyTo(out_temp);

roi=Rect(x2,y2,w2,h2);
Mat m_temp, out_temp;
m_temp=m(roi);
out_temp = output(roi);
m_temp.copyTo(out_temp);
于 2012-11-22T17:24:40.440 回答
0

您的问题的答案只需要查看 OpenCV 文档或在您最喜欢的搜索引擎中进行搜索。

在这里,您可以获得 Ipl 图像和较新的 Mat 数据的答案。

为了获得我在您的图像中看到的输出,我会设置 ROI,这样会更有效。

于 2012-11-22T12:08:49.550 回答