#include <istream> #include <opencv2/opencv.hpp> using namespace cv; using namespace std; int main(int argc, char **argv) { Mat src; // 加载图片 src = imread("../../picture/bg1.webp", 1); if (!src.data) { printf("No image data \n"); return -1; } // 画线 Point p1 = Point(0,0),p2=Point(550,190); Scalar line_color = Scalar(0,0,255); line(src,p1,p2,line_color,2,LINE_8); // 画框 Rect rect = Rect(400,0,350,390); Scalar rect_color = Scalar(255,0,0); rectangle(src,rect,rect_color,2,LINE_8); // 画椭圆 Scalar ellipse_color = Scalar(0,255,0); ellipse(src,Point(575,190),Size(190,170),90,0,360,ellipse_color,2,LINE_8); // 画圆 Scalar circle_color = Scalar(255,255,0); circle(src,Point(575,190),100,circle_color,1,LINE_8); // 画多边形 Point pts[1][5]; pts[0][0] = Point(100,100); pts[0][1] = Point(100,200); pts[0][2] = Point(200,200); pts[0][3] = Point(200,100); pts[0][4] = Point(100,100); const Point* ppts[] = {pts[0]}; int npt[] = {5}; Scalar pts_color = Scalar(255,0,255); fillPoly(src,ppts,npt,1,pts_color,LINE_8); // 画字符 Scalar text_color = Scalar(0,255,255); putText(src,"Beautiful Girl",Point(450,450),FONT_HERSHEY_COMPLEX,1.0,text_color,1,LINE_8); namedWindow("src", WINDOW_AUTOSIZE); imshow("src", src); // 等待按键 waitKey(0); return 0; }