Skip to content

Instantly share code, notes, and snippets.

@tanviredu
Created August 2, 2020 13:35
Show Gist options
  • Save tanviredu/141a2e72d2bd4f96c5cc67fce45a7f21 to your computer and use it in GitHub Desktop.
Save tanviredu/141a2e72d2bd4f96c5cc67fce45a7f21 to your computer and use it in GitHub Desktop.
def Otsus_Binarization(folder,target):
images = []
i=1
for file in os.listdir(folder):
try:
img = cv2.imread(os.path.join(folder,file),cv2.IMREAD_GRAYSCALE)
ret2,th2 = cv.threshold(img,0,255,cv.THRESH_BINARY+cv.THRESH_OTSU)
except:
pass
if img is not None:
print("[+] {} is loaded".format(i))
images.append([th2,target])
i+=1
else:
print("[-] Problem importing" )
return images
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment