Reading data from a TXT file draw a trapezoid on the picture
#include <iostream>#include <opencv2/opencv.hpp>using namespaceCvusing namespace STD;Chars[ +][ -] = {0};//For reading each row of data in a file up to 40 rows per parking space 4 points (8 shaping number 8 lines) to ensure adequate#define N 4 //4 spaces up to four spaces int*num = (int*)malloc(sizeof(int)*(8* N));//8 number of plastic for each parking spacePoint pt[4][4];//A total of four points for four parking spaces can be storedintMain () {Mat src = imread ("1.jpg",1); FILE * FP1 = fopen ("1.txt","R");//Open input file if(FP1 = = NULL) {//exit if the file fails to open puts("Can't open the file!" ");return 0; }//Four spaces determine the four points required for each parking space (in fact, there are eight integer values that constitute four points of pt.x and Pt.y) for(intn =0; N <4; n++)//Four spaces{ for(inti =0; I <8; i++)//Eight integer values per parking space{fscanf(FP1,'%s ', s[8* n + i]); num[8* n + i] = atoi (s[8* n + i]);Eight integer values to be deposited in the corresponding parking spaces} }//Four spaces to determine four vertices per parking space and draw each parking space on the src map for(intn =0; N <4; n++) {//for (int i = 0; i < 8; i++) //{ //Loc[n * 8 + i] = num[8 * n + i]; ////cout << Loc[n * 8 + i] << ""; ////if (i = = 7) //// cout << Endl; //} //assignment of four points per parking spacept[n][0].x = Num[n *8+0]; pt[n][0].Y = Num[n *8+1]; pt[n][1].x = Num[n *8+2]; pt[n][1].Y = Num[n *8+3]; pt[n][2].x = Num[n *8+4]; pt[n][2].Y = Num[n *8+5]; pt[n][3].x = Num[n *8+6]; pt[n][3].Y = Num[n *8+7];//painting parking spacesLine (SRC, pt[n][0], pt[n][1], Cvscalar (0,255,0,0),1, CV_AA,0); Line (SRC, pt[n][0], pt[n][2], Cvscalar (0,255,0,0),1, CV_AA,0); Line (SRC, pt[n][3], pt[n][1], Cvscalar (0,255,0,0),1, CV_AA,0); Line (SRC, pt[n][3], pt[n][2], Cvscalar (0,255,0,0),1, CV_AA,0); Imshow ("RECT", SRC);//waitkey (ten);} fclose (FP1);//Close input fileWaitkey (); System"Pause");return 0;}
- Experimental results show (we have successfully drawn the effect of the parking space we want)
Reading data from a TXT file picture parking spaces (2)