我正在将一个像素 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/