Crop rectangle with specific border color and JAVA cetane background color

I have an image with some rectangles inside it. I only need to crop rectangles with red border and white background using (Java) or JavaCV.

for example, I have a picture of a car with a license plate. Each letter on a license plate has a red rectangle around it and a white background.

what I'm looking for is to crop each letter in one image. letters are indicated by a red rectangle around each and against a white background.

Any suggestions? Thanks to

+3


source to share


2 answers


  • Change color space to HSV

     IplImage* imgHSV = cvCreateImage(cvGetSize(img), 8, 3);
     cvCvtColor(img, imgHSV, CV_BGR2HSV);
    
          

  • Get tint channel only:

    cvSplit( imgHSV, h_plane, s_plane, v_plane, 0 );
    
          

  • Make a threshold for looking for red:

    cvInRangeS(h_plane, cvScalar(x, x, x), cvScalar(x, x, x), imgThreshed);
    
          

    x is the range of red in the HSV color model.

    After that, you will have a white and black image, where white will be red in your original image (they should be rectangular as you said).

  • Then use the cvFindContours function.

    int contoursCont = cvFindContours( imgThreshed, storage,&contours,sizeof(CvContour),CV_RETR_LIST,CV_CHAIN_APPROX_SIMPLE,cvPoint(0,0));
    
          

  • To have the linked rectangle (rectangle) use (for each path):

    CvBox2D box = cvMinAreaRect2( @current_contour@,
                            CvMemStorage* storage CV_DEFAULT(NULL))
    
          

    To check the background color, count its histogram and check if the bin values ​​are only 255 and 0 (these are the white and black values).



Hope this is helpful!

0


source


You can try this:

  • Find a group of red pixels close to each other.
  • Find all red pixels associated with them, bucket fill style
  • Calculate the bounding box of all found pixels
  • Maybe check if all red pixels are close to the edge of the bounding rectangle
  • Make sure the inside of the box is mostly white.


This should work as long as your boxes are not interrupted and overlap.

0


source







All Articles