2 qq 34614890 qq_34614890 于 2016.05.09 11:03 提问

图像加减运算,为什么输出结果不对

#include
#include
#include
#include

#include

using namespace std;

//图像加减运算
//unsigned char *lpSrc1:原图像1像素指针
//unsigned char *lpSrc2:原图像2像素指针
//unsigned char *lpDst:目标像素指针

int main()
{
IplImage * image1, *image2, *image3;
image1 = cvLoadImage("1.jpg", 0);
image2 = cvLoadImage("2.jpg", 0);
cvNamedWindow("image1", CV_WINDOW_AUTOSIZE);
cvNamedWindow("image2", CV_WINDOW_AUTOSIZE);
cvNamedWindow("image3", CV_WINDOW_AUTOSIZE);
cvSaveImage("1.jpg", image1, 0);
cvSaveImage("2.jpg", image2, 0);
cvShowImage("image1", image1);
cvShowImage("image2", image2);
image3 = cvCreateImage(cvGetSize(image1), image1->depth, 1);

unsigned char *lpSrc1;
unsigned char *lpSrc2;
unsigned char *lpDst;

int i, j;

for ( i = 0; i < image1->height;i++) 

    for ( j = 0; j< image1->width;j++)
    {
        lpSrc1 = (unsigned char *)image1->imageData + i*image1->widthStep + j;


        for (i = 0; i < image2->height;i++)

            for (j = 0; j < image2->width;j++)
            {
                lpSrc2 = (unsigned char *)image2->imageData + i*image2->widthStep + j;


                lpDst = (unsigned char *)image3->imageData + i*image3->widthStep + j;


                if ((*lpSrc1 + *lpSrc2) > 255)
                    *lpDst = 255;
                else
                    *lpDst = (*lpSrc1 + *lpSrc2);

            }
    }




cvShowImage("image3", image3);
cvWaitKey(0);
return 0;

}

2个回答

qq_34614890
qq_34614890   2016.05.09 11:08

图像加减运算,为什么输出结果不对

sinat_34928892
sinat_34928892   2016.05.09 11:16

请问你下面的图是怎么弄的啊,我发问题,图片总是看不清

Csdn user default icon
上传中...
上传图片
插入图片
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!