Methods and systems for detecting stamps in scanned documents
Systems and methods for detecting stamps include if at least one regular shape in an image of a document is detected then outputting said at least one regular shape as a stamp; else: removing at least one of text, lines, and noise in the image of the document; and if at least one closed shape is remaining in the image of the document, then inscribing said at least one closed shape and outputting said at least one inscribed closed shape as a stamp; else if at least one open shape is remaining in the image of the document, then enclosing said at least one open shape and outputting said at least one enclosed shape as a stamp.
1 . A sequential computerized algorithmic method for detecting stamps in documents, the method comprising, using a computer processor:
if at least one regular shape in an image of a document is detected then outputting said at least one regular shape as a stamp, wherein detecting at least one regular shape in the image of the document comprises:
detecting edges in the image of the document;
calculating contours in the image of the document;
filtering the calculated contours to identify at least one closed contour;
calculating an area of the at least one closed contour;
iteratively comparing the area of the at least one closed contour with an area of a circumscribing shape selected from a predefined list of regular shapes to determine if the at least one closed contour is the same regular shape as the circumscribing shape; and
outputting the closed contour as a regular shape stamp; else:
removing at least one of text, lines, and noise in the image of the document; and
if at least one closed shape is remaining in the image of the document, then inscribing said at least one closed shape and outputting said at least one inscribed closed shape as a stamp; else
if at least one open shape is remaining in the image of the document, then enclosing said at least one open shape and outputting said at least one enclosed shape as a stamp.
2 . The sequential algorithmic method of claim 1 , wherein the at least one regular shape comprises at least one of: a circle, an ellipse, a triangle, a square, or a rectangle.
3 . The sequential algorithmic method of claim 1 , wherein detecting edges comprises using one of a Canny algorithm or a Laplace algorithm.
4 . The sequential algorithmic method of claim 1 , comprising detecting at least one colored stamp in the image of the document, said detecting comprising:
converting the image of the document to an HSV color space;
selecting a first predefined H value interval;
for the selected H value interval:
calculating an S component which minimizes a quantity of white pixel blobs in the converted image of the document;
binarizing a resulting image having said S component;
inverting the binarized image;
applying an OR mask to the image of the document using the inverted image; and
detecting at least one regular shape in the masked image of the document and outputting said at least one regular shape as a colored stamp; and
iteratively repeating for a different H value interval if no colored stamp is output.
5 . The sequential algorithmic method of claim 1 , wherein inscribing at least one remaining closed shape in the image of the document comprises:
identifying large objects in the image relative to a font size;
detecting edges in the image of the document;
calculating at least one contour in the image of the document;
obtaining a convex hull of the at least one contour;
determining a shape of the convex hull by iteratively inscribing a maximum shape selected from a predefined list of regular shapes inside the convex hull; and
applying a mask of the determined shape to the image of the document and outputting the result as a stamp.
6 . The sequential algorithmic method of claim 1 , wherein enclosing at least one remaining open shape in the image of the document comprises:
identifying large objects in the image relative to a font size;
detecting edges in the image of the document;
calculating one or more contours in the image of the document;
filtering the one or more contours to identify at least one contour with points approximating a shape selected from a predefined list of regular shapes;
enclosing the at least one contour with the selected shape;
determining if the at least one contour is the same shape as the selected shape; and
applying a mask of the selected shape to the image of the document and outputting the result as a stamp.
7 . The sequential algorithmic method of claim 1 , further comprising comparing a pre-stored template of a stamp with the image of the document using a k nearest neighbor (KNN) algorithm to identify at least a portion of the template stamp in the image of the document.
8 . The sequential algorithmic method of claim 1 , comprising receiving user input verifying the output stamp as an actual stamp, and automatically classifying, based on the user input, the image of the document as stamped or not stamped.
9 . The sequential algorithmic method of claim 1 , comprising editing the image of the document to remove the output stamp from the image of the document and implementing an optical character recognition process to identify text in the edited image.
10 . A system for detecting stamps in documents, the system comprising:
at least one computer processor; and
a memory containing instructions which, when executed by the at least one processor, cause the at least one processor to perform a sequential algorithmic method, the sequential algorithmic method comprising the steps of:
if at least one regular shape in an image of a document is detected then outputting said at least one regular shape as a stamp; else:
removing at least one of text, lines, and noise in the image of the document; and
if at least one closed shape is remaining in the image of the document, then inscribing said at least one closed shape and outputting said at least one inscribed closed shape as a stamp; else
if at least one open shape is remaining in the image of the document, then enclosing said at least one open shape and outputting said at least one enclosed shape as a stamp, wherein the at least one processor is configured to enclose at least one remaining open shape in the image of the document by:
identifying large objects in the image relative to a font size;
detecting edges in the image of the document;
calculating one or more contours in the image of the document;
filtering the one or more contours to identify at least one contour with points approximating a shape selected from a predefined list of regular shapes;
enclosing the at least one contour with the selected shape;
determining if the at least one contour is the same shape as the selected shape;
applying a mask of the selected shape to the image of the document and outputting the result as a stamp.
11 . The system of claim 10 , wherein the at least one regular shape comprises at least one of: a circle, an ellipse, a triangle, a square, or a rectangle.
12 . The system of claim 10 wherein the at least one processor is configured to detect at least one regular shape in the image of the document by:
detecting edges in the image of the document;
calculating contours in the image of the document;
filtering the calculated contours to identify at least one closed contour;
calculating an area of the at least one closed contour;
iteratively comparing the area of the at least one closed contour with an area of a circumscribing shape selected from a predefined list of regular shapes to determine if the at least one closed contour is the same regular shape as the circumscribing shape; and
outputting the closed contour as a regular shape stamp.
13 . The system of claim 12 , wherein the at least one processor is configured to detect edges using one of a Canny algorithm or a Laplace algorithm.
14 . The system of claim 10 , wherein the at least one processor is configured to detect at least one colored stamp in the image of the document, by:
converting the image of the document to an HSV color space;
selecting a first predefined H value interval;
for the selected H value interval:
calculating an S component which minimizes a quantity of white pixel blobs in the converted image of the document;
binarizing a resulting image having said S component;
inverting the binarized image;
applying an OR mask to the image of the document using the inverted image; and
detecting at least one regular shape in the masked image of the document and outputting said at least one regular shape as a colored stamp; and
iteratively repeating for a different H value interval if no colored stamp is output.
15 . The system of claim 10 , wherein the at least one processor is configured to inscribe at least one remaining closed shape in the image of the document by:
identifying large objects in the image relative to a font size;
detecting edges in the image of the document;
calculating at least one contour in the image of the document;
obtaining a convex hull of the at least one contour;
determining a shape of the convex hull by iteratively inscribing a maximum shape selected from a predefined list of regular shapes inside the convex hull; and
applying a mask of the determined shape to the image of the document and outputting the result as a stamp.
16 . The system of claim 10 , wherein the at least one processor is further configured to compare a pre-stored template of a stamp with the image of the document using a k nearest neighbor (KNN) algorithm to identify at least a portion of the template stamp in the image of the document.
17 . The system of claim 10 , wherein the at least one processor is configured to receive user input verifying the output stamp as an actual stamp, and automatically classifying, based on the user input, the image of the document as stamped or not stamped.
18 . A sequential computerized algorithmic method for detecting stamps in documents, the method comprising, using a computer processor:
if at least one regular shape in an image of a document is detected then outputting said at least one regular shape as a stamp; else:
removing at least one of text, lines, and noise in the image of the document; and
if at least one closed shape is remaining in the image of the document, then inscribing said at least one closed shape and outputting said at least one inscribed closed shape as a stamp, wherein inscribing at least one remaining closed shape in the image of the document comprises:
identifying large objects in the image relative to a font size;
detecting edges in the image of the document;
calculating at least one contour in the image of the document;
obtaining a convex hull of the at least one contour;
determining a shape of the convex hull by iteratively inscribing a maximum shape selected from a predefined list of regular shapes inside the convex hull; and
applying a mask of the determined shape to the image of the document and outputting the result as a stamp; else
if at least one open shape is remaining in the image of the document, then enclosing said at least one open shape and outputting said at least one enclosed shape as a stamp.
19 . A sequential computerized algorithmic method for detecting stamps in documents, the method comprising, using a computer processor:
if at least one regular shape in an image of a document is detected then outputting said at least one regular shape as a stamp; else:
removing at least one of text, lines, and noise in the image of the document; and
if at least one closed shape is remaining in the image of the document, then inscribing said at least one closed shape and outputting said at least one inscribed closed shape as a stamp; else
if at least one open shape is remaining in the image of the document, then enclosing said at least one open shape and outputting said at least one enclosed shape as a stamp; and
detecting at least one colored stamp in the image of the document, said detecting comprising:
converting the image of the document to an HSV color space;
selecting a first predefined H value interval;
for the selected H value interval:
calculating an S component which minimizes a quantity of white pixel blobs in the converted image of the document;
binarizing a resulting image having said S component;
inverting the binarized image;
applying an OR mask to the image of the document using the inverted image; and
detecting at least one regular shape in the masked image of the document and outputting said at least one regular shape as a colored stamp; and
iteratively repeating for a different H value interval if no colored stamp is output.