  
  
  def hash_image_file(filename):
      """ Return an image file's sha1 hash """
      img = cv2.imread(filename)  # pylint: disable=no-member
      img_hash = sha1(img).hexdigest()
      logger.trace("filename: '%s', hash: %s", filename, img_hash)
      return img_hash
  
  
 
</s> remove         try:
            image = cv2.imread(filename)  # pylint: disable=no-member
        except TypeError:
            raise Exception("Error while reading image", filename)

 </s> add         image = cv2_read_img(filename, raise_error=True) </s> remove             logger.trace("Loading image: '%s'", filename)
            try:
                image = cv2.imread(filename)  # pylint: disable=no-member
            except Exception as err:  # pylint: disable=broad-except
                logger.error("Failed to load image '%s'. Original Error: %s", filename, err)
 </s> add             image = cv2_read_img(filename, raise_error=False)
            if image is None: </s> remove         image = cv2.imread(self.images["a"][0])  # pylint: disable=no-member
 </s> add         image = cv2_read_img(self.images["a"][0], raise_error=True) </s> remove             retval = cv2.imread(filename)  # pylint: disable=no-member
 </s> add             retval = cv2_read_img(filename, raise_error=True) </s> remove             image = cv2.imread(src)  # pylint: disable=no-member
 </s> add             image = cv2_read_img(src, raise_error=True)
    img = cv2_read_img(filename, raise_error=True)
  
  
  def hash_image_file(filename):
      """ Return an image file's sha1 hash """
    img = cv2_read_img(filename, raise_error=True)
      img_hash = sha1(img).hexdigest()
      logger.trace("filename: '%s', hash: %s", filename, img_hash)
      return img_hash
  
  
keep keep keep keep replace keep keep keep keep keep
 Centralize cv2 image reading and handle bad filenames 
lib/utils.py