Lines, rectangles, circles, ellipses, and text drawing

 

 See details Code:

 

#include <opencv2 / opencv.hpp> 
#include <iostream> a using namespace CV; 
Mat bgImage; const char * drawdemo_win = " Draw Shapes and text Demo " ;
 // Note the call function, main function before the function declaration. void MyLines ();
 void MyRectangle ();
 void MyEllipse ();
 void the MyCircle ();
 void MyPolygon (); int main ( int argc, char ** the argv) { 
    bgImage = imread ( " L: /4.jpg " ) ;
     IF (!


 
 


bgImage.data) 
    { 
        the printf ( " Could Not Load Image ... \ n- " );
         return - . 1 ; 
    } 
    MyLines ();        // Call MyLine () function 
    MyRectangle ();    // Call MyRectangle () function 
    MyEllipse () ;      // Call MyEllipse () function 
    MyCircle ();       // Call MyCircle () function 
    MyPolygon ();      // Call MyPolygon () function 

    // pictures to draw text 
    putText (bgImage, " the Hello on Opencv " , Point ( 300 , 300), CV_FONT_HERSHEY_COMPLEX, 1.0 , the Scalar ( 12 is , 23 is , 200 is ), . 3 , . 8 );
     // Parameters: 1 target image coordinates of the lower left corner 3. 4. 2. Content Format Font Font Size 5. 6. 7 font color. 8. The default font weight. 8 
    namedWindow (drawdemo_win, CV_WINDOW_AUTOSIZE); 
    imshow (drawdemo_win, bgImage); 
    waitKey ( 0 );
     return  0 ; 
} 

// linear function 
void MyLines () { 
    Point P1 = Point ( 20 is , 30 ); 
    Point P2 ; 
    P2.x = 300 ; 
    p2.y= 300 ; 
    the Scalar Color = the Scalar ( 0 , 0 , 255 ); 
    line (bgImage, P1, P2, Color, 2 , LINE_8);   // LINE_8 lines of antialiasing
     // Parameters of the line: 1 the image 2 is written. 4. type 3.p2 point p1 point 6. the thickness of the lines 5. the color line 
} 

// rectangular function 
void MyRectangle () { 
    Rect RECT = Rect ( 200 is , 100 , 300 , 300 );
     // Rect _ (_ Tp of the _x, _y _TP, _TP the _width, _TP _height)
     // define a left corner coordinate (_x, _y) in a rectangular window _width * _height 
    Scalar color = Scalar (255, 0, 0);
    rectangle(bgImage, rect, color, 2, LINE_8);
}

//椭圆函数
void MyEllipse() {
    Scalar color = Scalar(0, 255, 0);
    ellipse(bgImage, Point(bgImage.cols / 2, bgImage.rows / 2), Size(bgImage.cols / 4, bgImage.rows / 8), 45, 0, 360, color, 2, LINE_8);
    //ellipse function parameters: 1. The inclination angle of the target image drawing 2. drawing an elliptical central drawing an elliptical 3. 4. The major and minor axes of the ellipse angle of 5.6 lines (arcs) (0-360) 8 7. color. 9. The type of line thickness, line 
} 

// round function 
void the MyCircle () { 
    the Scalar Color = the Scalar ( 0 , 255 , 255 ); 
    Point Center = Point (bgImage.cols / 2 , bgImage.rows / 2 ); 
    circle (bgImage, Center, 150 , Color, 2 , . 8 ); 
} 

// polygon fill function 
void MyPolygon () { 
    Point PTS [ . 1 ] [ . 5 ];                    //Five points define a two-dimensional array of 
        PTS [ 0 ] [ 0 ] = Point ( 100 , 100 ); 
        PTS [ 0 ] [ . 1 ] = Point ( 100 , 200 is ); 
        PTS [ 0 ] [ 2 ] = Point ( 200 is , 200 is ); 
        PTS [ 0 ] [ . 3 ] = Point ( 200 is , 100 ); 
        PTS [ 0 ] [ . 4 ] = Point ( 100 , 100 ); 

        const Point PPTS * [] = {PTS [0 ]};   // PPTS a pointer pts [0] array 
        int npt [] = { 5 };                // one-dimensional array npt 5, representatives of five points 
        the Scalar the Scalar Color = ( 255 , 0 , 255 ); 

        fillPoly (bgImage, PPTS, NPT, 1 , Color, . 8 );
         // fillPoly function parameters: a two-dimensional array 2. The input image is a one-dimensional array of pointers to the number of vertices of the pointer 3. 4. 5. The number of filled polygon color default parameters 6.line_type = 8 
}

 

Guess you like

Origin www.cnblogs.com/Jack-Elvis/p/11494332.html