i have written code for lane detection using, hough line transform,lines are identified in my video file stored in my pc [which is having 1280*720 resolution],my video is running slowly,how i can make run faster?,in my code i have checked the time of execution of function hough_transform comprising of canny,cvtcolor and hough transform,up on which i am retrieving the frames, i can able to execute two frames per/sec,please help me to reduce the execution time.thanks in advance here is the code:

#include <opencv2/highgui/highgui.hpp>
#include "opencv2/imgproc/imgproc.hpp"
#include <iostream>

using namespace cv;
using namespace std;

int hough_tranform(Mat src){

if(src.empty())
{

    cout << "can not open " << endl;
    return -1;
}

Mat dst, cdst;
Canny(src, dst, 50, 200, 3);

cvtColor(dst, cdst, COLOR_GRAY2BGR);

vector<Vec4i> lines;
   HoughLinesP(dst, lines, 1, CV_PI/180, 50, 50, 10 );

for( size_t i = 0; i < lines.size(); i++ )
{
    Vec4i l = lines[i];
    line( cdst, Point(l[0], l[1]), Point(l[2], l[3]), Scalar(0,0,255), 3, 0);
}

 imshow("detected lines", cdst);

}


int main() {

Mat frame;
string path = "C:/santhu/Wildlife.wmv";
VideoCapture capture(path); 
namedWindow("my_window");

for(;;) {
capture >> frame;

hough_tranform(frame);

imshow("my_window", frame);

  if(cv::waitKey(30) >= 0) break;
 }
}
有帮助吗?

解决方案

Playing around with the parameters of HoughLinesP function will help you to improve the performance a bit in the cost of precision. Performance will drastically reduce for this function when the image size increases.

If possible, use HoughLines instead of probabilistic approach as it is faster.

Downscaling the image using bilinear interpolation will not effect the quality of the output as hough transformation is carried out on canny edge detector output.

The steps that I would follow will be:

  • Read a frame.
  • Convert to grayScale.
  • Downscale the gray image.
  • If possible, select the ROI on the gray image on which lane is to be detected.
  • Do canny on the ROI image.
  • Do hough transformation.

As you are doing lane detection algorithm I shall put my two cents in. Canny detection alone will not be of much help on road which contains shadows of trees etc as there will be edges detected around it. Though Probabilisitic Hough approach reduces the error in the above circumstances, (a) Limiting the theta value, (b) using sobel edge detection in which dx is given more priority than dy are some experiments worth trying.

其他提示

You should downsize your image before performing edge detection, followed by Hough's Line Transform. Then you can upsize result back to the original size.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top