Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def process_motion(frame):
- start_time_tst = time.time()
- gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
- fgmask = bgs.apply(cv2.GaussianBlur(frame,(21,21),0))
- mn = np.mean(fgmask)
- if mn <20.0 and mn > .5:
- #keypoints = detector.detect(fgmask)
- # Draw detected blobs as red circles.
- ret, thresh = cv2.threshold(fgmask, 200, 255, 0)
- thresh = cv2.GaussianBlur(thresh,(21,21),0)
- contours, hierarchy = cv2.findContours(thresh, cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE)
- for cnt in contours:
- (x,y),radius = cv2.minEnclosingCircle(cnt)
- center = (int(x),int(y))
- radius = int(radius)
- area_circle = (radius ** 2) * math.pi
- area = cv2.contourArea(cnt)
- if radius < 500 and radius > 30 and area > 0.3 * area_circle:
- tmp_bee = Bee(_is_input=True, start_point = (x,y), rect = (x - radius, y - radius, 2*radius, 2*radius), img = frame)
- #s_log("detect bee")
- is_need_add = True
- tmp_point = (x,y)
- for b in g_bees:
- if b.is_input == tmp_bee.is_input and ( equals_centroid(b.start_point, tmp_point) or equals_centroid(b.end_point, tmp_point)) :
- b.change((x, y), (x - radius, y - radius, 2*radius, 2*radius), img = frame )
- is_need_add = False
- break
- if is_need_add:
- g_bees.append(tmp_bee)
- pass
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement