Dynamic minimum focus threshold determination inside a region of interest in an image
Embodiments disclosed are directed to a computing system that performs steps for automatically capturing images. The computing system receives an automatic image capture control signal from an application installed on a device and captures, by a camera of the device during a predetermined time interval, preview frames of an object and a background. For each of the preview frames, the computing system identifies an outline of the object in the preview frame, removes the background of the preview frame based on the outline to generate a modified preview frame, and determines a focus value of the modified preview frame. Subsequently, the computing system determines whether a predetermined amount of focus values are greater than a threshold focus value corresponding to the device and, if so, automatically captures, via the camera, an image of the object.
1 . A computer-implemented method for automatically capturing images, comprising:
capturing, by a camera of a device during a predetermined time interval, preview frames of an object and a background;
for each of the preview frames:
identifying an outline of the object in the preview frame, and
removing, based on the outline, the background in the preview frame to generate a modified preview frame by masking the background based on the outline before determining a focus value of the preview frame,
automatically capturing, via the camera, an image of the object once it is determined that the modified preview frame is in focus;
determining whether a calculated size and aspect ratio of the object in the modified preview frame is within a predetermined threshold size and corresponds to a predetermined aspect ratio, respectively, associated with a predetermined document type; and
in response to determining that the calculated size of the object is within the predetermined threshold size and the calculated aspect ratio of the object corresponds to the predetermined aspect ratio, automatically extracting a cropped image of the object from the modified preview frame.
2 . The computer-implemented method of claim 1 , wherein the removing the background comprises cropping, based on the outline, the object in the preview frame to generate the modified preview frame.
3 . The computer-implemented method of claim 1 , wherein:
the background consists of pixels; and
the masking the background comprises replacing, based on the outline, the pixels with black pixels to generate the modified preview frame.
4 . The computer-implemented method of claim 1 , the determining whether the modified preview frame is in focus comprises determining whether a predetermined amount of focus values corresponding to multiple preview frames are greater than a threshold focus value corresponding to the device.
5 . The computer-implemented method of claim 4 , wherein:
the threshold focus value is a first threshold focus value; and
the computer-implemented method further comprises:
determining whether the predetermined amount of focus values are greater than a second threshold focus value different from the first threshold focus value; and
in response to determining that the predetermined amount of focus values are greater than the second threshold focus value,
determining a minimum focus value of the modified preview frames;
determining a maximum focus value of the modified preview frames;
determining a mean focus value of the modified preview frames;
determining a standard deviation value of the modified preview frames;
determining a variance value of the modified preview frames; and
determining the first threshold focus value based on the minimum focus value, the maximum focus value, the mean focus value, the standard deviation value, and the variance value.
6 . The computer-implemented method of claim 1 , wherein the object is an identification document selected from a group consisting of a government-issued identification card, a health insurance card, an employee identification card, an identification card issued by a non-government institution, and a combination thereof.
7 . A device for automatically capturing images, comprising:
a memory storing an application installed on the device;
a camera;
a display; and
one or more processors in communication with the camera, the display, and the memory, and configured to:
capture, by the camera during a predetermined time interval, preview frames of an object and a background;
for each of the preview frames:
identify an outline of the object in the preview frame, and
remove, based on the outline, the background of the preview frame to generate a modified preview frame by masking the background based on the outline before determining a focus value of the preview frame,
automatically capture, via the camera, an image of the object once it is determined that the modified preview frame is in focus;
determine whether a calculated size and aspect ratio of the object in the modified preview frame is within a predetermined threshold size and corresponds to a predetermined aspect ratio, respectively, associated with a predetermined document type; and
in response to a determination that the calculated size of the object is within the predetermined threshold size and the calculated aspect ratio of the object corresponds to the predetermined aspect ratio, automatically extract a cropped image of the object from the modified preview frame.
8 . The device of claim 7 , wherein to remove the background, the one or more processors are configured to crop, based on the outline, the object in the preview frame to generate the modified preview frame.
9 . The device of claim 7 , wherein:
the background consists of pixels; and
to mask the background, the one or more processors are configured to replace, based on the outline, the pixels with black pixels to generate the modified preview frame.
10 . The device of claim 7 , wherein to determine whether the modified preview frame is in focus, the one or more processors are configured to determine whether a predetermined amount of focus values corresponding to multiple preview frames are greater than a threshold focus value corresponding to the device.
11 . The device of claim 10 , wherein:
the threshold focus value is a first threshold focus value; and
the determination is a first determination; and
the one or more processors are further configured to:
determine whether the predetermined amount of focus values are greater than a second threshold focus value different from the first threshold focus value; and
in response to a second determination that the predetermined amount of focus values are greater than the second threshold focus value,
determine a minimum focus value of the modified preview frames;
determine a maximum focus value of the modified preview frames;
determine a mean focus value of the modified preview frames;
determine a standard deviation value of the modified preview frames;
determine a variance value of the modified preview frames; and
determine the first threshold focus value based on the minimum focus value, the maximum focus value, the mean focus value, the standard deviation value, and the variance value.
12 . The device of claim 7 , wherein the object is an identification document selected from a group consisting of a government-issued identification card, a health insurance card, an employee identification card, an identification card issued by a non-government institution, and a combination thereof.
13 . A non-transitory computer readable medium storing instructions that, when executed by one or more processors of a device, cause the one or more processors to:
capture, by a camera of the device during a predetermined time interval, preview frames of an object and a background;
for each of the preview frames:
identify an outline of the object in the preview frame, and
remove, based on the outline, the background of the preview frame to generate a modified preview frame by masking the background based on the outline before determining a focus value of the preview frame,
automatically capture, via the camera, an image of the object once it is determined that the modified preview frame is in focus;
determine whether a calculated size and aspect ratio of the object in the modified preview frame is within a predetermined threshold size and corresponds to a predetermined aspect ratio, respectively, associated with a predetermined document type; and
in response to a determination that the calculated size of the object is within the predetermined threshold size and the calculated aspect ratio of the object corresponds to the predetermined aspect ratio, automatically extract a cropped image of the object from the modified preview frame.
14 . The non-transitory computer readable medium of claim 13 , wherein to remove the background, the instructions cause the one or more processors to crop, based on the outline, the object in the preview frame to generate the modified preview frame.
15 . The non-transitory computer readable medium of claim 13 , wherein:
the background consists of pixels; and
to mask the background, the instructions cause the one or more processors to replace, based on the outline, the pixels with black pixels to generate the modified preview frame.
16 . The non-transitory computer readable medium of claim 13 , wherein to determine whether the modified preview frame is in focus, the instructions cause the one or more processors to determine whether a predetermined amount of focus values corresponding to multiple preview frames are greater than a threshold focus value corresponding to the device.
17 . The non-transitory computer readable medium of claim 16 , wherein:
the threshold focus value is a first threshold focus value;
the determination is a first determination; and
the instructions cause the one or more processors to:
determine whether the predetermined amount of focus values are greater than a second threshold focus value different from the first threshold focus value; and
in response to a second determination that the predetermined amount of focus values are greater than the second threshold focus value,
determine a minimum focus value of the modified preview frames;
determine a maximum focus value of the modified preview frames;
determine a mean focus value of the modified preview frames;
determine a standard deviation value of the modified preview frames;
determine a variance value of the modified preview frames; and
determine the first threshold focus value based on the minimum focus value, the maximum focus value, the mean focus value, the standard deviation value, and the variance value.