为一个图像创建多个图像头。读取一个大小至少为100×100的图像。另创建两个图像头并设置它们的origion,depth,nChannels和widthStep属性同之前读取的图像一样。在新的图像头中,设置宽度为20,高度为30。最后,将imageData指针分别指向像素(5,10)和(50,60)像素位置。传递这两个新的图像头给cvNot()。最后显示最初读取的图像,在那个大图像中应该有两个矩形,矩形内的值是原始值的求反值。
// 练习3-6(104).cpp : 定义控制台应用程序的入口点。
//
#include "stdafx.h"
#include "cv.h"
#include "highgui.h"
int main()
{
IplImage *Image=cvLoadImage("1.jpg");
IplImage *dst1,*dst2;
dst1=cvCreateImage(cvSize(20,30),Image->depth,Image->nChannels);
dst1->origin=Image->origin;
dst1->widthStep=Image->widthStep;
dst2=cvCreateImage(cvSize(20,30),Image->depth,Image->nChannels);
dst2->origin=Image->origin;
dst2->widthStep=Image->widthStep;
dst1->imageData=Image->imageData+10*Image->widthStep+5*Image->nChannels;
dst2->imageData=Image->imageData+60*Image->widthStep+50*Image->nChannels;
cvNot(dst1,dst1); //将选中图像区域每一位取反,将结果赋给后面的dst1
cvNot(dst2,dst2);
cvNamedWindow("Image",1);
cvShowImage("Image",Image);
cvWaitKey(0);
cvReleaseImage(&Image);
cvReleaseImage(&dst1);
cvReleaseImage(&dst2);
cvDestroyWindow("Image");
return 0;
}