以下代码在白色背景上画线画圆并保存为a12.jpg.
#include <stdio.h>
#include <iostream>
#include <opencv2/opencv.hpp>
#include <opencv2/core.hpp>
#include <opencv2/imgcodecs.hpp>
#include <opencv2/highgui.hpp>
using namespace cv;
using namespace std;
/**
* https://docs.opencv.org/4.6.0/index.html
* https://docs.opencv.org/4.6.0/d6/d00/tutorial_py_root.html
* https://docs.opencv.org/4.x/db/deb/tutorial_display_image.html
* https://docs.opencv.org/4.6.0/d3/d96/tutorial_basic_geometric_drawing.html
*
* cmake .
* make
* ./a
*/
int main(int argc, char **argv) {
Mat img = imread("white.jpg", IMREAD_UNCHANGED);
if (!img.data) {
printf("No image data \n");
return -1;
}
Point start = Point(0, 0);
Point end = Point(600, 200);
line(img, start, end, Scalar(0, 0, 255), 8, LINE_8);
circle(img, Point(200, 200), 50, Scalar(0, 0, 255), FILLED, LINE_8);
imwrite("a12.jpg", img);
namedWindow("Display Image", WINDOW_FREERATIO);
imshow("Display Image", img);
int k = waitKey(0);
return 0;
}
画线:
line(img, start, end, Scalar(0, 0, 255), 8, LINE_8);
画圆:
circle(img, Point(200, 200), 50, Scalar(0, 0, 255), FILLED, LINE_8);