#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):
pt1(_pt1), pt2(_pt2), 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(23, 45), Point(243, 145), Point(308, 25),
Point(180, 230), Point(343, 145), Point(108, 25)
};
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 triangle : 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;
}

  

最新文章

  1. ffmpeg+x264 Windows MSVC 静态编译
  2. 安全生产应急救援指挥系统之GIS一张图-flex/java
  3. 注意:DateTimePicker.Text不靠谱
  4. mac 激活Ultra Edit16
  5. TCP/IP之TCP的建立与终止
  6. Xcode 7安装KSImageNamed失败解决方法
  7. Android 布局 中实现适应屏幕大小及组件滚动
  8. Delphi笔记(GL_Scene四轴飞行器模型)
  9. Java 并发专题 :闭锁 CountDownLatch 之一家人一起吃个饭
  10. bundle install 出现 &amp;#39;gem install mysql2 -v &amp;#39;0.3.15&amp;#39; succeeds before bunding &amp;#39;
  11. PipedInputStream和PipedOutputStream详解
  12. C++获取基类指针所指子类对象的类名
  13. SQL Server学习之路(二):主键和外键
  14. PE文件详解二
  15. 语句调优基础知识-set statistics time on
  16. Confluence 6 内存使用和需求和一些问题
  17. 自学Linux Shell13.3-获得用户输入(read命令)
  18. MATLAB:增加噪声,同时多次叠加噪声图和原图以及求平均图像(imnoise,imadd函数)
  19. Mysql安装和基本使用
  20. MFC:ID命名和数字约定

热门文章

  1. UVa 12100打印队列(队列)
  2. 使用Spring + Jedis集成Redis
  3. DDL、DML、
  4. [luogu P2647] 最大收益(贪心+dp)
  5. 论文笔记之:Fully-Convolutional Siamese Networks for Object Tracking
  6. SQL Debugging
  7. 在Discuz中增加创始人
  8. C++ string::size_type 类型【转】
  9. wikioi 1204 寻找子串位置
  10. android 添加依赖的库文件