box.cpp

来自「opencv codes in C++ (linux and eclipse)」· C++ 代码 · 共 54 行

CPP
54
字号
//opencv c++ code to create an image with a rectangle crossing vertical yellow //line from bottom corner to top corner#include "cv.h" #include "highgui.h" int main(){ /* LINE */ 	int key;	   	IplImage* img = cvCreateImage(cvSize(500,500), 8, 3);  /*create new image to display line and rectangle*/ 	CvPoint x1 = cvPoint(250,0); /*coordinates of the line */ 	CvPoint y1 = cvPoint (250,495);  	CvScalar color = CV_RGB(255,255,0);  /*line color */  	cvLine(img, x1,y1,color,20,CV_AA,0); /*line, CV_AA means Anti Aliasing*/  	 	for (int i = 100; i<=300; i++) 	{ 		 CvPoint a1 = cvPoint(i,350-i); 		 CvPoint b1 = cvPoint (i+100,450-i); 		 cvRectangle( img, a1, b1, CV_RGB(204,255,255), CV_FILLED ); 		 cvNamedWindow("Line",1); 		 cvShowImage("Line", img); 		 key = cvWaitKey(3); 		 cvSaveImage("Resultant-Line.jpg",img); 		 cvRectangle( img, a1, b1, CV_RGB(0,0,0), CV_FILLED ); 		 cvLine(img, x1,y1,color,20,CV_AA,0);  		   		 	}   	      /* saving the image in a new file named ResultantLine,jpg */ 	cvSaveImage("ResultantLine.jpg",img);  	 	//wait for key to close the window 	cvWaitKey(0);  	/* destroy and release image*/ 	cvDestroyWindow( "Line" ); 	cvReleaseImage( &img); 	return 0; }

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?