Advertisement
Guest User

aye

a guest
Sep 23rd, 2019
271
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.74 KB | None | 0 0
  1. import cv2 as cv
  2. import numpy as np
  3.  
  4. img = cv.imread('stop.png') # ,cv.IMREAD_GRAYSCALE)
  5. frame = cv.resize(img, (600, 600), interpolation=cv.INTER_AREA)
  6. hsv = cv.cvtColor(frame, cv.COLOR_BGR2HSV)
  7. hsv = cv.blur(hsv, (5, 5))
  8. mask = cv.inRange(hsv, (0, 7, 0), (255, 255, 190))
  9.  
  10. contours_info = cv.findContours(mask, cv.RETR_TREE, cv.CHAIN_APPROX_NONE)
  11. contours = contours_info[1]
  12.  
  13. if contours:
  14. contours = sorted(contours, key=cv.contourArea, reverse=True)
  15. cv.drawContours(frame, contours, 0, (255, 255, 0), 3)
  16. (x, y, w, h) = cv.boundingRect(contours[0])
  17. cv.rectangle(frame, (x, y), (x + w, y + h), (0, 255, 255), 2)
  18.  
  19. cv.imshow("Contours", frame)
  20.  
  21. while (True):
  22. if cv.waitKey() != 0:
  23. break
  24. cv.destroyAllWindows()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement