0

I am searching for how to extract a digital number from the image in android. I have to take a picture then i need to get numbers from image. OpenCV is a option . can we convert opencv into android ? Kindly suggest me any proper way. I will be grateful to you.

M.ArslanKhan
  • 3,640
  • 8
  • 34
  • 56

3 Answers3

1

OpenCV supports Android platform. You have to set up OpenCV4Android, it's instructions step by step here.

http://docs.opencv.org/doc/tutorials/introduction/android_binary_package/O4A_SDK.html

However OpenCV is not an option but only a step. Then you have to use a character recognition engine. Most popular one is Tesseract-ocr. But it is really not easy task.

Also, they often recognize all characters. If you could achieve it, extracting the digits will be the easiest part in Java.

Faruk Yazici
  • 2,344
  • 18
  • 38
0

this works for me you just need to specify the number size` ArrayList output=new ArrayList<>();

    cvtColor(input,input,COLOR_BGRA2GRAY);


    Mat img_threshold = new Mat();
    threshold(input, img_threshold, 60, 255,THRESH_BINARY_INV);
    Mat img_contours =copy(img_threshold);
    //Find contours of possibles characters


    List<MatOfPoint> contours = new ArrayList<MatOfPoint>();
    findContours(img_contours, contours,new Mat(), Imgproc.RETR_EXTERNAL, Imgproc.CHAIN_APPROX_NONE); // all pixels of each contours
    contours=sort(contours);


    // Draw blue contours on a white image
    Mat result=copy(img_threshold);
    cvtColor(result, result, COLOR_GRAY2BGR);
    drawContours(result,contours,
            -1, // draw all contours
            new Scalar(0,0,255), // in blue
            1); // with a thickness of 1


    //Start to iterate to each contour founded
    ListIterator<MatOfPoint> itc = contours.listIterator();

    //Remove patch that are no inside limits of aspect ratio and area.
    while (itc.hasNext())
    {
        //Create bounding rect of object
        MatOfPoint mp = new MatOfPoint(itc.next().toArray());
        Rect mr = boundingRect(mp);
        rectangle(result,new Point(mr.x,mr.y),new Point(mr.x+mr.width,mr.y+mr.height),new Scalar(0,255,0));

        Mat auxRoi=new Mat(img_threshold,mr);


        if (OCR_verifySizes(auxRoi))
        {
            output.add(preprocessChar(auxRoi));
        }
    }

    return output;`