Ask Your Question

Kampi's profile - activity

2016-03-15 06:20:34 -0600 asked a question OpenCV and MJPEG USB Webcam

Hello,

I have an Imagingsource DFK AFU050-L34 USB Webcam and I wan´t use OpenCV to read out this Camera. My Code looks like this:

while(true)
{ 
    Mat frame
    VideoCapture cap;
    cap.open(0);

    if (!cap.isOpened())
    {
        cout << "Cannot open the video cam" << endl;
        return -1;
    }

    cap.set(CV_CAP_PROP_FOURCC, CV_FOURCC('M', 'J', 'P', 'G'));
    cap.set(CV_CAP_PROP_FRAME_WIDTH, 1280.0);
    cap.set(CV_CAP_PROP_FRAME_HEIGHT, 720.0);
    cap.set(CV_CAP_PROP_FPS, 30.0);

    bool bSuccess = cap.read(frame); 

    if (!bSuccess) //if not success, break loop
    {
        cout << "Cannot read a frame from video stream" << endl;
        break;
    }

    imshow("MyVideo", frame); 

    waitKey(100);
}

After starting this programm, I´ve got a black image and my Mat Frame has a size of 1280x720. I use OpenCV 3.1 with Visual Studio 2013 on a windows 7 machine.

How can I fix this black image? Thanks for help!

2016-02-18 09:09:32 -0600 received badge  Enthusiast
2016-02-15 05:59:22 -0600 received badge  Supporter (source)
2016-02-15 05:59:17 -0600 received badge  Scholar (source)
2016-02-15 03:35:19 -0600 answered a question Detect cars in video

Hello,

thank you for your response. I have to wait a few days to answer you, so please excuse me. I`ve changed my code to this:

    Camera >> RawImage;
    if (RawImage.empty())
    {
        cout << "Video beendet..." << endl;
        destroyAllWindows();
        break;
    }

    RawImage_Copy = RawImage.clone();
    BackgroundMask(RawImage_Copy, Mask);
    Mat Fill = getStructuringElement(MORPH_ELLIPSE, Size(2, 2), Point(1, 1));
    morphologyEx(Mask, Mask, CV_MOP_CLOSE, Fill);

    threshold(Mask, BinaryImage, 128, 255, CV_THRESH_BINARY);

    findContours(BinaryImage.clone(), Kontur, CV_RETR_EXTERNAL, CV_CHAIN_APPROX_NONE);

    for (int i = 0; i< Kontur.size(); i++)
    {
        Rect Object = boundingRect(Kontur[i]);
        ROI = RawImage_Copy(Object);
        resize(ROI, ROI, Size(200, 200));
        imshow("ROI", ROI);
    }

    imshow("Rohbild", RawImage);
    imshow("Binary Image", BinaryImage);
    imshow("Mask", Mask);
    waitKey(1);

This solution works pretty good.

image description

The next step is to count the cars passing an imaginary area. My first idea was to define a area and check the x-coordinates of a corner from the bounding rect of each car and check it with my box. If the x-coordinate of the bounding rect is inside my box, the software should increase a counter. But this solution doesn´t work very well. Does OpenCV provide a better solution to realize this idea?

2016-02-11 05:21:43 -0600 asked a question Detect cars in video

Hello,

I´m new with OpenCV and I want detect cars in a webcam or a video file. This is my current solution:

while (Camera.read(RawImage))
{
    Camera >> RawImage;
    BackgroundMask(RawImage, Mask);
    cv::threshold(Mask, BinaryMask, 100, 255, cv::THRESH_BINARY);
    Mat NewImage(RawImage.rows, RawImage.cols, CV_8UC3, Scalar(0, 255, 0));
    RawImage.copyTo(NewImage, BinaryMask);

    imshow("Rawimage", RawImage);
    imshow("New Image", NewImage);
    waitKey(30);
}

I get a green Image with the filtered cars in it. Now I want to draw a box around this cars. How can I do it in an easy way?

Thank you for help :)