c++ - OpenCV,将一 block 像素从图像映射到图像时的噪声

标签 c++ opencv mapping pixel copying

我正在将一个像素 block 从一个图像复制到另一个图像,结果我没有得到 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++); 
            }
        }
}

最佳答案

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

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

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

关于c++ - OpenCV,将一 block 像素从图像映射到图像时的噪声,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9291967/

相关文章:

c++ - 如何修复 "At least two classes are needed to perform a LDA"?

c# - 使用 AutoMapper 将对象的属性映射到字符串

google-maps - 在 Google map 图 block 顶部绘制 shapefile

sql - Oracle SQL Loader 中的映射字段

c++ - thrift-cpp 的客户端是线程安全的吗?

c++ - C++ 抽象类的问题(我可以在 Java 中完成,但不能在 C++ 中完成!)

python - 将屏幕截图加载到内存中以进行 CV 模板匹配的最快方法

c++ - 对静态变量的更改超出范围? (C++)

c++ - Non-Ivalue in assignment 错误

opencv - SVM 训练 OpenCV