#include <vector>
#include <algorithm>
#include <iostream>
#include <cstdint>
#include <cstdlib>
#include <opencv2/opencv.hpp>
using namespace std;
using namespace cv;
static void draw_subdiv( Mat& img, Subdiv2D& subdiv, Scalar delaunay_color )
{
vector<Vec6f> triangleList;
subdiv.getTriangleList(triangleList);
vector<Point> pt(3);
for( size_t i = 0; i < triangleList.size(); i++ )
{
Vec6f t = triangleList[i];
pt[0] = Point(cvRound(t[0]), cvRound(t[1]));
pt[1] = Point(cvRound(t[2]), cvRound(t[3]));
pt[2] = Point(cvRound(t[4]), cvRound(t[5]));
line(img, pt[0], pt[1], delaunay_color, 1, LINE_AA, 0);
line(img, pt[1], pt[2], delaunay_color, 1, LINE_AA, 0);
line(img, pt[2], pt[0], delaunay_color, 1, LINE_AA, 0);
}
}
int main(int argc, char** argv)
{
if (argc < 2)
{
cout << "usage: ./demo input_image" << endl;
return -1;
}
Mat img = imread(argv[1]);
if (img.empty())
{
cout << "error: image is empty" << endl;
}
Mat imgGray, imgBlur, imgEdge;
cvtColor(img, imgGray, CV_BGR2GRAY);
//GaussianBlur(imgGray, imgBlur, Size(3, 3), 0, 0);
blur(imgGray, imgBlur, Size(3, 3));
double threshold = 10.0;
Canny(imgBlur, imgEdge, threshold, threshold * 3, 3);
// imshow("img with edge", imgEdge);
// waitKey(0);
vector<Point2f> supportPoints;
uint32_t imgHeight = img.rows;
uint32_t imgWidth = img.cols;
uint32_t sampleInterval = 3;
for (int row = 0; row < imgHeight; row += sampleInterval)
{
for (int col = 0; col < imgWidth; col += sampleInterval)
{
if (imgEdge.at<uchar>(row, col) == 255)
{
supportPoints.push_back(Point2f(col, row));
}
}
}
Mat imgSupportPoints = img.clone();
for (int i = 0; i < supportPoints.size(); i++)
{
circle( imgSupportPoints, supportPoints[i], 1, Scalar(0, 0, 255), FILLED, LINE_8, 0 );
}
// imshow("img with support points", imgSupportPoints);
// waitKey(0);
Scalar delaunay_color(0,0,255);
Rect rect(0, 0, imgWidth, imgHeight);
Subdiv2D subdiv(rect);
subdiv.insert(supportPoints);
draw_subdiv(img, subdiv, delaunay_color);
imshow("img with Delaunay", img);
waitKey(0);
return 0;
}
[naive] delaunay trianglation
最后编辑于 :
©著作权归作者所有,转载或内容合作请联系作者
- 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
- 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
- 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
推荐阅读更多精彩内容
- Everybody deserved a love life,"Once naive,once authe...
- -2,前言 最近我们公司突然开始涉足react-native开发,老实说,我内心是拒绝的。其一,是因为目前我对于原...
- 1 最近一系列男性明星出轨,朋友圈中爆发出大量歧视性指责。“下半身动物”、“花心”、“段正淳”……以王胖的颜值,在...
- Everyday, he gets up then have a nice chat with his famil...