问题描述
我正在尝试使用houghLines和Canny边缘检测器检测图像中的线条,但是每次获取exe文件都停止工作时,这确实很烦人.我使用的是最新的预编译exe和visual studio作为ide. Canny可以正常工作,但是从我尝试努力的那一刻起.问题.
I'm trying to detect lines in an image using houghLines and Canny edge detector but every time I get exe has stopped working, and this is really annoying. I'm using the latest pre-compiled exe and visual studio as ide. The canny works perfectly but from the moment I try to hough.. problem.
使用OpenCV 3.1.0和vs 2015.
Using OpenCV 3.1.0 and vs 2015.
代码:
void detectLines(Mat image) {
Mat dest = image.clone();
Mat graydest = image.clone();
if (image.channels() == 3) {
cvtColor(image, image, CV_BGR2GRAY);
}
double threshold = 5;
Canny(image, dest, 0.4*threshold, threshold);
cvtColor(dest, graydest, COLOR_GRAY2BGR);
imshow("Display Window", dest);
waitKey(0);
vector<Vec2f> lines;
HoughLines(dest, lines,1,CV_PI / 180, 0,0);
cout << "Number of lines " << lines.size() << endl;
if (!lines.empty()) {
for (size_t i = 0; i < lines.size(); i++)
{
float rho = lines[i][0];
float theta = lines[i][1];
double a = cos(theta), b = sin(theta);
double x0 = a*rho, y0 = b*rho;
cout << rho << " " << theta << " " << a << " " << x0 << " " << endl;
Point pt1(cvRound(x0 + 1000 * (-b)),
cvRound(y0 + 1000 * (a)));
Point pt2(cvRound(x0 - 1000 * (-b)),
cvRound(y0 - 1000 * (a)));
line(graydest, pt1, pt2, Scalar(0, 0, 255), 3, 8);
}
}
imshow("source", image);
imshow("Display Window", graydest);
waitKey(0);
}
输出实际上是返回向量的时间的1/2,而其他1/2则停止工作.
The output is crap 1/2 of the time it actually return a vector, the other 1/2 it just goes stopped working.
进一步调试会导致读取访问冲突,我认为行的向量大小太大.
Debugging further gives a read access violation and I think the vector size of the lines is just too big.
[解决方案]
见下文,三木
推荐答案
这种错误通常是由调试/发布库的混合引起的.
This kind of errors is usually caused by mixing debug/release libraries.
请确保在调试模式opencv_<module><version>d
(后跟 d )中使用库,并在发布模式中不使用后跟 d .
Be sure to use in Debug mode opencv_<module><version>d
(with trailing d) libraries, and in Release mode without the trailing d.
从注释中可以看出,您正在以调试模式链接到opencv_world310.lib
和opencv_world310d.lib
.您应该删除第一个,因为在调试"模式下,您应该仅具有调试库(后跟 d ).
As it turns out from comments, you're linking in Debug mode to both opencv_world310.lib
and opencv_world310d.lib
. You should remove the first one, since in Debug mode you should have only debug libraries (with trailing d).
这篇关于HoughLine不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!