SHARE
TWEET

Untitled

a guest Jan 15th, 2020 52 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import cv2 as cv
  2. import numpy as np
  3.  
  4.  
  5. img = cv.imread('duckie.jpg')
  6. cv.imshow('duckie.jpg', img)
  7. cv.waitKey(0)
  8.  
  9. while():
  10.     _, frame = img.read()  # Take each frame
  11.     hsv = cv.cvtColor(img, cv.COLOR_BGR2HSV)
  12.     lower_yellow = np.array([30, 255, 255])  # define range of yellow color in HSV
  13.     upper_yellow = np.array([[255, 255, 255]])
  14.     # Threshold the HSV image to get only yellow
  15.     mask = cv.inRange(hsv, lower_yellow, upper_yellow)
  16.     # Bitwise-AND mask and original image
  17.     res = cv.bitwise_and(frame, frame, mask=mask)
  18.     cv.imshow('frame', frame)
  19.     cv.imshow('mask', mask)
  20.     cv.imshow('res', res)
  21.     k = cv.waitKey(5) & 0xFF
  22.     if k == 27:
  23.         break
  24. cv.destroyAllWindows()
  25.  
  26. # for contours
  27. cv.drawContours(img, contours, 3, (0,255,0), 3)
  28. im = cv.imread('duckie.jpg')
  29. img = cv.cvtColor(im, cv.COLOR_BGR2HSV)
  30. ret, thresh = cv.threshold(img, 127, 255, 0)
  31. contours, hierarchy = cv.findContours(thresh, cv.RETR_TREE, cv.CHAIN_APPROX_SIMPLE)
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top