Reading data from a TXT file picture parking spaces (2)

Source: Internet
Author: User

Reading data from a TXT file draw a trapezoid on the picture
    • Function description
      (1) Application of C language reading documents
      (2) converting data read from a text file
      (3) Use of OpenCV Library: Draw trapezoid, Draw rectangle

    • Code Show

#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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.