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('duckie.jpg')
- cv.imshow('duckie.jpg', img)
- cv.waitKey(0)
- while():
- _, frame = img.read() # Take each frame
- hsv = cv.cvtColor(img, cv.COLOR_BGR2HSV)
- lower_yellow = np.array([30, 255, 255]) # define range of yellow color in HSV
- upper_yellow = np.array([[255, 255, 255]])
- # Threshold the HSV image to get only yellow
- mask = cv.inRange(hsv, lower_yellow, upper_yellow)
- # Bitwise-AND mask and original image
- res = cv.bitwise_and(frame, frame, mask=mask)
- cv.imshow('frame', frame)
- cv.imshow('mask', mask)
- cv.imshow('res', res)
- k = cv.waitKey(5) & 0xFF
- if k == 27:
- break
- cv.destroyAllWindows()
- # for contours
- cv.drawContours(img, contours, 3, (0,255,0), 3)
- im = cv.imread('duckie.jpg')
- img = cv.cvtColor(im, cv.COLOR_BGR2HSV)
- ret, thresh = cv.threshold(img, 127, 255, 0)
- contours, hierarchy = cv.findContours(thresh, cv.RETR_TREE, cv.CHAIN_APPROX_SIMPLE)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement