Advertisement
Guest User

Untitled

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