Question

I'm trying to recognize a parking lot using JavaCV

I have a image like this (with angle):

Original Image

And I would like the software to be able to recognize the places and stands out, getting the coordinates, like this (sorry for bad photoshop):

Output Image

My code until now:

imgOriginal = cvLoadImage("D:\\imagem\\original2.JPG");

imgModify = cvCreateImage(cvGetSize(imgOriginal), IPL_DEPTH_8U, 1);
imgOut = cvCloneImage(imgOriginal);

cvSmooth(imgOut, imgOut, CV_GAUSSIAN, 3);
    cvCvtColor(imgOut, imgModify, CV_BGR2GRAY);
    cvThreshold(imgModify, imgModify, 0, 255, CV_THRESH_BINARY + CV_THRESH_OTSU);
    cvErode(imgModify, imgModify, null, 1);

    CvMemStorage storage = cvCreateMemStorage(0);
    CvSeq cvSeq = cvCreateSeq(0, Loader.sizeof(CvContour.class), Loader.sizeof(CvSeq.class), storage);
    cvFindContours(imgModificada, storage, cvSeq, Loader.sizeof(CvContour.class), CV_RETR_EXTERNAL, CV_CHAIN_APPROX_SIMPLE);

    int objects = 0;
    CvRect region;
    for (; cvSeq != null; cvSeq = cvSeq.h_next()) {
        double areaObject = Math.abs(cvContourArea(cvSeq, CV_WHOLE_SEQ, 0));
        if (areaObject > 500) { //ignore small contours
            objects++;

            region = cvBoundingRect(cvSeq, 0);
            cvRectangle(imgOut, cvPoint(region.x(), region.y()), cvPoint(region.x() + region.width(), region.y() + region.height()), CvScalar.BLUE, 1, CV_AA, 0);


        }
    }
System.out.println(objects);
cvShowImage("Out", imgOut);
cvWaitKey(0);
cvReleaseImage(imgOut);

How can I do the output image? Anyone knows? Thanks.

Was it helpful?

Solution

If you apply Gabor filter :

http://en.wikipedia.org/wiki/Gabor_filter

http://mplab.ucsd.edu/tutorials/gabor.pdf

instead of gaussian, you can apply different angles and find best matching result from magnitude of response. So, the angle of gabor filter which gives you the best result is what you need. You can use this angle for drawing rectangle. For finding corner points of parking lot, you can apply basic "Connected Component Labelling" method.

If your system is real time and response time is important for you. You need to find gradient of the image by applying one of edge detection methods like "Canny"

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top