#include <opencv2\opencv.hpp>
#include <iostream>
#include <math.h>
#include <vector>
using namespace cv;
using namespace std;
int main()
{
Mat src = imread("test1.jpg",1);
Mat midImage, dstImage;
dstImage = imread("test1.jpg", 1);
Canny(src, midImage, 50, 200, 3);
//vector<Vec2f> lines;
vector<Vec4i> lines;
HoughLinesP(midImage, lines, 1, CV_PI / 180, 150, 0, 0);
for (size_t i = 0; i < lines.size(); i++)
{
Vec4i l = lines[i];
line(dstImage, Point(l[0], l[1]), Point(l[2], l[3]), Scalar(186, 88, 255), 1, LINE_AA);
}
//for (size_t i = 0; i < 10; i++)
//{
// float rho = lines[i][0], theta = lines[i][1];
// Point pt1, pt2;
// double a = cos(theta), b = sin(theta);
// double x0 = a*rho, y0 = b*rho;
// pt1.x = cvRound(x0 + 1000 * (-b));
// pt1.y = cvRound(y0 + 1000 * (a));
// pt2.x = cvRound(x0 - 1000 * (-b));
// pt2.y = cvRound(y0 - 1000 * (a));
// line(dstImage, pt1, pt2, Scalar(55, 100, 195), 1, LINE_AA);
// }
namedWindow("yuantu1", WINDOW_AUTOSIZE);
namedWindow("yuantu2", WINDOW_AUTOSIZE);
namedWindow("yuantu3", WINDOW_AUTOSIZE);
imshow("yuantu1", src);
imshow("yuantu2", midImage);
imshow("yuantu3", dstImage);
waitKey(0);
return 1;
}
基于C++的opencv练习,霍夫变换
最新推荐文章于 2023-10-11 11:06:28 发布