我正在将一个像素片段从一个图像复制到另一个图像,因此我没有得到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++);
}
}
}
答案 0 :(得分:1)
是单通道图像还是多通道图像(如RGB)?如果是多通道图像,则必须考虑循环中的通道索引。
btw:OpenCV支持感兴趣区域(ROI),方便您实现复制图像的子区域。以下是您可以在OpenCV中找到有关ROI使用情况的信息的链接。
http://nashruddin.com/OpenCV_Region_of_Interest_(ROI)