SHARE
TWEET

Untitled

a guest Mar 24th, 2019 79 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import cv2  # For OpenCV modules (For Image I/O and Contour Finding)
  2.  
  3. from utils import resize_image
  4.  
  5.  
  6. def crop_fields(image, write_to_file=True):
  7.     """
  8.     if write_to_file == True, all digits will be exported in separate files
  9.     :param filename:
  10.     :param write_to_file:
  11.     :return:
  12.     """
  13.     fields = {}
  14.     crop_margin = 15
  15.     natija_jomliaa_faedh = image[190 + crop_margin:255 - crop_margin, 259 + crop_margin:487 - crop_margin]
  16.     fields["natija_jomliaa_faedh"] = natija_jomliaa_faedh
  17.  
  18.     jomli_masarif_mizanya = image[190:260,493:933]
  19.     fields['jomli_masarif_mizanya'] = jomli_masarif_mizanya
  20.  
  21.     border = 27
  22.     for field in fields:
  23.         fields[field] = cv2.resize(fields[field], None, fields[field], 3, 3)
  24.         fields[field] = cv2.copyMakeBorder(fields[field], border, border, border, border, cv2.BORDER_CONSTANT, value=255)
  25.  
  26.         cv2.imshow(field, fields[field])
  27.         cv2.waitKey()
  28.  
  29.     return fields
  30.  
  31.  
  32. if __name__ == '__main__':
  33.     import sys
  34.  
  35.     if len(sys.argv) < 2:
  36.         print("please provide input image that contains a number")
  37.     else:
  38.         filename = sys.argv[1]
  39.         image = cv2.imread(filename)
  40.         image = resize_image(image)
  41.         crop_fields(image)
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top