imgproc_HoughLinesPointSet.cpp 1.2 KB

12345678910111213141516171819202122232425262728293031323334
  1. #include <opencv2/core.hpp>
  2. #include <opencv2/imgproc.hpp>
  3. using namespace cv;
  4. using namespace std;
  5. int main()
  6. {
  7. Mat lines;
  8. vector<Vec3d> line3d;
  9. vector<Point2f> point;
  10. const static float Points[20][2] = {
  11. { 0.0f, 369.0f }, { 10.0f, 364.0f }, { 20.0f, 358.0f }, { 30.0f, 352.0f },
  12. { 40.0f, 346.0f }, { 50.0f, 341.0f }, { 60.0f, 335.0f }, { 70.0f, 329.0f },
  13. { 80.0f, 323.0f }, { 90.0f, 318.0f }, { 100.0f, 312.0f }, { 110.0f, 306.0f },
  14. { 120.0f, 300.0f }, { 130.0f, 295.0f }, { 140.0f, 289.0f }, { 150.0f, 284.0f },
  15. { 160.0f, 277.0f }, { 170.0f, 271.0f }, { 180.0f, 266.0f }, { 190.0f, 260.0f }
  16. };
  17. for (int i = 0; i < 20; i++)
  18. {
  19. point.push_back(Point2f(Points[i][0],Points[i][1]));
  20. }
  21. double rhoMin = 0.0f, rhoMax = 360.0f, rhoStep = 1;
  22. double thetaMin = 0.0f, thetaMax = CV_PI / 2.0f, thetaStep = CV_PI / 180.0f;
  23. HoughLinesPointSet(point, lines, 20, 1,
  24. rhoMin, rhoMax, rhoStep,
  25. thetaMin, thetaMax, thetaStep);
  26. lines.copyTo(line3d);
  27. printf("votes:%d, rho:%.7f, theta:%.7f\n",(int)line3d.at(0).val[0], line3d.at(0).val[1], line3d.at(0).val[2]);
  28. }