22
33import depthai as dai
44import cv2
5+ import numpy
56import serial
67import numpy as np
78
1718except :
1819 colorMode = QtGui .QImage .Format_RGB888
1920
20- CSV_HEADER = "TimeStamp,MxID,RealDistance,DetectedDistance, planeFitMSE,gtPlaneMSE,planeFitRMSE," \
21- "gtPlaneRMSE,fillRate,pixelsNo,Result,Side"
21+ CSV_HEADER = "TimeStamp,MxID,RealDistance,planeFitMSE,gtPlaneMSE,planeFitRMSE," \
22+ "gtPlaneRMSE,medGtPlaneRMSE, fillRate,pixelsNo,Result,Side"
2223mx_id = None
2324product = ''
2425inter_conv = None
@@ -254,7 +255,11 @@ def __init__(self, lrcheck, subpixel, extended, distortion, resolution):
254255 # print(self.device.getDeviceInfo().getXLinkDeviceDesc())
255256 sensors = self .device .getCameraSensorNames ()
256257 if resolution == 'Auto' :
257- mono_resolution = cam_res [sensors [dai .CameraBoardSocket .LEFT ]]
258+ try :
259+ mono_resolution = cam_res [sensors [dai .CameraBoardSocket .LEFT ]]
260+ except KeyError as e :
261+ print (f'=================e = { e } ' )
262+ # mono_resolution = cam_res[sensors[dai.CameraBoardSocket.CAM_B]]
258263 else :
259264 mono_resolution = cam_res [resolution ]
260265 if mono_resolution is dai .MonoCameraProperties .SensorResolution .THE_400_P :
@@ -551,6 +556,15 @@ class Application(QtWidgets.QMainWindow):
551556 def __init__ (self ):
552557 super ().__init__ ()
553558 # DepthTest = QtWidgets.QMainWindow()
559+ self .gt_plane_rmse_med = None
560+ self .plane_fit_rmse_avg = 0
561+ self .plane_fit_rmse_res = None
562+ self .gt_plane_mse_avg = 0
563+ self .gt_plane_mse_res = None
564+ self .plane_fit_mse_avg = 0
565+ self .plane_fit_mse_res = None
566+ self .fill_plane_res = None
567+ self .gt_plane_rmse_res = None
554568 self .ir = False
555569 self .roi_depth_np = None
556570 self .pixels_no = 0
@@ -560,6 +574,7 @@ def __init__(self):
560574 self .gt_plane_mse = None
561575 self .plane_fit_mse = None
562576 self .true_distance = 0
577+ self .gt_plane_rmse_arr = []
563578 self .ui = Ui_DepthTest ()
564579 self .ui .setupUi (self )
565580 self .scene = Scene (self )
@@ -580,8 +595,8 @@ def __init__(self):
580595 self .count = 0
581596 self .pass_count = 0
582597 self .fail_count = 0
583- self .max_error = 0
584- self .min_plane_error = 100
598+ self .gt_plane_rmse_avg = 0
599+ self .fill_plane_avg = 100
585600 self .set_result ('' )
586601 self .z_distance = 0
587602 self .plot_fit_plane = None
@@ -674,8 +689,8 @@ def save_csv(self):
674689 side = 'right'
675690 elif self .ui .r_center .isChecked ():
676691 side = 'center'
677- file .write (f'{ int (time .time ())} ,{ mx_id } ,{ self .true_distance } ,{ self .z_distance } ,{ self .plane_fit_mse } ,\
678- { self .gt_plane_mse } ,{ self .plane_fit_rmse } ,{ self .max_error } ,{ self .min_plane_error } ,\
692+ file .write (f'{ int (time .time ())} ,{ mx_id } ,{ self .true_distance } ,{ self .plane_fit_mse_res } ,{ self .gt_plane_mse_res } ,\
693+ { self .plane_fit_rmse_res } ,{ self .gt_plane_rmse_res } ,{ self .gt_plane_rmse_med } ,{ self .fill_plane_res } ,\
679694 { self .pixels_no } ,{ self .ui .l_result .text ()} ,{ side } \n ' )
680695 file .close ()
681696
@@ -719,7 +734,7 @@ def calculate_errors(self):
719734 c , normal = fit_plane_LTSQ (sub_points3D )
720735 d = - np .array ([0.0 , 0.0 , c ]).dot (normal )
721736 plane_offset_error = 0
722- gt_offset_error = 0
737+ absolute_error = 0
723738 planeR_ms_offset_rror = 0
724739 gtR_ms_offset_error = 0
725740 for roi_point in valid_cam_coords .transpose ():
@@ -728,12 +743,12 @@ def calculate_errors(self):
728743 gt_plane = (gt_normal , - self .true_distance )
729744 gt_plane_dist = roi_point .dot (gt_plane [0 ]) + gt_plane [1 ]
730745 plane_offset_error += fitPlaneDist
731- gt_offset_error += gt_plane_dist
746+ absolute_error += gt_plane_dist
732747 planeR_ms_offset_rror += fitPlaneDist ** 2
733748 gtR_ms_offset_error += gt_plane_dist ** 2
734749
735750 self .plane_fit_mse = plane_offset_error / valid_cam_coords .shape [1 ]
736- self .gt_plane_mse = gt_offset_error / valid_cam_coords .shape [1 ]
751+ self .gt_plane_mse = absolute_error / valid_cam_coords .shape [1 ]
737752 self .plane_fit_rmse = np .sqrt (planeR_ms_offset_rror / valid_cam_coords .shape [1 ])
738753 self .gt_plane_rmse = round (np .sqrt (gtR_ms_offset_error / valid_cam_coords .shape [1 ]), 3 )
739754
@@ -806,31 +821,42 @@ def timer_event(self):
806821
807822 # if self.true_distance > 0 and self.z_distance > 0:
808823 if self .count < 30 :
809- if self .max_error < self .gt_plane_rmse :
810- self .max_error = self .gt_plane_rmse
811- if self .min_plane_error > self .fill_rate :
812- self .min_plane_error = self .fill_rate
824+ self .gt_plane_rmse_avg += self .gt_plane_rmse / 30
825+ self .gt_plane_rmse_arr .append (self .gt_plane_rmse_avg )
826+ self .fill_plane_avg += self .fill_rate / 30
827+ self .plane_fit_mse_avg += self .plane_fit_mse / 30
828+ self .gt_plane_mse_avg += self .gt_plane_mse / 30
829+ self .plane_fit_rmse_avg += self .plane_fit_rmse / 30
813830 self .count += 1
814831 else :
815- self .ui .l_fill_rate .setText (f'{ self .min_plane_error } ' )
816- self .ui .l_gt_plane_rmse .setText (f'{ self .max_error } ' )
817- self .ui .l_plane_fit_mse .setText (f'{ self .plane_fit_mse } ' )
818- self .ui .l_gt_plane_mse .setText (f'{ self .gt_plane_mse } ' )
819- self .ui .l_plane_fit_rmse .setText (f'{ self .plane_fit_rmse } ' )
832+ self .ui .l_fill_rate .setText (f'{ self .fill_plane_avg } ' )
833+ self .ui .l_gt_plane_rmse .setText (f'{ self .gt_plane_rmse_avg } ' )
834+ self .ui .l_plane_fit_mse .setText (f'{ self .plane_fit_mse_avg } ' )
835+ self .ui .l_gt_plane_mse .setText (f'{ self .gt_plane_mse_avg } ' )
836+ self .ui .l_plane_fit_rmse .setText (f'{ self .plane_fit_rmse_avg } ' )
820837 self .ui .l_pixels_no .setText (f'{ self .pixels_no } ' )
838+ self .gt_plane_rmse_res = self .gt_plane_rmse_avg
839+ self .gt_plane_rmse_avg = 0
840+ self .fill_plane_res = self .fill_plane_avg
841+ self .fill_plane_avg = 0
842+ self .plane_fit_mse_res = self .plane_fit_mse_avg
843+ self .plane_fit_mse_avg = 0
844+ self .gt_plane_mse_res = self .gt_plane_mse_avg
845+ self .gt_plane_mse_avg = 0
846+ self .plane_fit_rmse_res = self .plane_fit_rmse_avg
847+ self .plane_fit_rmse_avg = 0
848+ self .gt_plane_rmse_med = np .median (self .gt_plane_rmse_arr )
821849 if self .true_distance <= 1 :
822850 error_threshold = 0.03
823851 elif self .true_distance >= 2 :
824852 error_threshold = 0.06
825853 else :
826854 error_threshold = self .true_distance * 0.03
827- if self .max_error < error_threshold and self .min_plane_error > 0.98 :
855+ if self .gt_plane_rmse_res < error_threshold and self .fill_plane_res > 0.98 :
828856 self .set_result ('PASS' )
829857 else :
830858 self .set_result ('FAIL' )
831859 self .count = 0
832- self .max_error = 0
833- self .min_plane_error = 100
834860
835861
836862if __name__ == "__main__" :
0 commit comments