【问题标题】:OpenCV, noise when mapping a a patch of pixels from image to imageOpenCV,将一块像素从图像映射到图像时的噪声
【发布时间】:2012-02-15 10:51:32
【问题描述】:

我正在将一块像素从一个图像复制到另一个图像,因此我没有得到 1:1 的映射,但新图像的强度与源图像相差 1 或 2 个强度级别。

你知道是什么原因造成的吗?

这是代码:

void templateCut ( IplImage* ptr2Img, IplImage* tempCut, CvBox2D* boundingBox ) 
{ 

/* Upper left corner of target's BB */
int col1 = (int)boundingBox->center.x;
int row1 = (int)boundingBox->center.y;

for(int i=0; i<tempCut->height; i++)
        {       
        /* Pointer to a row */
            uchar * ptrImgBB = (uchar*)( ptr2Img->imageData + (row1+i)*ptr2Img->widthStep + col1 );
            uchar * ptrTemp  = (uchar*)( tempCut->imageData + i*tempCut->widthStep );

            for(int i2=0; i2<tempCut->width; i2++)
            {
                *ptrTemp++ = (*ptrImgBB++); 
            }
        }
}

【问题讨论】:

  • 您应该为您感兴趣的编程语言添加一个标签。我认为这是 C 代码,对吧?
  • 它的 c++。谢谢你的评论。
  • 我觉得opencv就够了。
  • 看起来您使用的是较旧的 C 接口。如果你安装了 OpenCV 2,你应该使用 Mat,而不是 IplImage。

标签: c++ opencv mapping pixel copying


【解决方案1】:

是单通道图像还是多通道图像(如RGB)?如果是多通道图像,则必须考虑循环中的通道索引。

顺便说一句:OpenCV 支持感兴趣区域 (ROI),这将方便您实现复制图像的子区域。以下是您可以找到有关 OpenCV 中 ROI 使用信息的链接。

http://nashruddin.com/OpenCV_Region_of_Interest_(ROI)

【讨论】:

  • 很抱歉浏览器将括号“()”转换为不正确的 URL 格式。我已经在上面硬编码了。
  • 在新的 C++ 接口中定义感兴趣区域有所不同。您只需通过将 Rect 传递给现有的 Mat 对象来创建 Mat 对象:Mat img = imread("image.jpg"); Rect r(10, 10, 100, 100); Mat smallImg = img(r);
  • 是的,新版本的opencv引入了很多新的数据结构,更加面向对象。但是问题中发布的代码似乎来自旧的编码风格。
猜你喜欢
  • 2018-04-14
  • 2014-05-22
  • 2017-07-05
  • 1970-01-01
  • 2018-03-28
  • 2012-08-17
  • 1970-01-01
  • 2021-08-02
相关资源
最近更新 更多