Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import cv2
- import numpy as np
- def ex1():
- img2 = cv2.imread('/home/sense/Downloads/znak1.jpg')
- # img2 = cv2.imread('znak2.png')
- # Convert BGR to HSV
- hsv2 = cv2.cvtColor(img2, cv2.COLOR_BGR2HSV)
- # hsv2 = cv2.cvtColor(img2, cv2.COLOR_BGR2HSV)
- # define range of blue color in HSV
- lower_yellow = np.array([10, 100, 100])
- upper_yellow = np.array([60, 255, 255])
- mask = cv2.inRange(hsv2, lower_yellow, upper_yellow)
- kernel = np.ones((3, 3), np.uint8)
- erosion = cv2.erode(mask, kernel, iterations=1)
- dilation = cv2.dilate(erosion, kernel, iterations=1)
- image, contours, hierarchy = cv2.findContours(dilation, cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE)
- new = cv2.drawContours(img2, contours, -1, (0, 255, 0), 3)
- # Bitwise-AND mask and original image
- res = cv2.bitwise_and(img2, img2, mask=dilation)
- cv2.imshow('frame', new)
- # cv2.imshow('mask', mask)
- cv2.imshow('res', res)
- pass
- ex1()
- cv2.waitKey(0)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement