问题描述
- 图像加减运算,为什么输出结果不对
-
#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;
}
解决方案
图像加减运算,为什么输出结果不对
解决方案二:
请问你下面的图是怎么弄的啊,我发问题,图片总是看不清
时间: 2024-11-05 23:57:58