How to set Region of Interest in OpenCV - JAVA -
How to set Region of Interest in OpenCV - JAVA -
i have image of business card on have preformed perspective transform in order extract card image. now, want o feed image tesseract-ocr engine. before that, want extract part of involvement have text , feed instead of whole image. how can extract text card.
here illustration of image:
here code going you. did first finding contours of text available on image , using contours on actual image.
mat img_grayroi = highgui.imread(perspective__transform_file, highgui.cv_load_image_grayscale); imgproc.gaussianblur(img_grayroi, img_grayroi, new size(15,15),50.00);imgproc.thresh_binary_inv, 15, 4); imgproc.threshold(img_grayroi, img_grayroi, -1, 255, imgproc.thresh_binary_inv+imgproc.thresh_otsu); imgproc.dilate(img_grayroi, img_grayroi, imgproc.getstructuringelement(imgproc.morph_rect, new size(2, 2))); mat heirarchy= new mat(); point shift=new point(150,0); list<matofpoint> contours = new arraylist<matofpoint>(); imgproc.findcontours(img_grayroi, contours, heirarchy, imgproc.retr_list, imgproc.chain_approx_simple); double[] cont_area =new double[contours.size()]; for(int i=0; i< contours.size();i++){ if (imgproc.contourarea(contours.get(i)) > 50 ){ rect rect = imgproc.boundingrect(contours.get(i)); cont_area[i]=imgproc.contourarea(contours.get(i)); if (rect.height > 25){ core.rectangle(result, new point(rect.x,rect.y), new point(rect.x+rect.width,rect.y+rect.height),new scalar(0,0,255)); system.out.println(rect.x +"-"+ rect.y +"-"+ rect.height+"-"+rect.width); highgui.imwrite(roi_file,result); } } }
perspective_transform source image on need find roi.
hope helps.
java opencv ocr tesseract
Comments
Post a Comment