gpt4 book ai didi

c++ - 逐像素复制 IPL 图像

转载 作者:行者123 更新时间:2023-11-28 07:52:23 25 4
gpt4 key购买 nike

问题解决了....我用的是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++。例如,如果下图是源图像,enter image description here

真实输出图像enter image description here

最佳答案

编辑:

我可以看到建议使用 cvGet2d 的评论。我认为,如果你只是想显示“点”,最好用一个小的邻域来显示它们,这样就可以看到它们在哪里。为此,您可以在蒙版上绘制原点为 (x,y) 的白色实心圆,然后执行 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

旧帖:

创建一个 mask 并复制这些像素:

#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

或者,您可以逐个复制:

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);

关于c++ - 逐像素复制 IPL 图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13508664/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com