Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Object detection and splitting, clustering?

I'm currently working on an application that will split a scanned image (that contains multiple receipts) into individual receipt images.

Below is the sample image:

image description

I was able to detect the edges of each receipts in the scanned image using canny function. Below is the sample image with detected edges:

image description

... while my sample code is

Mat src = Highgui.imread(filename);
Mat gray = new Mat();

int threshold = 12;

Imgproc.cvtColor(src, gray, Imgproc.COLOR_BGR2GRAY);
Imgproc.blur(gray, gray, new Size(3, 3));
Imgproc.Canny(gray, gray, threshold, threshold * 3, 3, true);

List<MatOfPoint> contours = new ArrayList<>();
Mat hierarchy = new Mat();

Imgproc.findContours(gray, contours, hierarchy,
        Imgproc.RETR_CCOMP,
        Imgproc.CHAIN_APPROX_SIMPLE);

if (hierarchy.size().height > 0 && hierarchy.size().width > 0) {
    for (int idx = 0; idx >= 0; idx = (int) hierarchy.get(0, idx)[0]) {
        Rect rect = Imgproc.boundingRect(contours.get(idx));
        Core.rectangle(src, new Point(rect.x, rect.y),
                new Point(rect.x + rect.width, rect.y + rect.height),
                new Scalar(255, 0, 0));
    }
}

Now my problem is, I don't know how am I going to identify the 3rd receipt since unlike with the first 2 it is not enclosed in one rectangular shape which I will use as the basis for splitting the image.

I've heard that for me to extract the 3rd image, I must use a clustering algorithm like DBSCAN, unfortunately I can't find one.

Anyone knows how am I going to identify the 3rd image?

Thank you in advance!

Object detection and splitting, clustering?

I'm currently working on an application that will split a scanned image (that contains multiple receipts) into individual receipt images.

Below is the sample image:

image description

I was able to detect the edges of each receipts in the scanned image using canny function. Below is the sample image with detected edges:

image description

... while my sample code is

Mat src = Highgui.imread(filename);
Mat gray = new Mat();

int threshold = 12;

Imgproc.cvtColor(src, gray, Imgproc.COLOR_BGR2GRAY);
Imgproc.blur(gray, gray, new Size(3, 3));
Imgproc.Canny(gray, gray, threshold, threshold * 3, 3, true);

List<MatOfPoint> contours = new ArrayList<>();
Mat hierarchy = new Mat();

Imgproc.findContours(gray, contours, hierarchy,
        Imgproc.RETR_CCOMP,
        Imgproc.CHAIN_APPROX_SIMPLE);

if (hierarchy.size().height > 0 && hierarchy.size().width > 0) {
    for (int idx = 0; idx >= 0; idx = (int) hierarchy.get(0, idx)[0]) {
        Rect rect = Imgproc.boundingRect(contours.get(idx));
        Core.rectangle(src, new Point(rect.x, rect.y),
                new Point(rect.x + rect.width, rect.y + rect.height),
                new Scalar(255, 0, 0));
    }
}

Now my problem is, I don't know how am I going to identify the 3rd receipt since unlike with the first 2 it is not enclosed in one rectangular shape which I will use as the basis for splitting the image.

I've heard that for me to extract the 3rd image, I must use a clustering algorithm like DBSCAN, unfortunately I can't find one.

Anyone knows how am I going to identify the 3rd image?

Thank you in advance!

Object detection and splitting, clustering?

I'm currently working on an application that will split a scanned image (that contains multiple receipts) into individual receipt images.

Below is the sample image:

image description

I was able to detect the edges of each receipts in the scanned image using canny function. Below is the sample image with detected edges:

image description

... while my sample code is

Mat src = Highgui.imread(filename);
Mat gray = new Mat();

int threshold = 12;

Imgproc.cvtColor(src, gray, Imgproc.COLOR_BGR2GRAY);
Imgproc.blur(gray, gray, new Size(3, 3));
Imgproc.Canny(gray, gray, threshold, threshold * 3, 3, true);

List<MatOfPoint> contours = new ArrayList<>();
Mat hierarchy = new Mat();

Imgproc.findContours(gray, contours, hierarchy,
        Imgproc.RETR_CCOMP,
        Imgproc.CHAIN_APPROX_SIMPLE);

if (hierarchy.size().height > 0 && hierarchy.size().width > 0) {
    for (int idx = 0; idx >= 0; idx = (int) hierarchy.get(0, idx)[0]) {
        Rect rect = Imgproc.boundingRect(contours.get(idx));
        Core.rectangle(src, new Point(rect.x, rect.y),
                new Point(rect.x + rect.width, rect.y + rect.height),
                new Scalar(255, 0, 0));
    }
}

Now my problem is, I don't know how am I going to identify the 3rd receipt since unlike with the first 2 it is not enclosed in one rectangular shape which I will use as the basis for splitting the image.

I've heard that for me to extract the 3rd image, I must use a clustering algorithm like DBSCAN, unfortunately I can't find one.

Anyone knows how am I going to identify the 3rd image?

Thank you in advance!