remove redundent code
This commit is contained in:
parent
6a54b5cae2
commit
0b48c40b82
1 changed files with 10 additions and 93 deletions
|
@ -9,9 +9,8 @@ import numpy as np
|
|||
|
||||
import cv2
|
||||
import mark_detector
|
||||
# import optical_flow_tracker
|
||||
from stabilizer import Stabilizer
|
||||
import pose_estimator
|
||||
from stabilizer import Stabilizer
|
||||
|
||||
INPUT_SIZE = 128
|
||||
|
||||
|
@ -33,18 +32,6 @@ def main():
|
|||
cov_process=0.01,
|
||||
cov_measure=0.1) for _ in range(6)]
|
||||
|
||||
# # Remember the user state for updating kalman filter parameters.
|
||||
# # 1: moving; 0: still.
|
||||
# target_latest_state = 0
|
||||
# target_current_state = 1
|
||||
|
||||
# # Introduce an optical flow tracker to help to decide how kalman filter
|
||||
# # should be configured. Alos keep one frame for optical flow tracker.
|
||||
# tracker = optical_flow_tracker.Tracker()
|
||||
# frame_prev = cam.read()
|
||||
# frame_count = 0
|
||||
# tracker_threshold = 2
|
||||
|
||||
while True:
|
||||
# Read frame, crop it, flip it, suits your needs.
|
||||
frame_got, frame = cam.read()
|
||||
|
@ -58,31 +45,6 @@ def main():
|
|||
if video_src == 0:
|
||||
frame = cv2.flip(frame, 2)
|
||||
|
||||
# Draw a dark background for user state text on frame.
|
||||
# cv2.rectangle(frame, (4, 28), (70, 4), (70, 70, 70), -1)
|
||||
# frame_count += 1
|
||||
|
||||
# # Optical flow tracker should work before kalman filter.
|
||||
# frame_opt_flw = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
|
||||
|
||||
# # If optical flow is already working, get user state from it.
|
||||
# if len(tracker.tracks) > 0:
|
||||
# if tracker.get_average_track_length() > tracker_threshold:
|
||||
# # User is moving.
|
||||
# target_current_state = 1
|
||||
# cv2.putText(frame, "Moving", (10, 20),
|
||||
# cv2.FONT_HERSHEY_SIMPLEX, 0.5, (78, 207, 219))
|
||||
# else:
|
||||
# target_current_state = 0
|
||||
# # User is still.
|
||||
# cv2.putText(frame, "Still", (10, 20),
|
||||
# cv2.FONT_HERSHEY_SIMPLEX, 0.5, (255, 180, 118))
|
||||
|
||||
# tracker.update_tracks(frame_prev, frame_opt_flw)
|
||||
|
||||
# # Store current frame for next frame's optical flow.
|
||||
# frame_prev = frame_opt_flw
|
||||
|
||||
# Pose estimation by 3 steps:
|
||||
# 1. detect face;
|
||||
# 2. detect landmarks;
|
||||
|
@ -90,20 +52,6 @@ def main():
|
|||
frame_cnn = frame.copy()
|
||||
facebox = mark_detector.extract_cnn_facebox(frame_cnn)
|
||||
if facebox is not None:
|
||||
# # Set mask equal to face area for optical flow tracker.
|
||||
# target_box = [facebox[1], facebox[3],
|
||||
# facebox[0], facebox[2]]
|
||||
|
||||
# # Update state check threshold
|
||||
# tracker_threshold = abs(facebox[2] - facebox[0]) * 0.005
|
||||
|
||||
# # Track might vanish in the current frame, get new one if needed.
|
||||
# if frame_count % 30 == 0:
|
||||
# tracker.get_new_tracks(frame_opt_flw, target_box)
|
||||
|
||||
# Uncomment following line to show optical flow tracks.
|
||||
# tracker.draw_track(frame_cnn)
|
||||
|
||||
# Detect landmarks from image of 128x128.
|
||||
face_img = frame_cnn[facebox[1]: facebox[3],
|
||||
facebox[0]: facebox[2]]
|
||||
|
@ -129,44 +77,11 @@ def main():
|
|||
stabile_marks[:, 0] += facebox[0]
|
||||
stabile_marks[:, 1] += facebox[1]
|
||||
|
||||
# Uncomment the following line to show raw marks.
|
||||
# mark_detector.draw_marks(frame_cnn, landmarks)
|
||||
|
||||
# All kind of detections face a common issue: jitter. Usually this is
|
||||
# solved by kinds of estimators, like partical filter or Kalman filter, etc.
|
||||
# Here an Extended Kalman Filter is introduced as the target is not always
|
||||
# in the same state. An optical flow tracker also proved to be helpfull to
|
||||
# tell which state the target is currently in.
|
||||
# Different state require different kalman filter parameters. The filters
|
||||
# should be re-configured only if the state has changed, for better performance.
|
||||
# stabile_marks = []
|
||||
# if target_current_state != target_latest_state:
|
||||
# if target_current_state == 1:
|
||||
# # Target is moving.
|
||||
# cov_process = 0.1
|
||||
# cov_measure = 0.01
|
||||
# else:
|
||||
# # Traget is still.
|
||||
# cov_process = 0.0001
|
||||
# cov_measure = 0.1
|
||||
|
||||
# # Update state.
|
||||
# target_latest_state = target_current_state
|
||||
|
||||
# # Re-configure the filters.
|
||||
# for stabilizer in stabilizers:
|
||||
# stabilizer.set_q_r(cov_process=cov_process,
|
||||
# cov_measure=cov_measure)
|
||||
|
||||
# # Filters re-configured, stabilize the marks.
|
||||
# for point, stabilizer in zip(landmarks, stabilizers):
|
||||
# stabilizer.update(point)
|
||||
# stabile_marks.append([stabilizer.filter.statePost[0],
|
||||
# stabilizer.filter.statePost[1]])
|
||||
|
||||
# # Uncomment following line to show stabile marks.
|
||||
# Uncomment following line to show raw marks.
|
||||
# mark_detector.draw_marks(
|
||||
# frame_cnn, marks, color=(0, 255, 0))
|
||||
|
||||
# Uncomment following line to show stabile marks.
|
||||
# mark_detector.draw_marks(
|
||||
# frame_cnn, stabile_marks, color=(255, 0, 0))
|
||||
|
||||
|
@ -183,11 +98,13 @@ def main():
|
|||
stabile_pose.append(ps_stb.state[0])
|
||||
stabile_pose = np.reshape(stabile_pose, (-1, 3))
|
||||
|
||||
# Draw pose annotaion on frame.
|
||||
# frame_cnn = pose_estimator.draw_annotation_box(
|
||||
# frame_cnn, pose[0], pose[1])
|
||||
# Uncomment following line to draw pose annotaion on frame.
|
||||
frame_cnn = pose_estimator.draw_annotation_box(
|
||||
frame_cnn, stabile_pose[0], stabile_pose[1], color=(0, 255, 0))
|
||||
frame_cnn, pose[0], pose[1])
|
||||
|
||||
# Uncomment following line to draw stabile pose annotaion on frame.
|
||||
# frame_cnn = pose_estimator.draw_annotation_box(
|
||||
# frame_cnn, stabile_pose[0], stabile_pose[1], color=(0, 255, 0))
|
||||
|
||||
# Show preview.
|
||||
cv2.imshow("Preview", frame_cnn)
|
||||
|
|
Loading…
Add table
Reference in a new issue