Ask Your Question
0

getting the most prominent green object in the scene

asked 2014-09-16 03:21:38 -0600

prasanna aarthi gravatar image

updated 2014-09-16 06:41:37 -0600

thdrksdfthmn gravatar image

I am trying to recognize pedestrian traffic signal.I am converting the image to HSV color space, then applying in-range function to get only green lights.

This is my code:

public void onManagerConnected(int status) {
   switch (status) {
      case LoaderCallbackInterface.SUCCESS:
      {
         Log.i(TAG, "OpenCV loaded successfully...................");
         Mat img = null;
         try {
            img = Utils.loadResource(getBaseContext(), R.drawable.glarrygreen, Highgui.CV_LOAD_IMAGE_COLOR);
         } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
         }
         Mat mHSV = new Mat();
         Mat mRgba2=new Mat();
         Mat mHSVThreshed=new Mat();
         Imgproc.cvtColor(img, mHSV, Imgproc.COLOR_BGR2HSV,3);
         //This works for red lights
         Core.inRange(mHSV, new Scalar(0, 64, 200), new Scalar(69, 255, 255), mHSVThreshed);
         //this works for green lights
         Core.inRange(mHSV, new Scalar(85, 64, 200), new Scalar(170, 255, 255), mHSVThreshed);
         Imgproc.cvtColor(mHSVThreshed, img, Imgproc.COLOR_GRAY2BGR, 0);
         Imgproc.cvtColor(img, mRgba2, Imgproc.COLOR_BGR2RGBA, 0);
         Bitmap bmp = Bitmap.createBitmap(img.cols(), img.rows(), Bitmap.Config.ARGB_8888);
         Utils.matToBitmap(mRgba2, bmp);
      }
   }
}

Here is my input and output images image description

Now I need to filter out other green signals in the scene.How do I do this?How do I get the most prominent green signal in the scene.

image description

edit retag flag offensive close merge delete

Comments

1

What do you mean by "most prominent green signal"? The greater green object?

thdrksdfthmn gravatar imagethdrksdfthmn ( 2014-09-16 06:47:17 -0600 )edit

yeah the greater green object

prasanna aarthi gravatar imageprasanna aarthi ( 2014-09-16 23:59:16 -0600 )edit

1 answer

Sort by ยป oldest newest most voted
1

answered 2014-09-17 02:44:05 -0600

thdrksdfthmn gravatar image

updated 2014-09-18 10:39:02 -0600

In this case of "finding the larger green area", starting from the binary image that you have shown, you can do it in 2 ways:

  1. using fitEllipse
  2. using minAreaRect

The idea is that you have the white spots. Based on this you need to find the contours and then find the minimum fitting ellipse or rectangle (in fact they are both RotatedRect). Then it is simple to compute the area of that contour based on mathematics and just pick the biggest one.

Another thing: because the white regions are having holes, you can do a morphology operation (ex: closing) for making a more compact area.


Ok, I shall add: You can also filter based on the eccentricity (or aspect ratio): if the ellipse is very long (or longer_axis/shorter_axis > a_threshold), you shall eliminate it. I have thought of this because of the green regions on the zebra mark, that after closing may get a very big region (and in my opinion very tall).

edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2014-09-16 03:21:38 -0600

Seen: 914 times

Last updated: Sep 18 '14