add colors to text prints + cleanup

This commit is contained in:
Prohurtz 2023-01-22 19:09:56 -06:00
parent a47b746962
commit f492e3fdab
10 changed files with 72 additions and 60 deletions

View File

@ -90,9 +90,7 @@ class Camera:
if should_push:
self.push_image_to_queue(image, frame_number, fps)
except:
print(
"Capture source problem, assuming camera disconnected, waiting for reconnect."
)
print("\033[91m[WARN] Capture source problem, assuming camera disconnected, waiting for reconnect...\033[0m")
self.camera_status = CameraState.DISCONNECTED
pass
@ -101,8 +99,6 @@ class Camera:
# some sort of capture event conflict though.
qsize = self.camera_output_outgoing.qsize()
if qsize > 1:
print(
f"CAPTURE QUEUE BACKPRESSURE OF {qsize}. CHECK FOR CRASH OR TIMING ISSUES IN ALGORITHM."
)
print(f"\033[91mCAPTURE QUEUE BACKPRESSURE OF {qsize}. CHECK FOR CRASH OR TIMING ISSUES IN ALGORITHM.\033[0m")
self.camera_output_outgoing.put((image, frame_number, fps))
self.capture_event.clear()

View File

@ -183,7 +183,7 @@ class CameraWidget:
event == self.gui_save_tracking_button
and values[self.gui_camera_addr] != self.config.capture_source
):
print("[INFO] New value: {}".format(values[self.gui_camera_addr]))
print("\033[94m[INFO] New value: {}\033[0m".format(values[self.gui_camera_addr]))
try:
# Try storing ints as ints, for those using wired cameras.
self.config.capture_source = int(values[self.gui_camera_addr])
@ -208,14 +208,14 @@ class CameraWidget:
self.main_config.save()
if event == self.gui_tracking_button:
print("[INFO] Moving to tracking mode")
print("\033[94m[INFO] Moving to tracking mode\033[0m")
self.in_roi_mode = False
self.camera.set_output_queue(self.capture_queue)
window[self.gui_roi_layout].update(visible=False)
window[self.gui_tracking_layout].update(visible=True)
if event == self.gui_roi_button:
print("[INFO] Move to roi mode")
print("\033[94m[INFO] Move to roi mode\033[0m")
self.in_roi_mode = True
self.camera.set_output_queue(self.roi_queue)
window[self.gui_roi_layout].update(visible=True)
@ -257,7 +257,7 @@ class CameraWidget:
elif self.camera.camera_status == CameraState.DISCONNECTED:
window[self.gui_mode_readout].update("CAMERA DISCONNECTED")
elif needs_roi_set:
window[self.gui_mode_readout].update("Awaiting Eye Cropping Setting")
window[self.gui_mode_readout].update("Awaiting Eye Crop")
elif self.ransac.calibration_frame_counter != None:
window[self.gui_mode_readout].update("Calibration")
else:
@ -301,9 +301,6 @@ class CameraWidget:
if eye_info.info_type != InformationOrigin.FAILURE and not eye_info.blink:
graph.update(background_color="white")
#try:
# print(eye_info.x, eye_info.y)
if not np.isnan(eye_info.x) and not np.isnan(eye_info.y):
graph.draw_circle(
@ -313,15 +310,13 @@ class CameraWidget:
line_color="white",
)
else:
graph.draw_circle(
(0.0 * -100, 0.0 * -100),
25,
fill_color="black",
line_color="white",
)
# except:
# pass
elif eye_info.blink:
graph.update(background_color="#6f4ca1")
elif eye_info.info_type == InformationOrigin.FAILURE:

View File

@ -57,6 +57,9 @@ from ransac import *
from hsrac import *
from blink import *
from intensity_eye_open import *
class InformationOrigin(Enum):
RANSAC = 1
BLOB = 2
@ -171,7 +174,7 @@ class EyeProcessor:
min_cutoff = float(self.settings.gui_min_cutoff) # 0.0004
beta = float(self.settings.gui_speed_coefficient) # 0.9
except:
print('[WARN] OneEuroFilter values must be a legal number.')
print('\033[93m[WARN] OneEuroFilter values must be a legal number.\033[0m')
min_cutoff = 0.0004
beta = 0.9
noisy_point = np.array([1, 1])
@ -194,7 +197,7 @@ class EyeProcessor:
self.previous_image = self.current_image
self.previous_rotation = self.config.rotation_angle
except: # If this fails it likely means that the images are not the same size for some reason.
print('[ERROR] Size of frames to display are of unequal sizes.')
print('\033[91m[ERROR] Size of frames to display are of unequal sizes.\033[0m')
pass
def capture_crop_rotate_image(self):
@ -214,7 +217,7 @@ class EyeProcessor:
except:
# Failure to process frame, reuse previous frame.
self.current_image = self.previous_image
print("[ERROR] Frame capture issue detected.")
print("\033[91m[ERROR] Frame capture issue detected.\033[0m")
try:
# Apply rotation to cropped area. For any rotation area outside of the bounds of the image,
@ -265,6 +268,7 @@ class EyeProcessor:
# self.output_images_and_update(thresh, EyeInformation(InformationOrigin.HSRAC, 0, 0, 0, False))
def HSFM(self):
cx, cy, frame = External_Run_HSF.HSFS(self)
intense(cx, cy, frame)
out_x, out_y = cal_osc(self, cx, cy)
if cx == 0:
self.output_images_and_update(frame, EyeInformation(InformationOrigin.HSF, out_x, out_y, 0, True)) #update app

View File

@ -50,8 +50,8 @@ def main():
# Check to see if we can connect to our video source first. If not, bring up camera finding
# dialog.
print("[INFO] Checking for updates...")
print("\033[95m[INFO] Checking for updates...\033[0m")
url = "https://raw.githubusercontent.com/RedHawk989/EyeTrackVR-Installer/master/Version-Data/Version_Num.txt"
html = urlopen(url).read()
soup = BeautifulSoup(html, features="html.parser")

View File

@ -813,10 +813,10 @@ class HSRAC_cls(object):
self.timedict["crop"].append(cv_end_time - crop_start_time)
self.timedict["total_cv"].append(cv_end_time - cv_start_time)
if calc_print_enable:
# if calc_print_enable:
# the lower the response the better the likelyhood of there being a pupil. you can adujst the radius and steps accordingly
print('Kernel response:', response)
print('Pixel position:', center_xy)
# print('Kernel response:', response)
# print('Pixel position:', center_xy)
if imshow_enable:
if self.now_modeo != self.cv_modeo[0] and self.now_modeo != self.cv_modeo[1]:

View File

@ -19,26 +19,40 @@ xy = 69
def intense(x, y, frame):
xy = int(str(x) + str(y))
intensity = np.sum(frame)
print(intensity)
#print(intensity)
try:
try: #max pupil per cord
dfb = data[data['xy']==xy].index.values.astype(int)[0] # find pandas index of line with matching xy value
if intensity < data.at[dfb, 'intensity']: #if current intensity value is less (more pupil), save that
data.at[dfb, 'intensity'] = intensity # set value
data.to_csv(fname, encoding='utf-8', index=False) #save file since we made a change
if intensity > data.at[0, 'intensity']: #if current intensity value is more (less pupil), save that NOTE: we have the
data.at[0, 'intensity'] = intensity # set value
data.to_csv(fname, encoding='utf-8', index=False) #save file since we made a change
#e = data.at[dfb,'intensity'] #find intensity with value
except: # that value is not yet saved
data.loc[len(data.index)] = [xy, intensity] #create new data on last line of csv with current intesity
data.to_csv(fname, encoding='utf-8', index=False) #save file since we made a change
try: # min pupil global
if intensity > data.at[0, 'intensity']: #if current intensity value is more (less pupil), save that NOTE: we have the
data.at[0, 'intensity'] = intensity # set value at 0 index
data.to_csv(fname, encoding='utf-8', index=False) #save file since we made a change
print("new max", intensity)
except: # there is no max intensity yet, create
data.at[0, 'intensity'] = intensity # set value at 0 index
data.to_csv(fname, encoding='utf-8', index=False) #save file since we made a change
print("create max", intensity)
maxp = data.at[dfb, 'intensity']
minp = data.at[0, 'intensity']
eyeopen = (intensity - maxp) / (minp - maxp)
print(f"EYEOPEN: {eyeopen}")
#e = data.at[dfb,'intensity'] #find intensity with value
#data.at[dfb, 'intensity'] = 4 # set value
#data.to_csv(fname, encoding='utf-8', index=False) #save file
@ -48,24 +62,25 @@ def intense(x, y, frame):
return
vid = cv2.VideoCapture("http://192.168.1.43:4747/video")
x = int(input("x"))
y = int(input("y"))
while(True):
ret, frame = vid.read()
cv2.imshow('frame', frame)
upper_x = x + 20
lower_x = x - 20
upper_y = y + 20
lower_y = y - 20
cropped_image = frame[lower_y:upper_y, lower_x:upper_x]
intense(x,y, cropped_image)
#vid = cv2.VideoCapture("http://192.168.1.43:4747/video")
#x = int(input("x"))
#y = int(input("y"))
if cv2.waitKey(1) & 0xFF == ord('q'):
break
#while(True):
# ret, frame = vid.read()
vid.release()
cv2.destroyAllWindows()
# cv2.imshow('frame', frame)
# upper_x = x + 20
#lower_x = x - 20
# upper_y = y + 20
# lower_y = y - 20
# cropped_image = frame[lower_y:upper_y, lower_x:upper_x]
# intense(x,y, cropped_image)
# if cv2.waitKey(1) & 0xFF == ord('q'):
# break
#vid.release()
#cv2.destroyAllWindows()

View File

@ -50,4 +50,4 @@ class OneEuroFilter:
return x_hat
except:
print("[WARN] One Euro Filter Error. Is your system clock running properly?")
print("\033[91m[ERROR] One Euro Filter Error. Is your system clock running properly?\033[0m")

View File

@ -163,7 +163,7 @@ class VRChatOSCReceiver:
print(f"\033[91m[ERROR] OSC Recieve port: {self.config.gui_osc_receiver_port} occupied.\033[0m")
def shutdown(self):
print("\033[94m[INFO] Exiting OSC receiver")
print("\033[94m[INFO] Exiting OSC receiver\033[0m")
try:
self.server.shutdown()
except:

View File

@ -38,6 +38,8 @@ def cal_osc(self, cx, cy):
self.ts = 10
try:
out_x = 0.5
out_y = 0.5
xl = float(
(cx - self.xoff) / (self.xmax - self.xoff)
)
@ -51,8 +53,6 @@ def cal_osc(self, cx, cy):
(cy - self.yoff) / (self.ymax - self.yoff)
)
out_x = 0
out_y = 0
if self.settings.gui_flip_y_axis: # check config on flipped values settings and apply accordingly
if yd >= 0:
out_y = max(0.0, min(1.0, yd))
@ -76,6 +76,8 @@ def cal_osc(self, cx, cy):
out_x = -abs(max(0.0, min(1.0, xl)))
except:
print("[ERROR] Eye Calibration Invalid!")
out_x = 0.5
out_y = 0.5
try:
noisy_point = np.array([float(out_x), float(out_y)]) # fliter our values with a One Euro Filter
point_hat = self.one_euro_filter(noisy_point)

View File

@ -349,9 +349,9 @@ class SettingsWidget:
self.config.gui_osc_port = int(values[self.gui_osc_port])
changed = True
else:
print("[ERROR] OSC port value must be an integer 0-65535")
print("\033[91m[ERROR] OSC port value must be an integer 0-65535\033[0m")
except:
print("[ERROR] OSC port value must be an integer 0-65535")
print("\033[91m[ERROR] OSC port value must be an integer 0-65535\033[0m")
if self.config.gui_osc_receiver_port != values[self.gui_osc_receiver_port]:
try:
@ -360,9 +360,9 @@ class SettingsWidget:
self.config.gui_osc_receiver_port = int(values[self.gui_osc_receiver_port])
changed = True
else:
print("[ERROR] OSC receive port value must be an integer 0-65535")
print("\033[91m[ERROR] OSC receive port value must be an integer 0-65535\033[0m")
except:
print("[ERROR] OSC receive port value must be an integer 0-65535")
print("\033[91m[ERROR] OSC receive port value must be an integer 0-65535\033[0m")
if self.config.gui_osc_address != values[self.gui_osc_address]:
self.config.gui_osc_address = values[self.gui_osc_address]