我试图从卫星图像中探测道路!它可以是任何类型的铺砌/沥青路面。我正在使用OpenCV!我尝试的方式是,首先我使用Canny来检测边缘,我试图应用hough变换来检测边缘的直线。然后我计划检测圆圈以检测道路的曲线。我面临的问题是,在做了精灵之后,霍夫无法正常工作。到目前为止,这是我的代码:
#include <iostream>
#include <math.h>
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc/imgproc.hpp>
using namespace cv;
using namespace std;
int main()
{
//read an image
cv::Mat image = cv::imread("img2.jpg");
//create image window named "My Image"
cv::namedWindow("My Image");
//show the image on the window
cv::imshow("My Image", image);
cv::Mat contours,hough;
//canny
cv::Canny(image, contours, 0, 100);
cv::namedWindow("My Image2");
cv::imshow("My Image2", contours);
// Hough tranform for line detection
std::vector<cv::Vec2f> lines;
cv::HoughLines(contours, lines, 1, CV_PI/180, 80, 0, 0);
std::vector<cv::Vec2f>::const_iterator it= lines.begin();
while(it!=lines.end())
{
float rho= (*it)[0];
// first element is distance rho
float theta= (*it)[1];
//second element is angle theta
if(theta < CV_PI/4. || theta > 3.*CV_PI/4.)
{ // ~vertical line
// point of intersection of the line with first row
cv::Point pt1(rho/cos(theta),0);
// point of intersection of the line with last row
cv::Point pt2((rho-result.rows*sin(theta))/cos(theta),result.rows);
// draw a white line
cv::line( image, pt1, pt2, cv::Scalar(255), 1);
}
else
{ // ~horizontal line
// point of intersection of the
// line with first column
cv::Point pt1(0,rho/sin(theta));
// point of intersection of the line with last column
cv::Point pt2(result.cols,(rho-result.cols*cos(theta))/sin(theta));
// draw a white line
cv::line(image, pt1, pt2, cv::Scalar(255), 1);
}
++it;
}
//show lines
cv::namedWindow("My Image3");
cv::imshow("My Image3", hough);
//wait key for 5000ms
cv::waitKey(80000);
return 0;
}
在此代码中,我在&#34;结果&#34;下收到错误在cv::Point pt2((rho-result.rows*sin(theta))/cos(theta),result.rows);
行
&#34;结果&#34;下的另一个错误在cv::Point pt2(result.cols,(rho-result.cols*cos(theta))/sin(theta));
行
我无法弄清楚那些错误是什么以及解决方案是什么!任何帮助,将不胜感激 :) 此外,我对计算机视觉有了全新的认识,如果您有任何其他更简单,更简单的方法来实现我的目标,请随时分享:)
为了您的帮助,我提供了样本图片和错误图片:
https://drive.google.com/open?id=0B4qYRvG5emZDWXhNV2V2djZWdUk
错误是错误,Canny是在执行canny算法之后,输入是我拍的样本图像!
注意:我正在使用OpenCV cookbook获取我的代码!