创建图像头以及取反

为一个图像创建多个图像头。读取一个至少为100*100的图像。另创建两个图像头并设置它们的origion depth nChannels和widthStep属性同之前读取的图像一样。在新的图像头
中,设置宽度为20,高度为30。最后,将imageData指针分别指向像素(5,10)和(50,60)像素位置。传递这两个新的图像头给cvNot()。最后显示最初读取的图像,在那个大图像中应该有两个矩形,矩形内的值是原始值的求反值。

#include "cv.h"
#include "highgui.h"

int main(int argc, char** argv)
{
	IplImage *img;
    img = cvLoadImage("lena.jpg",0);
	
	if(img==NULL){
		printf("图像读取错误!\n");
		exit(0);
	}

	IplImage* dst1 = cvCreateImageHeader(cvSize(20,30),img->depth,img->nChannels);
	IplImage* dst2 = cvCreateImageHeader(cvSize(20,30),img->depth,img->nChannels);

	dst1->origin = img->origin;
	dst2->origin = img->origin;
	dst1->widthStep = img->widthStep;
	dst2->widthStep = img->widthStep;
	dst1->imageData = img->imageData+10*img->widthStep+5*img->nChannels;
	dst2->imageData = img->imageData+60*img->widthStep+50*img->nChannels;

	cvNot(dst1,dst1);
	cvNot(dst2,dst2);

	cvNamedWindow( "OpenCVTest5", CV_WINDOW_AUTOSIZE );
	cvShowImage( "OpenCVTest5", img );
	cvWaitKey();
	cvDestroyWindow("OpenCVTest5");
	cvReleaseImageHeader(&dst1);
	cvReleaseImageHeader(&dst2);
	return 0;
}

  

原文地址:https://www.cnblogs.com/vitah/p/3092115.html