Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version
//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);
    if(!stream1.isOpened()){
        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;
    //cv::Mat houghImage;
    std::vector<cv::Vec4i> lines;
    while (true) {
        stream1 >> cameraFrame;

        if(cameraFrame.empty()){
            std::cerr<<"the frame is empty"<<std::endl;
            break;
        }

        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);
        //cv::imshow("hough lines", houghImage);

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

    }
    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.

//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);
    if(!stream1.isOpened()){
        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;
    //cv::Mat houghImage;
    std::vector<cv::Vec4i> lines;
    while (true) {
        stream1 >> cameraFrame;

        if(cameraFrame.empty()){
            std::cerr<<"the frame is empty"<<std::endl;
            break;
        }

        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);
        //cv::imshow("hough lines", houghImage);

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

    }
    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.