3

I've looked at JavaCV wrapper for OpenCV library and I saw that it is possible to use that library in Java for face detection on an image, but I was wondering is it possible to use that library for detecting traffic warning signs on an image and how?

I have pictures taken from the road that look like this: http://www.4shared.com/photo/5QxoVDwd/041.html and the result of detection should look sometning like this or similar: http://www.4shared.com/photo/z_pL0lSK/overlay-0.html

EDIT: After I detect red color I get this image:

enter image description here

And I have a problem detecting just the warning sign triangle shape and ignore all other shapes. I tried changing the cvApproxPoly parameters but with no result. This is my code:

public void myFindContour(IplImage image)
{
    IplImage grayImage = cvCreateImage(cvGetSize(image), IPL_DEPTH_8U, 1);
    cvCvtColor(image, grayImage, CV_BGR2GRAY);

    CvMemStorage mem;
    CvSeq contours = new CvSeq();
    CvSeq ptr = new CvSeq();
    cvThreshold(grayImage, grayImage, 150, 255, CV_THRESH_BINARY);
    mem = cvCreateMemStorage(0);

    cvFindContours(grayImage, mem, contours, Loader.sizeof(CvContour.class) , CV_RETR_CCOMP, CV_CHAIN_APPROX_SIMPLE, cvPoint(0,0));
    Random rand = new Random();

    while (contours != null && !contours.isNull()) {
        if (contours.elem_size() > 0) {
            CvSeq points = cvApproxPoly(contours, Loader.sizeof(CvContour.class),
                    mem, CV_POLY_APPROX_DP, cvContourPerimeter(contours)*0.02, 0);
            Color randomColor = new Color(rand.nextFloat(), rand.nextFloat(), rand.nextFloat());
            CvScalar color = CV_RGB( randomColor.getRed(), randomColor.getGreen(), randomColor.getBlue());
            cvDrawContours(image, points, color, CV_RGB(0,0,0), -1, CV_FILLED, 8, cvPoint(0,0));
        }
        contours = contours.h_next();
    }

    cvSaveImage("myfindcontour.png", image);

}

This is the output that i get (I used different colors for every shape, but in the final output i will use only white for detected warning sign and everything other left black):

enter image description here

ivandj
  • 43
  • 6

3 Answers3

2

You have to do the following:

  1. Detect red color on image - you will get 1bit image where: 0=non-red, 1=red.
  2. Detect triangles on created in previous step image. You can do that using approxPoly function.
ArtemStorozhuk
  • 8,715
  • 4
  • 35
  • 53
  • Thanks, I will try that definitively. Found [this](http://ganeshtiwaridotcomdotnp.blogspot.com/2011/12/javacv-simple-color-detection-using.html) article for detecting color on image. Is that what you had in mind? Hopefully I'll find something for approxPoly function you suggested, because there is not a lot of documentation for JavaCV. – ivandj Aug 03 '12 at 14:35
  • How can I use approxPoly function to detect triangles? – ivandj Aug 08 '12 at 14:52
  • I don't think I can check for sides of contour to see if there are 3 sides, since the edges of triangle are rounded. Is there a way to still detect the shapes as triangles, even with the round edges? – ivandj Aug 13 '12 at 12:15
  • @ivandj have you read docs? You have to set such parameter which will remove small sides of contour. – ArtemStorozhuk Aug 13 '12 at 12:20
0

see ,the first find the contour area. compare it with the precalculated value and keep it with in a range like

if(area>Mincontourarea && area<maxcontourare)
{
thats it  now we have the signboard do  
}

the value if calculated wouldnot be bigger than the car conotur, to get the contoutr up to my knowledge u need Moments operator

code for the momnts operator:

Moments moment = moments((cv::Mat)contours[index]);
       area = moment.m00;  //m00 gives the area of the detected contour

put the above code before the if block discussed above

if you want the x and y coordinates put a post again..

Radim Köhler
  • 122,561
  • 47
  • 239
  • 335
Chaitu
  • 11
  • 3
0

take a look of my answer, it is in c++ but using opencv it is able to detect road signs, you can take it as a good example. https://stackoverflow.com/a/52651521/8035924

Giulio Pettenuzzo
  • 786
  • 1
  • 5
  • 20