//VS2008+opencv2.4 //绘制一个绿色矩形平面 #include "stdafx.h" #include "highgui.h" #include "cv.h" int _tmain(int argc, _TCHAR* argv[]) { cvNamedWindow("ShowImage", CV_WINDOW_AUTOSIZE); //创建矩阵并置零 IplImage* image= cvCreateImage(cvSize(400, 400), IPL_DEPTH_8U, 3); cvZero(image); //画绿色矩形 for(int i=50; i< 350; i++) //画(50, 50)-->(350, 350)的矩形 { uchar* ptr= (uchar*) (image->imageData+ i* image->widthStep); for(int j=50; j< 350; j++) { ptr[3*j]= 0; ptr[3*j+ 1]= 255; ptr[3*j+ 2]= 0; } } cvShowImage("ShowImage", image); cvWaitKey(0); cvReleaseImage(&image); cvDestroyWindow("ShowImage"); return 0; }