Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

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?