Created
January 25, 2017 07:39
-
-
Save ShakoHo/ff4f202c6c6f2287f71cb89fc2aa2446 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import cv2 | |
import numpy | |
def convert_to_dct(image_fp, skip_status_bar_fraction=1.0): | |
dct_obj = None | |
try: | |
img_obj = cv2.imread(image_fp) | |
height, width, channel = img_obj.shape | |
height = int(height * skip_status_bar_fraction) - int(height * skip_status_bar_fraction) % 2 | |
img_obj = img_obj[:height][:][:] | |
img_gray = numpy.zeros((height, width)) | |
for channel in range(channel): | |
img_gray += img_obj[:, :, channel] | |
img_gray /= channel | |
img_dct = img_gray / 255.0 | |
dct_obj = cv2.dct(img_dct) | |
except Exception as e: | |
print e | |
return dct_obj | |
def compare_dct(dct_obj_1, dct_obj_2, threshold=0.0003): | |
match = False | |
try: | |
row1, cols1 = dct_obj_1.shape | |
row2, cols2 = dct_obj_2.shape | |
if (row1 == row2) and (cols1 == cols2): | |
mismatch_rate = numpy.sum(numpy.absolute(numpy.subtract(dct_obj_1, dct_obj_2))) / (row1 * cols1) | |
if mismatch_rate <= threshold: | |
match = True | |
except Exception as e: | |
print e | |
return match | |
a1 = convert_to_dct('temp/img00401.bmp') | |
a2 = convert_to_dct('temp/img02060.bmp') | |
print compare_dct(a1, a2) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment