Graphics rendering code that is commonly used as follows:
#include<opencv2/opencv.hpp> #include<iostream> using namespace std; using namespace cv; int main(int argc, char** argv) { Mat image = imread("D:/OpenCVprj/image/test3.jpg"); namedWindow("image", CV_WINDOW_AUTOSIZE); //line Point p1; p1.x = image.cols; p1.y = image.rows; Point p2 = Point(0, 0); Scalar color = Scalar(0, 0, 255); line(image, p1, p2, color, 1, LINE_8); //rectangle Scalar color1 = Scalar(0, 255, 0); Rect rect = Rect(image.cols / 4, image.rows / 4, 2*image.cols / 4, 2*image.rows/4); rectangle(image, rect, color1, 3, LINE_8); //ellipse 椭圆 Scalar color2 = Scalar(255, 0, 0); // 90, represents the rotation 90 °, 0,360, represented Videos arc size, line thickness 1 represents ellipse (image, Point (image.cols / 2, image.rows / 2), Size (image.cols / 4, image.rows /. 8), 90, 0, 360, color2 for,. 1, LINE_8); // Circle the Scalar color3 the Scalar = (255, 255, 0); Circle (Image, Point (image.cols / 2, image.rows / 2), 200 is, color3,. 5, LINE_8); // fillpoly Point PTS [. 1] [. 5]; 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]}; int NPT [] = {. 5}; the Scalar Color4 = the Scalar (255, 0, 255); fillPoly (Image, PPTS, NPT,. 1, Color4, LINE_8); text // the Scalar color5 the Scalar = (0, 255, 0); putText(image, "Hello OpenCV", Point(100, image.rows/2), CV_FONT_HERSHEY_COMPLEX, 2, color5); imshow("image", image); waitKey(0); return 0; }