Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import cv2
- def find_curved_contour(img):
- # Convert image to hsv colour space
- img_hsv = cv2.cvtColor(img, cv2.COLOR_BGR2HSV)
- # cv2.imshow("hsv", img_hsv)
- # cv2.waitKey(1000)
- # Apply threshold to filter out the red background
- thresh_min = (100, 0.000, 0.000)
- thresh_max = (109, 255, 255)
- thresh_img = cv2.inRange(img_hsv, thresh_min, thresh_max)
- cv2.imshow("thresh", thresh_img)
- cv2.waitKey(1000)
- # Find contours
- _, contours, hierarchy = cv2.findContours(thresh_img, cv2.RETR_TREE, cv2.CHAIN_APPROX_NONE)
- # Display the contour with the biggest area
- if contours is not None and len(contours) > 0:
- contour = max(contours, key=cv2.contourArea)
- cv2.drawContours(img, contour, -1, (0,255,0), 2)
- cv2.imshow("contour", img)
- cv2.waitKey(10000)
- if __name__ == '__main__':
- img_path = "/home/jarod/Pictures/curved_image.png"
- img = cv2.imread(img_path)
- cv2.imshow("raw", img)
- cv2.waitKey(1000)
- # Find contours
- find_curved_contour(img)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement