Opencv3 the application of the minimum bounding rectangle in the image-scroll bar

Source: Internet
Author: User

1#include <opencv2/opencv.hpp>2#include <iostream>3#include <vector>4 5 using namespaceCV;6 using namespacestd;7 8 intg_nminthred = -, g_nmaxthred =255;9 intG_nthick =0;Ten  One intMain () A { -Mat srcimage = Imread ("group.jpg"); -  theNamedwindow (""Original"",0); -Imshow (""Original"", srcimage); -  -Createtrackbar ("minthred",""Original"", &g_nminthred,255,0); +Createtrackbar ("maxthred",""Original"", &g_nmaxthred,255,0); -Createtrackbar ("Thick",""Original"", &g_nthick, -,0); +  A     //first, the image is converted into space (in order to extract the binary image later) at Mat grayimage; - Cvtcolor (Srcimage, Grayimage, Cv_bgr2gray); -     //filtering the image to achieve better results -Gaussianblur (Grayimage, Grayimage, Size (3,3),0,0); -Imshow (""Filtered image"", grayimage); -  in     Charkey; -      while(1) to     { +         //obtaining binary images by Edge detection - Mat cannyimage; theCanny (Grayimage, Cannyimage, g_nminthred, g_nmaxthred,3); *  $         //extracting outlines in a binary imagePanax NotoginsengVector<vector<point>>contours; -Vector<vec4i>hierarchy; theFindcontours (cannyimage, contours, hierarchy, Retr_tree, Chain_approx_simple, point (0,0)); +  A         //find the approximate polygon for each contour point set theVector<vector<point>>Approxpoint (Contours.size ()); +          for(inti =0; I < (int) Contours.size (); i++) -         { $             //The four vertex coordinates of the rectangle are obtained from the rectpoint variable. $Rotatedrect Rectpoint =Minarearect (Contours[i]); -             //define a variable that stores the coordinates of the above four points -POINT2F fourpoint2f[4]; the             //Place the coordinate values stored in the Rectpoint variable into an array of Fourpoint - rectpoint.points (fourpoint2f);Wuyi  the             //draws a rectangle based on the coordinates of the resulting four points -              for(inti =0; I <3; i++) Wu             { -Line (Cannyimage, Fourpoint2f[i], Fourpoint2f[i +1] About, Scalar (255,255,255), G_nthick); $             } -Line (Cannyimage, fourpoint2f[0], fourpoint2f[3] -, Scalar (255,255,255), G_nthick); -         } A  +Imshow (""Image after drawing"", cannyimage); the  -Key = Waitkey (1); $         if(Key = = -) the              Break; the     } the  the     return 0; -}

Top
0
Step

Opencv3 the application of the minimum bounding rectangle in the image-scroll bar

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.