Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import cv2 as cv
- import numpy as np
- img = cv.imread('stop.png') # ,cv.IMREAD_GRAYSCALE)
- frame = cv.resize(img, (600, 600), interpolation=cv.INTER_AREA)
- hsv = cv.cvtColor(frame, cv.COLOR_BGR2HSV)
- hsv = cv.blur(hsv, (5, 5))
- mask = cv.inRange(hsv, (0, 7, 0), (255, 255, 190))
- contours_info = cv.findContours(mask, cv.RETR_TREE, cv.CHAIN_APPROX_NONE)
- contours = contours_info[1]
- if contours:
- contours = sorted(contours, key=cv.contourArea, reverse=True)
- cv.drawContours(frame, contours, 0, (255, 255, 0), 3)
- (x, y, w, h) = cv.boundingRect(contours[0])
- cv.rectangle(frame, (x, y), (x + w, y + h), (0, 255, 255), 2)
- cv.imshow("Contours", frame)
- while (True):
- if cv.waitKey() != 0:
- break
- cv.destroyAllWindows()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement