Ask Your Question

Hough Transform on Live Video

asked 2013-10-03 18:43:27 -0500

adecker246 gravatar image

updated 2013-10-03 20:44:25 -0500

I am trying to run a hough transform on live video input. It runs fine on what seems to be the first frame then it throws this:

The thread 'Win32 Thread' (0x12b0) has exited with code 1950154752 (0x743d0000).
HEAP[openCV.exe]: Invalid address specified to RtlFreeHeap( 01DC0000, 041EC660 )
Windows has triggered a breakpoint in openCV.exe.

This may be due to a corruption of the heap, which indicates a bug in openCV.exe or any of the DLLs it has loaded.

This may also be due to the user pressing F12 while openCV.exe has focus.

The output window may have more diagnostic information.
The program '[900] openCV.exe: Native' has exited with code 0 (0x0).

And the code:

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

using namespace std;
using namespace cv;

int main(int, char**)
    VideoCapture stream1(0);
    cout << "cannot open camera" << endl;

    while (true) {
        Mat cannyImage;
        Mat cameraFrame;
        Mat houghImage;;
    imshow("Source Input", cameraFrame);

        cvtColor(cameraFrame, cannyImage, CV_BGR2GRAY);
         Canny( cannyImage, cannyImage, 100, 200, 3 );
         imshow("Canny", cannyImage);

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

        if (waitKey(30) >= 0)

return 0;

I have been googleing and searching around to no avail. Anyone have an pointers?

edit retag flag offensive close merge delete


You haven't release the resource of the camera(cvCaptureFromCAM and cvQueryFrame are c api, you need to deal with resource by yourself), please use c++ api(VideoCapture) instead of c api.Try your best to stick with c++ api rather than c api, this could save you from a lot of headaches.

stereomatching gravatar imagestereomatching ( 2013-10-03 20:14:01 -0500 )edit

Alright. Thanks! I changed my code, however I am still getting the same windows breakpoint error. Code posted above.

adecker246 gravatar imageadecker246 ( 2013-10-03 20:43:52 -0500 )edit

1 answer

Sort by ยป oldest newest most voted

answered 2013-10-03 21:06:48 -0500

stereomatching gravatar image

updated 2013-10-03 22:50:19 -0500

//better use cstdio and cstdlib to replace stdio.h and stdlib.h in c++  
#include <cstdio>
#include <cstdlib>
#include <iostream>

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

int main()
    cv::VideoCapture stream1(0);
        std::cerr << "cannot open camera" << std::endl;
        return -1;

    //declare the variables outside of the loop
    //to decrease the number of memory allocation
    cv::Mat cannyImage;
    cv::Mat cameraFrame;
    std::vector<cv::Vec4i> lines;
    while (true) {
        stream1 >> cameraFrame;

            std::cerr<<"the frame is empty"<<std::endl;

        cv::imshow("Source Input", cameraFrame);
        cv::cvtColor(cameraFrame, cannyImage, CV_BGR2GRAY);
        cv::Canny( cannyImage, cannyImage, 100, 200, 3 );
        cv::imshow("Canny", cannyImage);

        cv::HoughLinesP(cannyImage, lines, 1, CV_PI/180, 50, 10, 10);

        if (cv::waitKey(30) >= 0)

    return 0;

The codes run smooth on my machine(Mac OSX 10.8.x).Are you sure you link to the dll correctly?What version of your openCV?What compiler are you using?OS?If you are using gcc48, then you better recompile it, because the dll come with the packages may not compatible with it.

edit flag offensive delete link more

Question Tools

1 follower


Asked: 2013-10-03 18:43:27 -0500

Seen: 2,993 times

Last updated: Oct 03 '13