C++ OpenCV,将像素块从图像映射到图像时的噪波

C++ OpenCV,将像素块从图像映射到图像时的噪波,c++,opencv,mapping,pixel,copying,C++,Opencv,Mapping,Pixel,Copying,我从一个图像复制一块像素到另一个图像,因此我没有得到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 = (i

我从一个图像复制一块像素到另一个图像,因此我没有得到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++); 
            }
        }
}
void templateCut(IplImage*ptr2Img、IplImage*tempCut、CvBox2D*boundingBox)
{ 
/*目标BB的左上角*/
int col1=(int)boundingBox->center.x;
int row1=(int)边界框->中心.y;
for(int i=0;iheight;i++)
{       
/*指向行的指针*/
uchar*ptrImgBB=(uchar*)(ptr2Img->imageData+(行1+i)*ptr2Img->widthStep+col1);
uchar*ptrTemp=(uchar*)(tempCut->imageData+i*tempCut->widthStep);
for(int i2=0;i2width;i2++)
{
*ptrTemp++=(*ptrImgBB++);
}
}
}

是单通道图像还是多通道图像(如RGB)?如果它是多通道图像,则必须考虑循环中的信道索引。 顺便说一句:OpenCV支持感兴趣区域(ROI),这将方便您实现复制图像的子区域。下面是您可以在OpenCV中找到ROI使用信息的链接

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

您应该为感兴趣的编程语言添加一个标记。我认为这是C代码,对吧?C++。谢谢你的评论。我想opencv已经足够了。看起来你使用的是旧的C接口。如果已安装OpenCV 2,则应使用Mat,而不是IplImage。很抱歉,浏览器将括号“()”转换为URL格式,这是不正确的。我已经在上面进行了硬编码。在新的C++接口中定义不同的感兴趣区域。只需通过向现有Mat对象传递Rect来创建Mat对象:
Mat img=imread(“image.jpg”);rectr(10,10100100);Mat smallImg=img(r)是的,新版本的opencv引入了许多新的数据结构,并且更加面向对象。但问题中的代码似乎来自旧的编码风格。