Ask Your Question

fi8er1's profile - activity

2020-04-07 03:10:46 -0600 received badge  Popular Question (source)
2017-12-01 12:06:35 -0600 received badge  Student (source)
2017-12-01 08:45:15 -0600 marked best answer How to remove background of a selected contour
@Override
public Mat onCameraFrame(CameraBridgeViewBase.CvCameraViewFrame inputFrame) {
    Mat srcMat = inputFrame.rgba();
    Mat processedMat = new Mat();
    Imgproc.cvtColor(srcMat, processedMat, Imgproc.COLOR_BGR2GRAY);
    Imgproc.GaussianBlur(processedMat, processedMat, new Size(3, 3), 0);
    Imgproc.threshold(processedMat, processedMat, 127, 255, Imgproc.THRESH_BINARY);
    List<MatOfPoint> contours = new ArrayList<>();
    Mat hierarchy = new Mat();
    Imgproc.findContours(processedMat, contours, hierarchy, Imgproc.RETR_EXTERNAL, Imgproc.CHAIN_APPROX_SIMPLE);
    Log.e(TAG, "ContourSize: " + contours.size());
    double maxVal = 0;
    int maxValIdx = 0;
    for (int contourIdx = 0; contourIdx < contours.size(); contourIdx++) {
        double contourArea = Imgproc.contourArea(contours.get(contourIdx));
        if (maxVal < contourArea) {
            maxVal = contourArea;
            maxValIdx = contourIdx;
        }
    }
    Imgproc.drawContours(srcMat, contours, maxValIdx, new Scalar(0,255,0),  -2);
    if (!contours.isEmpty()) {
        Log.e("largestContour", "" + contours.get(maxValIdx));
        Rect rect = Imgproc.boundingRect(contours.get(maxValIdx));
        srcMat.submat(rect);
    }
        return srcMat; }

Input Image: https://ibin.co/3irmfXKjYocz.jpg

Output:

image description

As you can see I have applied .submat but I'm not sure why is it masking the inners of the contour instead of the outer surface. Moreover, filtering the largest contour is also not consistent. Any ideas on how can I make it more robust based on the dimensions of the ticket as my aim is to scan tickets with very same dimensions.

As a newbie OpenCV enthusiast, I want someone to guide me with my final mission here, which is to get the year, month, date, and time from the calender in the ticket and show it in text form. The ticket will have punched holes as markings. So, what I have in mind is to track each (hole) blob and extract it along with it's surrounding digits to know which number it was based on its surrounding, and do this to all of the blobs (holes) with some hierarchy in place to know if the extraction was from the 'year' field or month or day field respectively. Or is there any other better approach for this?

2017-11-29 03:27:11 -0600 commented answer How to remove background of a selected contour

I'm having trouble finding tutorials or examples in java for my use and can't get my around python example either. Is th

2017-11-29 02:15:57 -0600 received badge  Enthusiast
2017-11-28 10:32:13 -0600 commented question How to remove background of a selected contour

Sample Token Scanned: https://ibin.co/3irqGlxXezL3.jpg

2017-11-28 10:30:25 -0600 asked a question How to remove background of a selected contour

How to remove background of a selected contour @Override public Mat onCameraFrame(CameraBridgeViewBase.CvCameraViewFrame

2017-11-24 13:16:15 -0600 received badge  Editor (source)
2017-11-24 13:16:15 -0600 edited question Help: Android OMR OC

Help: Android OMR OC I have been developing Android apps for more than two years now. I’m trying to create a OMR system

2017-11-24 13:06:38 -0600 asked a question Help: Android OMR OC

Help: Android OMR OC I have been developing Android apps for more than two years now. I’m trying to create a OMR system