1

I am working on a project of using a camera to take a picture for detecting the available parking space in the carpark.

I am going to use image subtraction for comparing the empty and occupied situation in the carpark.

These are the two picture for comparison

This is the resulting image:

Can anyone tell me how to

  1. recognize and put a rectangle outside the vehicle

  2. output the number of the car for my further usage?

Here is the code:

    // Test.cpp

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

#include<iostream>

using namespace std;
using namespace cv;

Mat bg_frame;
Mat cam_frame;
Mat diff_frame;
char charCheckForEscKey = 0;

int main() {

    while (charCheckForEscKey != 27 /*&& capWebcam.isOpened()*/) {

    bg_frame = imread("Picture1.jpg",0);
    cam_frame = imread("Picture4.jpg",0);

    resize(cam_frame, cam_frame, bg_frame.size());

    imshow("test1", bg_frame);
    imshow("test2", cam_frame);

    absdiff(bg_frame, cam_frame, diff_frame);

    threshold(diff_frame, diff_frame, 80, 255, THRESH_BINARY);


    //erode(diff_frame, diff_frame, getStructuringElement(MORPH_RECT, Size(1, 1)));

    dilate(diff_frame, diff_frame, Mat(), Point(-1, -1));

    //Canny(diff_frame, diff_frame, 30, 70);

    imshow("test3", diff_frame);

    charCheckForEscKey = cv::waitKey(1);            // delay (in ms) and get key press, if any
    }

    return(0);

}

1 Answer 1

1

Your problem is very complex to be solved in a single post, but I will give you some pointers on how to solve it.

The idea is correct, you should compare the differences between images. I would not recommend comparing directly pixel by pixel, but its a fast solution for a prototype. For more robust methods checkout background subtraction c++ and more extense but in python

As for counting the number of vehicles, given the complexity of the scene (overlapping cars, non uniform parking) then I would recommend manually specifying a region of interest (ROI) for each car. Applying the method you already have for each ROI, you can detect if that parking space is occupied or not.

On how to draw a rectangle in opencv.

void rectangle(Mat& img, Point pt1, Point pt2, const Scalar& color, int thickness=1, int lineType=8, int shift=0);
Sign up to request clarification or add additional context in comments.

2 Comments

Thank you so much, can you talk about more about ROI?
its simply a rectangular section of the image, a series of pixels that define a region. In your case its a region per parking space. This way you can split the global problem to a simple case of "is this image a car or an empty park space?"

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.