mirror of
https://github.com/EyeTrackVR/EyeTrackVR.git
synced 2025-11-04 14:39:42 +08:00
fix: camera handel, crash fix
This commit is contained in:
parent
a8cf676730
commit
a7f0fd10a9
@ -422,7 +422,6 @@ def get_empty_array(
|
|||||||
# memo: Unelegant code
|
# memo: Unelegant code
|
||||||
# memo: transposed version
|
# memo: transposed version
|
||||||
|
|
||||||
|
|
||||||
wh_in_arr = (
|
wh_in_arr = (
|
||||||
np.hstack(
|
np.hstack(
|
||||||
[
|
[
|
||||||
@ -715,6 +714,7 @@ def fine_detection(img_gray, pupil_rect_coarse):
|
|||||||
except:
|
except:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
def detect_edges(img_pupil_blur):
|
def detect_edges(img_pupil_blur):
|
||||||
tau1 = 1 - 20.0 / img_pupil_blur.shape[1]
|
tau1 = 1 - 20.0 / img_pupil_blur.shape[1]
|
||||||
edges = cv2.Canny(img_pupil_blur, 64, 128)
|
edges = cv2.Canny(img_pupil_blur, 64, 128)
|
||||||
@ -981,8 +981,15 @@ def External_Run_AHSF(frame_gray):
|
|||||||
right_padding = new_image_size - frame_gray.shape[1] - left_padding
|
right_padding = new_image_size - frame_gray.shape[1] - left_padding
|
||||||
|
|
||||||
# Add padding to the image
|
# Add padding to the image
|
||||||
frame_gray = cv2.copyMakeBorder(frame_gray, top_padding, bottom_padding, left_padding, right_padding,
|
frame_gray = cv2.copyMakeBorder(
|
||||||
cv2.BORDER_CONSTANT, value=average_color)
|
frame_gray,
|
||||||
|
top_padding,
|
||||||
|
bottom_padding,
|
||||||
|
left_padding,
|
||||||
|
right_padding,
|
||||||
|
cv2.BORDER_CONSTANT,
|
||||||
|
value=average_color,
|
||||||
|
)
|
||||||
frame_clear_resize = frame_gray.copy()
|
frame_clear_resize = frame_gray.copy()
|
||||||
|
|
||||||
# while True:
|
# while True:
|
||||||
@ -998,8 +1005,6 @@ def External_Run_AHSF(frame_gray):
|
|||||||
|
|
||||||
# frame_gray = cv2.resize(frame_gray, (100, 100))
|
# frame_gray = cv2.resize(frame_gray, (100, 100))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
wmax = min(
|
wmax = min(
|
||||||
(frame_gray.shape[1] * 0.3), 240
|
(frame_gray.shape[1] * 0.3), 240
|
||||||
) # likes to crash, might need more tuning still
|
) # likes to crash, might need more tuning still
|
||||||
@ -1019,6 +1024,7 @@ def External_Run_AHSF(frame_gray):
|
|||||||
"init_rect_flag": False,
|
"init_rect_flag": False,
|
||||||
"init_rect": (0, 0, frame_gray.shape[1], frame_gray.shape[0]),
|
"init_rect": (0, 0, frame_gray.shape[1], frame_gray.shape[0]),
|
||||||
}
|
}
|
||||||
|
try:
|
||||||
(
|
(
|
||||||
pupil_rect_coarse,
|
pupil_rect_coarse,
|
||||||
outer_rect_coarse,
|
outer_rect_coarse,
|
||||||
@ -1027,11 +1033,12 @@ def External_Run_AHSF(frame_gray):
|
|||||||
mu_outer,
|
mu_outer,
|
||||||
) = coarse_detection(frame_gray, params)
|
) = coarse_detection(frame_gray, params)
|
||||||
ellipse_rect, center_fitting = fine_detection(frame_gray, pupil_rect_coarse)
|
ellipse_rect, center_fitting = fine_detection(frame_gray, pupil_rect_coarse)
|
||||||
|
except TypeError:
|
||||||
|
print("[WARN] AHSF NoneType Error")
|
||||||
# print(ellipse_rect)
|
# print(ellipse_rect)
|
||||||
# Pupil_rect, Outer_rect, max_response, mu_inner, mu_outer = coarse_detection(frame_gray, params)
|
# Pupil_rect, Outer_rect, max_response, mu_inner, mu_outer = coarse_detection(frame_gray, params)
|
||||||
image_brg = frame_gray # cv2.cvtColor(frame_gray, cv2.COLOR_GRAY2BGR)
|
image_brg = frame_gray # cv2.cvtColor(frame_gray, cv2.COLOR_GRAY2BGR)
|
||||||
|
|
||||||
|
|
||||||
# show
|
# show
|
||||||
# cv2.rectangle(
|
# cv2.rectangle(
|
||||||
# image_brg,
|
# image_brg,
|
||||||
@ -1061,23 +1068,24 @@ def External_Run_AHSF(frame_gray):
|
|||||||
major_diameter = math.sqrt(width**2 + height**2)
|
major_diameter = math.sqrt(width**2 + height**2)
|
||||||
minor_diameter = min(width, height)
|
minor_diameter = min(width, height)
|
||||||
average_diameter = (major_diameter + minor_diameter) / 2
|
average_diameter = (major_diameter + minor_diameter) / 2
|
||||||
# print(x_center, y_center)
|
print(x_center, y_center)
|
||||||
return frame_gray, frame_clear_resize, x_center, y_center, average_diameter
|
return frame_gray, frame_clear_resize, x_center, y_center, average_diameter
|
||||||
|
|
||||||
# return frame_gray, 0.0, 0.0, 0.0
|
|
||||||
# if imshow_enable:
|
|
||||||
# cv2.imshow("pppp", image_brg)
|
|
||||||
# if cv2.waitKey(1) & 0xFF == ord("q"):
|
|
||||||
# pass
|
|
||||||
# if save_video:
|
|
||||||
# video_wr.write(image_brg)
|
|
||||||
|
|
||||||
# if save_video:
|
# return frame_gray, 0.0, 0.0, 0.0
|
||||||
# video_wr.release()
|
# if imshow_enable:
|
||||||
# logger.info("video output: {}".format(output_video_path))
|
# cv2.imshow("pppp", image_brg)
|
||||||
# cap.release()
|
# if cv2.waitKey(1) & 0xFF == ord("q"):
|
||||||
# if imshow_enable:
|
# pass
|
||||||
# cv2.destroyAllWindows()
|
# if save_video:
|
||||||
|
# video_wr.write(image_brg)
|
||||||
|
|
||||||
|
# if save_video:
|
||||||
|
# video_wr.release()
|
||||||
|
# logger.info("video output: {}".format(output_video_path))
|
||||||
|
# cap.release()
|
||||||
|
# if imshow_enable:
|
||||||
|
# cv2.destroyAllWindows()
|
||||||
|
|
||||||
|
|
||||||
# main_end_time = timeit.default_timer()
|
# main_end_time = timeit.default_timer()
|
||||||
|
|||||||
@ -83,7 +83,7 @@ class Camera:
|
|||||||
should_push = True
|
should_push = True
|
||||||
# If things aren't open, retry until they are. Don't let read requests come in any earlier
|
# If things aren't open, retry until they are. Don't let read requests come in any earlier
|
||||||
# than this, otherwise we can deadlock ourselves.
|
# than this, otherwise we can deadlock ourselves.
|
||||||
if self.config.capture_source != None and self.config.capture_source != "" and len(self.config.capture_source) > 3:
|
if self.config.capture_source != None and self.config.capture_source != "":
|
||||||
self.current_capture_source = self.config.capture_source
|
self.current_capture_source = self.config.capture_source
|
||||||
if "COM" in str(self.current_capture_source):
|
if "COM" in str(self.current_capture_source):
|
||||||
if (
|
if (
|
||||||
|
|||||||
@ -394,10 +394,14 @@ class EyeProcessor:
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
self.hasrac_en = True
|
self.hasrac_en = True
|
||||||
self.current_image_gray, resize_img, self.rawx, self.rawy, self.radius = External_Run_AHSF(
|
(
|
||||||
self.current_image_gray
|
self.current_image_gray,
|
||||||
)
|
resize_img,
|
||||||
self.current_image_gray_clean = resize_img
|
self.rawx,
|
||||||
|
self.rawy,
|
||||||
|
self.radius,
|
||||||
|
) = External_Run_AHSF(self.current_image_gray)
|
||||||
|
self.current_image_gray_clean = resize_img.copy()
|
||||||
|
|
||||||
self.thresh = resize_img
|
self.thresh = resize_img
|
||||||
(
|
(
|
||||||
@ -436,7 +440,6 @@ class EyeProcessor:
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
self.hasrac_en = True
|
self.hasrac_en = True
|
||||||
# todo: add process to initialise er_hsrac when resolution changes
|
|
||||||
self.rawx, self.rawy, self.thresh, self.radius = self.er_hsf.run(
|
self.rawx, self.rawy, self.thresh, self.radius = self.er_hsf.run(
|
||||||
self.current_image_gray
|
self.current_image_gray
|
||||||
)
|
)
|
||||||
@ -528,9 +531,13 @@ class EyeProcessor:
|
|||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
pass
|
pass
|
||||||
self.current_image_gray, resize_img, self.rawx, self.rawy, self.radius = External_Run_AHSF(
|
(
|
||||||
self.current_image_gray
|
self.current_image_gray,
|
||||||
)
|
resize_img,
|
||||||
|
self.rawx,
|
||||||
|
self.rawy,
|
||||||
|
self.radius,
|
||||||
|
) = External_Run_AHSF(self.current_image_gray)
|
||||||
self.thresh = self.current_image_gray
|
self.thresh = self.current_image_gray
|
||||||
self.out_x, self.out_y, self.avg_velocity = cal.cal_osc(
|
self.out_x, self.out_y, self.avg_velocity = cal.cal_osc(
|
||||||
self, self.rawx, self.rawy
|
self, self.rawx, self.rawy
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user