title: OpenCV + Android + Vehicle number Plate Recognition
body: <p>I'm developing a Android app to detect vehicle number plate. i did image processing up to findContours level of image. Now i need to convert following C++ code to Opencv Based Android java.  </p>
  
  <p>This is original <a href="http://rnd.azoft.com/wp-content/uploads/2014/05/vehicle-license-plate-recognition-algorithm-02.jpg" rel="nofollow noreferrer">image</a> </p>
  
  <p><img src="https://i.stack.imgur.com/F8MQx.jpg" alt="enter image description here"></p>
  
  <p>This is after Otsu thresholding <a href="http://rnd.azoft.com/wp-content/uploads/2014/05/vehicle-license-plate-recognition-algorithm-12.jpg" rel="nofollow noreferrer">image</a></p>
  
  <p><img src="https://i.stack.imgur.com/MKGhR.jpg" alt="enter image description here"></p>
  
  <p>This is my andoid+opencv code (working 100%)</p>
  
  <pre><code>ImageView imgView  = (ImageView) findViewById(R.id.imageView1);
  Bitmap bmp = BitmapFactory.decodeResource(getResources(),car);
  //First convert Bitmap to Mat
  Mat ImageMatin = new Mat ( bmp.getHeight(), bmp.getWidth(), CvType.CV_8U, new Scalar(4));    
  Mat ImageMatout = new Mat ( bmp.getHeight(), bmp.getWidth(), CvType.CV_8U, new Scalar(4));
  Mat ImageMatBk = new Mat ( bmp.getHeight(), bmp.getWidth(), CvType.CV_8U, new Scalar(4));
  Mat ImageMatTopHat = new Mat ( bmp.getHeight(), bmp.getWidth(), CvType.CV_8U, new Scalar(4));
  Mat temp = new Mat ( bmp.getHeight(), bmp.getWidth(), CvType.CV_8U, new Scalar(4));
  
  Bitmap myBitmap32 = bmp.copy(Bitmap.Config.ARGB_8888, true);
  Utils.bitmapToMat(myBitmap32, ImageMatin);  
  
  
  //Converting RGB to Gray.
  Imgproc.cvtColor(ImageMatin, ImageMatBk, Imgproc.COLOR_RGB2GRAY,8);    
  
  Imgproc.dilate(ImageMatBk, temp, Imgproc.getStructuringElement(Imgproc.MORPH_RECT, new Size(9, 9)));
  Imgproc.erode(temp, ImageMatTopHat, Imgproc.getStructuringElement(Imgproc.MORPH_RECT, new Size(9,9)));  
  
  //Core.absdiff(current, previous, difference);
  Core.absdiff(ImageMatTopHat, ImageMatBk, ImageMatout);      
  
  //Sobel operator in horizontal direction.    
  Imgproc.Sobel(ImageMatout,ImageMatout,CvType.CV_8U,1,0,3,1,0.4,Imgproc.BORDER_DEFAULT);
  
  //Converting GaussianBlur                   
  Imgproc.GaussianBlur(ImageMatout, ImageMatout, new Size(5,5),2);    
  
  Imgproc.dilate(ImageMatout, ImageMatout, Imgproc.getStructuringElement(Imgproc.MORPH_RECT, new Size(3,3)));
  
  Mat element = Imgproc.getStructuringElement(Imgproc.MORPH_RECT, new Size(17, 3));    
  Imgproc.morphologyEx(ImageMatout, ImageMatout, Imgproc.MORPH_CLOSE, element);
  
  //threshold image
  Imgproc.threshold(ImageMatout, ImageMatout, 0, 255, Imgproc.THRESH_OTSU+Imgproc.THRESH_BINARY);
  </code></pre>
  
  <p>Now I need to extract number Plate </p>
  
  <p>Please help me to convert following C++ code to java+opencv:.</p>
  
  <pre><code>std::vector rects;  
  std::vector&lt;std::vector &gt;::iterator itc = contours.begin();  
  while (itc != contours.end())  
  {  
      cv::RotatedRect mr = cv::minAreaRect(cv::Mat(*itc)); 
      float area = fabs(cv::contourArea(*itc));  
      float bbArea=mr.size.width * mr.size.height;  
      float ratio = area/bbArea;  
      if( (ratio &lt; 0.45) || (bbArea &lt; 400) ){  
          itc= contours.erase(itc);  
      }else{  
          ++itc;  
          rects.push_back(mr);  
      }  
  } 
  </code></pre>