Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import cv2 # For OpenCV modules (For Image I/O and Contour Finding)
- from utils import resize_image
- def crop_fields(image, write_to_file=True):
- """
- if write_to_file == True, all digits will be exported in separate files
- :param filename:
- :param write_to_file:
- :return:
- """
- fields = {}
- crop_margin = 15
- natija_jomliaa_faedh = image[190 + crop_margin:255 - crop_margin, 259 + crop_margin:487 - crop_margin]
- fields["natija_jomliaa_faedh"] = natija_jomliaa_faedh
- jomli_masarif_mizanya = image[190:260,493:933]
- fields['jomli_masarif_mizanya'] = jomli_masarif_mizanya
- border = 27
- for field in fields:
- fields[field] = cv2.resize(fields[field], None, fields[field], 3, 3)
- fields[field] = cv2.copyMakeBorder(fields[field], border, border, border, border, cv2.BORDER_CONSTANT, value=255)
- cv2.imshow(field, fields[field])
- cv2.waitKey()
- return fields
- if __name__ == '__main__':
- import sys
- if len(sys.argv) < 2:
- print("please provide input image that contains a number")
- else:
- filename = sys.argv[1]
- image = cv2.imread(filename)
- image = resize_image(image)
- crop_fields(image)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement