Ask Your Question

Revision history [back]

error while drawing lines from houghlines()

hi guys, im new to openCv and image processing in general and i need to draw the lines in real time from a camera input. it working fine until i try to draw in the original image the lines detected with houghlines(). here is my code:

int main(int argc, char* argv[])
{   
    Mat input;
    Mat HSV;
    Mat threshold;
    Mat CannyThresh;
    Mat HL;

    //video capture object to acquire webcam feed
    cv::VideoCapture capture;
    capture.open(0);
    capture.set(CV_CAP_PROP_FRAME_WIDTH, 640);
    capture.set(CV_CAP_PROP_FRAME_HEIGHT, 480);

    //start an infinite loop where webcam feed is copied to cameraFeed matrix
    //all operations will be performed within this loop

    while (true){ 

        capture.read(input);
        cvtColor(input, HSV, COLOR_BGR2HSV); //hsv
        inRange(HSV, Scalar(H_MIN, S_MIN, V_MIN), Scalar(H_MAX, S_MAX, V_MAX), threshold);//thershold
        MorphOps(threshold);//morph operations on threshold image
        Canny(threshold, CannyThresh, 100, 50); //canny edge detection

        std::vector<Vec4i> lines;
        HoughLines(CannyThresh, lines, 1, CV_PI/180, 150, 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( input, pt1, pt2, Scalar(0,0,255), 3, CV_AA);
        } 

        imshow("camera", input);
        waitKey(30);

    }
return 0;
}

im getting the following exception:

First-chance exception at 0x74DB3E28 in Proyecto0.1.exe: Microsoft C++ exception: cv::Exception at memory location 0x00D6F47C.

i know the error is happening in the

for( size_t i = 0; i &lt; lines.size(); i++ )

line because if i comment everything inside the for loop, i still get the same error, but if i remove the whole for-loop, it doesnt throws the exception. any ideas of what may be happening?

error while drawing lines from houghlines()

hi guys, im new to openCv and image processing in general and i need to draw the lines in real time from a camera input. it working fine until i try to draw in the original image the lines detected with houghlines(). here is my code:

int main(int argc, char* argv[])
{   
    Mat input;
    Mat HSV;
    Mat threshold;
    Mat CannyThresh;
    Mat HL;

    //video capture object to acquire webcam feed
    cv::VideoCapture capture;
    capture.open(0);
    capture.set(CV_CAP_PROP_FRAME_WIDTH, 640);
    capture.set(CV_CAP_PROP_FRAME_HEIGHT, 480);

    //start an infinite loop where webcam feed is copied to cameraFeed matrix
    //all operations will be performed within this loop

    while (true){ 

        capture.read(input);
        cvtColor(input, HSV, COLOR_BGR2HSV); //hsv
        inRange(HSV, Scalar(H_MIN, S_MIN, V_MIN), Scalar(H_MAX, S_MAX, V_MAX), threshold);//thershold
        MorphOps(threshold);//morph operations on threshold image
        Canny(threshold, CannyThresh, 100, 50); //canny edge detection

        std::vector<Vec4i> lines;
        HoughLines(CannyThresh, lines, 1, CV_PI/180, 150, 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( input, pt1, pt2, Scalar(0,0,255), 3, CV_AA);
        } 

        imshow("camera", input);
        waitKey(30);

    }
return 0;
}

im getting the following exception:

First-chance exception at 0x74DB3E28 in Proyecto0.1.exe: Microsoft C++ exception: cv::Exception at memory location 0x00D6F47C.

i know the error is happening in the

for( size_t i = 0; i &lt; lines.size(); i++ )

line because if i comment everything inside the for loop, i still get the same error, but if i remove the whole for-loop, it doesnt throws the exception. any ideas of what may be happening?

EDIT #1 as you can see in the second image, the debugger doesn't throw any errors. but in the console of the program it says OpenCV Error:Assertion failed (channels() == CV_MAT_CN(dtype)) in cv::Mat::copyTo, file C:\builds\master_packSlave-Win32-vc12-shared\opencv\modules\core\src\copy.cpp, line 281. Also the last call in the call stack is this: > KernelBase.dll!_RaiseException@16() Unknown, im starting to thing is an opencv problem and not a code problem, maybe something with that dll.

error while drawing lines from houghlines()

hi guys, im new to openCv and image processing in general and i need to draw the lines in real time from a camera input. it working fine until i try to draw in the original image the lines detected with houghlines(). here is my code:

int main(int argc, char* argv[])
{   
    Mat input;
    Mat HSV;
    Mat threshold;
    Mat CannyThresh;
    Mat HL;

    //video capture object to acquire webcam feed
    cv::VideoCapture capture;
    capture.open(0);
    capture.set(CV_CAP_PROP_FRAME_WIDTH, 640);
    capture.set(CV_CAP_PROP_FRAME_HEIGHT, 480);

    //start an infinite loop where webcam feed is copied to cameraFeed matrix
    //all operations will be performed within this loop

    while (true){ 

        capture.read(input);
        cvtColor(input, HSV, COLOR_BGR2HSV); //hsv
        inRange(HSV, Scalar(H_MIN, S_MIN, V_MIN), Scalar(H_MAX, S_MAX, V_MAX), threshold);//thershold
        MorphOps(threshold);//morph operations on threshold image
        Canny(threshold, CannyThresh, 100, 50); //canny edge detection

        std::vector<Vec4i> lines;
        HoughLines(CannyThresh, lines, 1, CV_PI/180, 150, 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( input, pt1, pt2, Scalar(0,0,255), 3, CV_AA);
        } 

        imshow("camera", input);
        waitKey(30);

    }
return 0;
}

im getting the following exception:

First-chance exception at 0x74DB3E28 in Proyecto0.1.exe: Microsoft C++ exception: cv::Exception at memory location 0x00D6F47C.

i know the error is happening in the

for( size_t i = 0; i &lt; lines.size(); i++ )

line because if i comment everything inside the for loop, i still get the same error, but if i remove the whole for-loop, it doesnt throws the exception. any ideas of what may be happening?

EDIT #1 as you can see in the second image, the debugger doesn't throw any errors. but in the console of the program it says OpenCV Error:Assertion failed (channels() == CV_MAT_CN(dtype)) in cv::Mat::copyTo, file C:\builds\master_packSlave-Win32-vc12-shared\opencv\modules\core\src\copy.cpp, line 281. Also the last call in the call stack is this: > KernelBase.dll!_RaiseException@16() Unknown, im starting to thing is an opencv problem and not a code problem, maybe something with that dll.