In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-03 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly explains "what are the basic graphics drawing functions of OpenCV". Interested friends may wish to have a look. The method introduced in this paper is simple, fast and practical. Next, let the editor take you to learn what are the basic graphics drawing functions of OpenCV.
Line function for drawing straight Lin
Ellipse function for drawing Ellipse
Rectangle function for drawing rectangles
Circle function for drawing circles
The fillPoly function used to draw filled polygons.
# include # include # include using namespace cv;using namespace std;#define WINDOW_WIDTH 600 / / Macro # define WINDOW_NAME1 "Atomic Diagram" / / Macro # define WINDOW_NAME2 "Polygon Diagram and Line drawing" / / Macro / * * draw Ellipse * / void DrawEllipse (Mat img, double angle) {int thickness = 2; / / Line width int lineType = 8 / / Linear, 8 represents Unicom Linear ellipse (img, Point (WINDOW_WIDTH / 2, WINDOW_WIDTH / 2), Size (WINDOW_WIDTH / 4, WINDOW_WIDTH / 16), angle, / / Angle, 0,360 degrees 0,360, Scalar (255,129,0), thickness, lineType) } / * draw a solid circle * / void DrawFilledCircle (Mat img, Point center) {int thickness =-1; / / Line thick-1, representing solid int lineType = 8; / / Linear, 8 represents connected linear circle (img, center, WINDOW_WIDTH / 32, Scalar (0,0,255), thickness, lineType) } / * concave polygon rendering * / void DrawPolygon (Mat img) {int lineType = 8; / / create some points Point rookPoints [1] [20]; rookPoints [0] [0] = Point (WINDOW_WIDTH / 4,7 * WINDOW_WIDTH / 8); rookPoints [0] [1] = Point (3 * WINDOW_WIDTH / 4,7 * WINDOW_WIDTH / 8); rookPoints [0] [2] = Point (3 * WINDOW_WIDTH / 4,13 * WINDOW_WIDTH / 16) RookPoints [0] [3] = Point (11 * WINDOW_WIDTH / 16, 13 * WINDOW_WIDTH / 16); rookPoints [0] [4] = Point (19 * WINDOW_WIDTH / 32, 3 * WINDOW_WIDTH / 8); rookPoints [0] [5] = Point (3 * WINDOW_WIDTH / 4, 3 * WINDOW_WIDTH / 8); rookPoints [0] [6] = Point (3 * WINDOW_WIDTH / 4, WINDOW_WIDTH / 8) RookPoints [0] [7] = Point (26 * WINDOW_WIDTH / 40, WINDOW_WIDTH / 8); rookPoints [0] [8] = Point (26 * WINDOW_WIDTH / 40, WINDOW_WIDTH / 4); rookPoints [0] [9] = Point (22 * WINDOW_WIDTH / 40, WINDOW_WIDTH / 4); rookPoints [0] [10] = Point (22 * WINDOW_WIDTH / 40, WINDOW_WIDTH / 8) RookPoints [0] [11] = Point (18 * WINDOW_WIDTH / 40, WINDOW_WIDTH / 8); rookPoints [0] [12] = Point (18 * WINDOW_WIDTH / 40, WINDOW_WIDTH / 4); rookPoints [0] [13] = Point (14 * WINDOW_WIDTH / 40, WINDOW_WIDTH / 4); rookPoints [0] [14] = Point (14 * WINDOW_WIDTH / 40, WINDOW_WIDTH / 8) RookPoints [0] [15] = Point (WINDOW_WIDTH / 4, WINDOW_WIDTH / 8); rookPoints [0] [16] = Point (WINDOW_WIDTH / 4, 3 * WINDOW_WIDTH / 8); rookPoints [0] [17] = Point (13 * WINDOW_WIDTH / 32, 3 * WINDOW_WIDTH / 8); rookPoints [0] [18] = Point (5 * WINDOW_WIDTH / 16, 13 * WINDOW_WIDTH / 16) RookPoints [0] [19] = Point (WINDOW_WIDTH / 4, 13 * WINDOW_WIDTH / 16); const Point* ppt [1] = {rookPoints [0]}; / / Polygon fixed-point set int npt [] = {20} / / number of fixed points of polygons fillPoly (img, ppt, npt, 1, Scalar (255,255,255), / / Polygon color: White lineType);} / * Line drawing * / void DrawLine (Mat img, Point start, Point end) {int thickness = 2; int lineType = 8 Line (img, start, end, Scalar), / / Black thickness, lineType);} int main (int argc, char * * argv) {Mat atomImage = Mat::zeros (WINDOW_WIDTH, WINDOW_WIDTH, CV_8UC3); Mat rookImage = Mat::zeros (WINDOW_WIDTH, WINDOW_WIDTH, CV_8UC3); / / Ellipse drawing DrawEllipse (atomImage, 0) DrawEllipse (atomImage, 90); DrawEllipse (atomImage, 45); DrawEllipse (atomImage,-45); / draw the center of the circle DrawFilledCircle (atomImage, Point (WINDOW_WIDTH / 2, WINDOW_WIDTH / 2)); / / draw polygons DrawPolygon (rookImage) / draw rectangular rectangle (rookImage, Point (0,7 * WINDOW_WIDTH / 8), Point (WINDOW_WIDTH, WINDOW_WIDTH), Scalar (0,255,255),-1,8); / / draw some line segments DrawLine (rookImage, Point (0,15 * WINDOW_WIDTH / 16), Point (WINDOW_WIDTH, 15 * WINDOW_WIDTH / 16)) DrawLine (rookImage, Point (WINDOW_WIDTH / 4, 7 * WINDOW_WIDTH / 8), Point (WINDOW_WIDTH / 4, WINDOW_WIDTH); DrawLine (rookImage, Point (WINDOW_WIDTH / 2,7 * WINDOW_WIDTH / 8), Point (WINDOW_WIDTH / 2, WINDOW_WIDTH)); DrawLine (rookImage, Point (3 * WINDOW_WIDTH / 4, 7 * WINDOW_WIDTH / 8), Point (3 * WINDOW_WIDTH / 4, WINDOW_WIDTH)) / /-display the drawn image-imshow (WINDOW_NAME1, atomImage); moveWindow (WINDOW_NAME1, 0200); imshow (WINDOW_NAME2, rookImage); moveWindow (WINDOW_NAME2, WINDOW_WIDTH, 200); waitKey (0); return (0);}
Run:
At this point, I believe you have a deeper understanding of "what are the basic graphics drawing functions of OpenCV?" you might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.