java - OpenCV + Android + Vehicle number Plate Recognition -
i'm developing android app detect vehicle number plate. did image processing findcontours level of image. need convert following c++ code opencv based android java.
this original image
this after otsu thresholding image
this andoid+opencv code (working 100%)
imageview imgview = (imageview) findviewbyid(r.id.imageview1); bitmap bmp = bitmapfactory.decoderesource(getresources(),car); //first convert bitmap 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 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);
now need extract number plate
please me convert following c++ code java+opencv:.
std::vector rects; std::vector<std::vector >::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 < 0.45) || (bbarea < 400) ){ itc= contours.erase(itc); }else{ ++itc; rects.push_back(mr); } }
looking @ http://docs.opencv.org/java , the documentation findcontours in particular
instead of
std::vector<std::vector<cv::point> > contours;
you have
java.util.arraylist<matofpoint> contours;
you can use contours.listiterator()
traverse list. below (not compiled let alone run,likely contain major blunders):
import java.util.*; import org.opencv.imgproc.imgproc; import org.opencv.core.*; /* ... */ arraylist<rotatedrect> rects = new arraylist<rotatedrect>() arraylist<matofpoint> contours = new arraylist<matofpoint>(); imgproc.findcontours(image, contours, new mat(), imgproc.retr_external, imgproc.chain_approx_none); listiterator<matofpoint> itc = contours.listiterator(); while(itc.hasnext()) { matofpoint2f mp2f = new matofpoint2f(itc.next().toarray()); rotatedrect mr = imgproc.minarearect(mp2f); double area = math.abs(imgproc.contourarea(mp2f)); double bbarea= mr.size.area(); double ratio = area / bbarea; if( (ratio < 0.45) || (bbarea < 400) ) { itc.remove(); // other deliberately making program slow, // erasing contour have purpose? } else { rects.add(mr); } }
Comments
Post a Comment