Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import numpy as np
- import cv2
- img = cv2.imread('comics.jpg')
- imgrey = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)
- ret,thresh1 = cv2.threshold(imgrey,127,255,cv2.THRESH_BINARY_INV)
- contours,heirarchy = cv2.findContours(thresh1,cv2.RETR_EXTERNAL,cv2.CHAIN_APPROX_NONE)
- for contour in contours:
- hull = cv2.convexHull(contour)
- cv2.drawContours(imgrey,[hull],-1,0,-1)
- ret,thresh1 = cv2.threshold(imgrey,127,255,cv2.THRESH_BINARY_INV)
- contours,heirarchy = cv2.findContours(thresh1,cv2.RETR_EXTERNAL,cv2.CHAIN_APPROX_NONE)
- for contour in contours:
- cv2.drawContours(img,[contour],-1,(0,255,0),3)
- cv2.imwrite('threshold_image.png',img)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement