java - how to remove unwanted lines/noise in OpenCV? -


i developing ocr app android(building java application). want detect text image captured camera , pre-processing using opencv,but getting lines being read text,i have followed approach:

1-rgb greyscale 2-threshold 3-gaussian blur 4-median blur 5-dilation 6-erosion

results atleast better before still not getting right results. how can remove noise,what general sequence of filters these can applied image improve result ocr. new opencv please guide me through. thanks.

old image


updated image


from above image able find result no 3,but when contours drawn somthing dont want there noise also.what missing here.dont know further. revised code:

package simple_contours;  import java.util.arraylist; import java.util.list;  import org.opencv.core.core; import org.opencv.core.cvtype; import org.opencv.core.mat; import org.opencv.core.matofpoint; import org.opencv.core.point; import org.opencv.core.rect; import org.opencv.core.scalar; import org.opencv.core.size; import org.opencv.highgui.highgui; import org.opencv.imgproc.imgproc;  public class main {      public static void main(string[] args) {         system.loadlibrary(core.native_library_name);         mat src_img,src_grey,src_blur,src_thresh,src_dilate,dest_img;          src_img=highgui.imread("n_num.jpg",imgproc.color_bgr2gray);           src_grey=new mat(src_img.size(), core.depth_mask_8u);         src_blur=new mat(src_img.size(), core.depth_mask_8u);         src_thresh=new mat(src_img.size(), core.depth_mask_8u);         src_dilate=new mat(src_img.size(), core.depth_mask_8u);         dest_img=mat.zeros(640,480, cvtype.cv_8uc3);         core.bitwise_not(dest_img, dest_img);         highgui.imwrite("dest.jpg", dest_img);          imgproc.cvtcolor(src_img, src_grey, imgproc.color_bgr2gray);         imgproc.gaussianblur(src_grey, src_blur, new size(3, 3), 0);         imgproc.threshold(src_blur, src_thresh, 80, 255, imgproc.thresh_binary_inv);         imgproc.dilate(src_thresh, src_dilate, imgproc.getstructuringelement(imgproc.morph_rect, new size(2, 2)));          highgui.imwrite("threshold.jpg", src_thresh);         highgui.imwrite("dilate.jpg", src_dilate);               list<matofpoint> contours = new arraylist<matofpoint>();             mat heirarchy= new mat();           point shift=new point(150,0);           imgproc.findcontours(src_dilate, contours,heirarchy, imgproc.retr_tree,imgproc.chain_approx_simple,shift);           double[] cont_area =new double[contours.size()];                for(int i=0; i< contours.size();i++)              {                  rect rect = imgproc.boundingrect(contours.get(i));                 cont_area[i]=imgproc.contourarea(contours.get(i));                  system.out.println("hight: "+rect.height);                 system.out.println("width: "+rect.width);                 system.out.println("area: "+cont_area[i]);               //system.out.println(rect.x +","+rect.y+","+rect.height+","+rect.width);                    core.rectangle(src_img, new point(rect.x,rect.y), new point(rect.x+rect.width,rect.y+rect.height),new scalar(0,0,255));                   imgproc.drawcontours(dest_img, contours, i, new scalar(0,0,0),-1,8,heirarchy,2,shift);                   core.rectangle(dest_img, new point(rect.x,rect.y), new point(rect.x+rect.width,rect.y+rect.height),new scalar(0,255,0));          }               highgui.imwrite("final.jpg", dest_img);              highgui.imwrite("original.jpg", src_img);     }  } 

i think able go far erode/dilate options. issue noise little more noise contains artefacts not dissimilar of characters trying detect.

i suggest solution need involve detecting contours in image. first should prepare image make more manageable contouring process.

i've used following sequence in past:

  • gaussian blur
  • adaptivethreshold
  • negativeimage
  • dilate

now can findcontours. should pick out letters , undesirable artefacts. need eliminate artefacts, might need number of strategies such as:

  • work out area of bounding box , eliminate areas small letters
  • check width of bounding box versus height: eliminate heights small

there more sophisticated approaches such trying find axis runs through middle of larger contours, give position , direction of characters (say rotated rect); use information ignore other pixels not in region.

sorry it's not simple solution complex problem might need experiment bit , build multiple strategies remove unwanted artefacts.


Comments

Popular posts from this blog

PHPMotion implementation - URL based videos (Hosted on separate location) -

javascript - Using Windows Media Player as video fallback for video tag -

c# - Unity IoC Lifetime per HttpRequest for UserStore -