# Revision history [back]

### HoughLines Debug Assertion Failed

Good Evening,

I have an application where I need to detect straight line segments within an image. It is my understanding that the "HoughLines" function would be the right function to be used to achieve this. I found an example at the following link:

http://docs.opencv.org/doc/tutorials/imgproc/imgtrans/hough_lines/hough_lines.html

Here is a copy of the exact code I'm using:

#include <vector>
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include <iostream>

using namespace cv;
using namespace std;

int main( int argc, char** argv ) {
if(src.empty()) {
cout << "can't open file" << endl;
return -1;
}

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

vector<Vec2f> lines;
HoughLines(dst, lines, 1, CV_PI/180, 100, 0, 0 );

for( size_t i = 0; i < lines.size(); i++ ) {
float rho = lines[i][0], theta = lines[i][1];
Point pt1, pt2;
double a = cos(theta), b = sin(theta);
double x0 = a*rho, y0 = b*rho;
pt1.x = cvRound(x0 + 1000*(-b));
pt1.y = cvRound(y0 + 1000*(a));
pt2.x = cvRound(x0 - 1000*(-b));
pt2.y = cvRound(y0 - 1000*(a));
line( cdst, pt1, pt2, Scalar(0,0,255), 3, CV_AA);
}

imshow("source", src);
imshow("detected lines", cdst);

waitKey();

return 0;
}


When I run this code I'm thrown the following:

"Debug Assertion Failed!

Program: c:\Projects\OtherFiles\TestOpenCV\Debug\TestOpenCV.exe

File: C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include\vector Line: 157

Expression: vector iterator + offset out of range

I've been searching for the solution to this for a number of days now and can't seem to find anyone else with my exact same problem, otherwise I would not have posted to a forum.

If anyone could provide me with a solution to this problem or could direct me to another forum post with some more help then I would very much appreciate it.

By the way, this is being written in Microsoft Visual Studio 2008 Professional Edition on a Windows 7 machine.

Thanks, Stanton