Added camera reinitialization.
This commit is contained in:
parent
8dbc573830
commit
2fc0f52385
2 changed files with 29 additions and 8 deletions
|
|
@ -61,7 +61,7 @@ import time
|
|||
import cv2
|
||||
import socket
|
||||
import struct
|
||||
from input_reader import InputReader, VideoReader
|
||||
from input_reader import InputReader, VideoReader, try_int
|
||||
from tracker import Tracker
|
||||
|
||||
target_ip = args.ip
|
||||
|
|
@ -71,12 +71,13 @@ if args.faces >= 40:
|
|||
print("Transmission of tracking data over network is not supported with 40 or more faces.")
|
||||
|
||||
fps = 0
|
||||
use_dshowcapture_flag = False
|
||||
if os.name == 'nt':
|
||||
fps = args.fps
|
||||
use_dshowcapture_flag = True if args.use_dshowcapture == 1 else False
|
||||
input_reader = InputReader(args.capture, args.raw_rgb, args.width, args.height, fps, use_dshowcapture=use_dshowcapture_flag)
|
||||
else:
|
||||
input_reader = InputReader(args.capture, args.raw_rgb, args.width, args.height, fps, use_dshowcapture=False)
|
||||
input_reader = InputReader(args.capture, args.raw_rgb, args.width, args.height, fps, use_dshowcapture=use_dshowcapture_flag)
|
||||
if type(input_reader.reader) == VideoReader:
|
||||
fps = 0
|
||||
|
||||
|
|
@ -105,7 +106,10 @@ if args.log_data != "":
|
|||
log.write("\r\n")
|
||||
log.flush()
|
||||
|
||||
is_camera = args.capture == str(try_int(args.capture))
|
||||
|
||||
try:
|
||||
attempt = 0
|
||||
frame_time = time.perf_counter()
|
||||
target_duration = 0
|
||||
if fps > 0:
|
||||
|
|
@ -114,12 +118,12 @@ try:
|
|||
need_reinit = 0
|
||||
while repeat or input_reader.is_open():
|
||||
if not input_reader.is_open() or need_reinit == 1:
|
||||
input_reader = InputReader(args.capture, args.raw_rgb, args.width, args.height, fps)
|
||||
input_reader = InputReader(args.capture, args.raw_rgb, args.width, args.height, fps, use_dshowcapture=use_dshowcapture_flag)
|
||||
need_reinit = 2
|
||||
time.sleep(0.001)
|
||||
time.sleep(0.02)
|
||||
continue
|
||||
if not input_reader.is_ready():
|
||||
time.sleep(0.001)
|
||||
time.sleep(0.02)
|
||||
continue
|
||||
|
||||
ret, frame = input_reader.read()
|
||||
|
|
@ -128,8 +132,19 @@ try:
|
|||
if need_reinit == 0:
|
||||
need_reinit = 1
|
||||
continue
|
||||
break
|
||||
elif is_camera:
|
||||
attempt += 1
|
||||
if attempt > 30:
|
||||
break
|
||||
else:
|
||||
time.sleep(0.02)
|
||||
if attempt == 3:
|
||||
need_reinit = 1
|
||||
continue
|
||||
else:
|
||||
break;
|
||||
|
||||
attempt = 0
|
||||
need_reinit = 0
|
||||
frame_count += 1
|
||||
now = time.time()
|
||||
|
|
|
|||
10
tracker.py
10
tracker.py
|
|
@ -136,7 +136,10 @@ def worker_thread(session, frame, input, crop_info, queue, input_name, idx, trac
|
|||
lms = np.array(output[1]) * np.array([crop_info[3], crop_info[2], 1.]) + np.array([crop_info[1], crop_info[0], 0.])
|
||||
conf = output[0]
|
||||
if conf > tracker.threshold:
|
||||
eye_state = tracker.get_eye_state(frame, lms, single=True)
|
||||
try:
|
||||
eye_state = tracker.get_eye_state(frame, lms, single=True)
|
||||
except:
|
||||
eye_state = [(1.0, 0.0, 0.0, 0.0), (1.0, 0.0, 0.0, 0.0)]
|
||||
queue.put((session, conf, (lms, eye_state), crop_info, idx))
|
||||
else:
|
||||
queue.put((session,))
|
||||
|
|
@ -992,7 +995,10 @@ class Tracker():
|
|||
lms = np.array(output[1]) * np.array([crop_info[0][3], crop_info[0][2], 1.]) + np.array([crop_info[0][1], crop_info[0][0], 0.])
|
||||
conf = output[0]
|
||||
if conf > self.threshold:
|
||||
eye_state = self.get_eye_state(frame, lms)
|
||||
try:
|
||||
eye_state = self.get_eye_state(frame, lms)
|
||||
except:
|
||||
eye_state = [(1.0, 0.0, 0.0, 0.0), (1.0, 0.0, 0.0, 0.0)]
|
||||
outputs[crop_info[0]] = (conf, (lms, eye_state), 0)
|
||||
else:
|
||||
started = 0
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue