def turnBinary(self, img, *args):
"""Pass image as graysacle, else will be converted, other args include 'a' - add to DB, 'inv'-inverting, 's'-show"""
#makes sure img is grayscale
if len(img.shape) == 3:
img = cv2.cvtColor(img, cv2.COLOR_RGB2GRAY)
_,img = cv2.threshold(img, 254,255,cv2.THRESH_BINARY)
print(img.shape)
print("Turned Binary")
try:
for arg in args:
# adds passed image to image db
if arg == 'a':
img_name = raw_input("Name for image\n")
self.pickled_dict[img_name] = img
self.savePickledDict()
# inverts binary img
if arg == 'inv':
img_name = raw_input("Name for image\n")
_, img = cv2.threshold(img,0,255,cv2.THRESH_BINARY_INV)
# shows img
if arg == "s":
cv2.imshow('img',img)
cv2.waitKey(0)
except:
pass
return img
评论列表
文章目录