Advertisement
Guest User

Untitled

a guest
Jan 26th, 2020
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.09 KB | None | 0 0
  1. import numpy as np
  2. import cv2 as cv
  3. import imutils
  4.  
  5. colorLower_1 = (10,1,220)
  6. colorUpper_1 = (40,220,255)
  7. colorLower_2 = (20,1,200)
  8. colorUpper_2 = (40,255,255)
  9.  
  10. cap = cv.VideoCapture(0)
  11.  
  12. while True:
  13.     ret, frame = cap.read()
  14.     frame = cv.resize(frame, (600,480))
  15.  
  16.     img = cv.medianBlur(frame, 3)
  17.  
  18.     hsv = cv.cvtColor(img, cv.COLOR_BGR2HSV)
  19.     first = cv.inRange(hsv, colorLower_1, colorUpper_1)
  20.     second = cv.inRange(hsv, colorLower_2, colorUpper_2)
  21.     img = cv.addWeighted( src1=first, alpha=1, src2=second, beta=1, gamma=0, dst=img)
  22.     img = cv.erode(img, None, iterations=2)
  23.     img = cv.dilate(img, None, iterations=2)
  24.     img = cv.GaussianBlur(img, (9,9), 2)   
  25.     circles = cv.HoughCircles(img, cv.HOUGH_GRADIENT, 1,200,
  26.                                     param1=100,param2=30,minRadius=10) 
  27.  
  28.     if circles is not None:
  29.         circles = np.round(circles[0, :]).astype("int")
  30.         for (x, y, r) in circles:
  31.             cv.circle(frame,(int(x), int(y)), int(r),
  32.                             (0, 255, 255), 2)
  33.  
  34.     # cv.imshow('img', img)
  35.     # cv.imshow('first', first)
  36.     # cv.imshow('second', second)
  37.     cv.imshow('frame', frame)
  38.     cv.waitKey(1)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement