An example of Delaunay triangular network algorithm in OPENCV

Source: Internet
Author: User

#include <opencv2/opencv.hpp> #include <vector>using namespace cv;using namespace Std;typedef struct _ Triangle_desc_{point pt1, PT2, pt3;_triangle_desc_ (const point _PT1, const point _PT2, const point _PT3):p T1 (_pt1), Pt2 (_p T2), PT3 (_PT3) {}}triangle_desc;vector<triangle_desc> delaunayalgorithm (const Rect Boundrc,const vector< point>& points) {if (Points.empty ()) {return vector<triangle_desc> ();} Vector<triangle_desc> result;vector<vec6f> _temp_result; subdiv2d subdiv2d (BOUNDRC), for (const auto point:points) {Subdiv2d.insert (point2f ((float) point.x, (float) point.y));} Subdiv2d.gettrianglelist (_temp_result); for (const auto _tmp_vec: _temp_result) {point pt1 ((int) _tmp_vec[0], (int) _tmp _VEC[1]); Point pt2 (int) _tmp_vec[2], (int) _tmp_vec[3]); Point PT3 (int) _tmp_vec[4], (int) _tmp_vec[5]); Result.push_back (Triangle_desc (pt1, Pt2, PT3));} return result;} int main (int argc, char* argv[]) {Const int width = 400;const int height = 400; Mat srcimg (height, width, CV_8UC3, Scalar (255,255,255)), const vector<point> testpoints = {point (at all), point (243, 145), point (308, +), point (343, 145), point (108, +)};for (const auto point:testpoints) {Circle (srcimg, point, 1, Scalar (0), 2);} Const Rect PAGERC (0, 0, width, height), const auto triangles = Delaunayalgorithm (pagerc,testpoints), for (const auto Trian Gle:triangles) {line (srcimg, TRIANGLE.PT1, Triangle.pt2, Scalar (255, 0, 0)), line (srcimg, TRIANGLE.PT1, TRIANGLE.PT3, Scalar (255, 0, 0)), line (srcimg, Triangle.pt2, TRIANGLE.PT3, Scalar (255, 0, 0));} Imshow ("src", srcimg); Waitkey (0); return 0;}

  

An example of Delaunay triangular network algorithm in OPENCV

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.