Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "opencv2/highgui/highgui.hpp"
- #include "opencv2/imgproc/imgproc.hpp"
- #include <iostream>
- void help()
- {
- std::cout << "\nThis program demonstrates line finding with the Hough transform.\n"
- "Usage:\n"
- "./houghlines <image_name>, Default is pic1.jpg\n" << std::endl;
- system("pause");
- }
- int main(int argc, char** argv)
- {
- //const char* filename = argc >= 2 ? argv[1] : "C:\temp\test.jpg";
- const char* filename = "C://temp//test3.jpg";
- std::cout << "OpenCV Version: " << CV_VERSION << std::endl;
- //IplImage* img = cvLoadImage("c://frame_201.bmp");
- cv::Mat src = cv::imread(filename, 0);
- if (src.empty())
- {
- help();
- std::cout << "can not open " << filename << std::endl;
- return -1;
- }
- cv::Mat dst, cdst;
- cv::Canny(src, dst, 100, 300, 3);
- cv::cvtColor(dst, cdst, cv::COLOR_GRAY2BGR);
- std::vector<cv::Vec4i> lines;
- //
- HoughLinesP(dst, lines, 1, CV_PI / 2, 200, 200, 5);
- for (size_t i = 0; i < lines.size(); i++)
- {
- cv::Vec4i l = lines[i];
- line(cdst, cv::Point(l[0], l[1]), cv::Point(l[2], l[3]), cv::Scalar(0, 0, 255), 3, cv::LINE_AA);
- }
- imshow("source", src);
- imshow("detected lines", cdst);
- cv::imwrite("LineDetection.jpg", cdst);
- cv::waitKey();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement