Advertisement
Guest User

example

a guest
Dec 12th, 2019
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.54 KB | None | 0 0
  1. def process_motion(frame):
  2. start_time_tst = time.time()
  3. gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
  4. fgmask = bgs.apply(cv2.GaussianBlur(frame,(21,21),0))
  5. mn = np.mean(fgmask)
  6. if mn <20.0 and mn > .5:
  7. #keypoints = detector.detect(fgmask)
  8. # Draw detected blobs as red circles.
  9. ret, thresh = cv2.threshold(fgmask, 200, 255, 0)
  10. thresh = cv2.GaussianBlur(thresh,(21,21),0)
  11. contours, hierarchy = cv2.findContours(thresh, cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE)
  12.  
  13. for cnt in contours:
  14. (x,y),radius = cv2.minEnclosingCircle(cnt)
  15.  
  16. center = (int(x),int(y))
  17. radius = int(radius)
  18. area_circle = (radius ** 2) * math.pi
  19. area = cv2.contourArea(cnt)
  20. if radius < 500 and radius > 30 and area > 0.3 * area_circle:
  21. tmp_bee = Bee(_is_input=True, start_point = (x,y), rect = (x - radius, y - radius, 2*radius, 2*radius), img = frame)
  22. #s_log("detect bee")
  23. is_need_add = True
  24. tmp_point = (x,y)
  25. for b in g_bees:
  26. if b.is_input == tmp_bee.is_input and ( equals_centroid(b.start_point, tmp_point) or equals_centroid(b.end_point, tmp_point)) :
  27. b.change((x, y), (x - radius, y - radius, 2*radius, 2*radius), img = frame )
  28. is_need_add = False
  29. break
  30. if is_need_add:
  31. g_bees.append(tmp_bee)
  32. pass
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement