【发布时间】:2014-03-20 19:37:49
【问题描述】:
我已经编写了车道检测代码,使用霍夫线变换,在我存储在我的电脑中的视频文件中识别了线条 [分辨率为 1280*720],我的视频运行缓慢,我怎样才能让运行更快? ,在我的代码中,我检查了函数 hough_transform 的执行时间,该函数由 canny、cvtcolor 和 hough 变换组成,我在上面检索帧,我可以每秒执行两帧,请帮助我减少执行时间。提前谢谢 这是代码:
#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;
}
}
【问题讨论】:
-
你试过用完全优化编译吗?
-
试试这些:对图像设置阈值以删除非必要点、遮罩、缩小尺寸。
-
您可以将步数减少 $R$ ant $\theta$ 以提高速度(当然,您会降低精度)。由于同步需求,霍夫变换的并行不会给您带来显着的努力。
标签: c++ visual-c++ opencv image-processing mat