def stop(self):
     # TODO: redundancy between all gaze mappers -> might be moved to parent class
     audio.say("Stopping Fingertip Calibration")
     logger.info('Stopping Fingertip Calibration')
     self.active = False
     self.button.status_text = ''
     if self.mode == 'calibration':
         finish_calibration.finish_calibration(self.g_pool, self.pupil_list, self.ref_list)
     elif self.mode == 'accuracy_test':
         self.finish_accuracy_test(self.pupil_list, self.ref_list)
     super().stop()
 def stop(self):
     # TODO: redundancy between all gaze mappers -> might be moved to parent class
     audio.say("Stopping Fingertip Calibration")
     logger.info("Stopping Fingertip Calibration")
     self.active = False
     self.button.status_text = ""
     if self.mode == "calibration":
         finish_calibration.finish_calibration(
             self.g_pool, self.pupil_list, self.ref_list
         )
     elif self.mode == "accuracy_test":
         self.finish_accuracy_test(self.pupil_list, self.ref_list)
     super().stop()
Beispiel #3
0
 def stop(self):
     # TODO: redundancy between all gaze mappers -> might be moved to parent class
     logger.info("Stopping {}".format(self.mode_pretty))
     self.smooth_pos = 0, 0
     self.counter = 0
     self.close_window()
     self.active = False
     self.button.status_text = ''
     if self.mode == 'calibration':
         finish_calibration(self.g_pool, self.pupil_list, self.ref_list)
     elif self.mode == 'accuracy_test':
         self.finish_accuracy_test(self.pupil_list, self.ref_list)
     super().stop()
 def stop(self):
     # TODO: redundancy between all gaze mappers -> might be moved to parent class
     logger.info("Stopping {}".format(self.mode_pretty))
     self.smooth_pos = 0, 0
     self.counter = 0
     self.close_window()
     self.active = False
     self.button.status_text = ''
     if self.mode == 'calibration':
         finish_calibration(self.g_pool, self.pupil_list, self.ref_list)
     elif self.mode == 'accuracy_test':
         self.finish_accuracy_test(self.pupil_list, self.ref_list)
     super().stop()
Beispiel #5
0
    def calibrate_from_user_calibration_data_file(self):
        user_calibration = load_object(os.path.join(self.g_pool.user_dir, "user_calibration_data"))

        self.pupil_list = user_calibration['pupil_list']
        self.ref_list = user_calibration['ref_list']
        calibration_method = user_calibration['calibration_method']

        if '3d' in calibration_method:
            logger.error('adjust calibration is not supported for 3d calibration.')
            return


        finish_calibration.finish_calibration(self.g_pool,self.pupil_list,self.ref_list)
 def stop(self):
     audio.say("Stopping  {}".format(self.mode_pretty))
     logger.info("Stoppingo  {}".format(self.mode_pretty))
     self.ts_file.close()
     self.screen_marker_state = 0
     self.active = False
     self.smooth_pos = 0.0, 0.0
     # self.close_window()
     self.button.status_text = ""
     if self.mode == "calibration":
         finish_calibration(self.g_pool, self.pupil_list, self.ref_list)
     elif self.mode == "accuracy_test":
         self.finish_accuracy_test(self.pupil_list, self.ref_list)
     super().stop()
     with open(self.ts_filename, 'a+') as self.ts_file:
         self.ts_file.close()
Beispiel #7
0
    def calibrate_from_csv(self, pupil_list, data_path):
        import csv
        ref_list = []
        all_ref_list = []
        with open(os.path.join(data_path, 'crowdpos/cal.csv'), 'rU') as csvfile:
            all = csv.reader(csvfile, delimiter=',')
            smooth_pos1 = 0.,0.
            smooth_vel1 = 0
            sample_site1 = (-2,-2)
            counter1 = 0
            counter_max = 30
            count_all_detected = 0
            for row in all:
                norm_center = make_tuple(row[1])
                center = (norm_center[0] * 1280, (1 - norm_center[1]) * 720)
                center = (int(round(center[0])),int(round(center[1])))

                # calculate smoothed manhattan velocity
                smoother = 0.3
                smooth_pos = np.array(smooth_pos1)
                pos = np.array(norm_center)
                new_smooth_pos = smooth_pos + smoother*(pos-smooth_pos)
                smooth_vel_vec = new_smooth_pos - smooth_pos
                smooth_pos = new_smooth_pos
                smooth_pos1 = list(smooth_pos)
                #manhattan distance for velocity
                new_vel = abs(smooth_vel_vec[0])+abs(smooth_vel_vec[1])
                smooth_vel1 = smooth_vel1 + smoother*(new_vel-smooth_vel1)

                #distance to last sampled site
                sample_ref_dist = smooth_pos-np.array(sample_site1)
                sample_ref_dist = abs(sample_ref_dist[0])+abs(sample_ref_dist[1])

                # start counter if ref is resting in place and not at last sample site
                if not counter1:

                    if smooth_vel1 < 0.01 and sample_ref_dist > 0.1:
                        sample_site1 = smooth_pos1
                        logger.debug("Steady marker found. Starting to sample %s datapoints" %counter_max)
                        # self.notify_all({'subject':'calibration marker found','timestamp':self.g_pool.capture.get_timestamp(),'record':True,'network_propagate':True})
                        counter1 = counter_max

                if counter1:
                    if smooth_vel1 > 0.01:
                        logger.warning("Marker moved too quickly: Aborted sample. Sampled %s datapoints. Looking for steady marker again."%(counter_max-counter1))
                        # self.notify_all({'subject':'calibration marker moved too quickly','timestamp':self.g_pool.capture.get_timestamp(),'record':True,'network_propagate':True})
                        counter1 = 0
                    else:
                        count_all_detected += 1
                        counter1 -= 1
                        ref = {}
                        ref["norm_pos"] = norm_center
                        ref["screen_pos"] = center
                        ref["timestamp"] = float(row[0])
                        ref_list.append(ref)
                        if counter1 == 0:
                            #last sample before counter done and moving on
                            logger.debug("Sampled %s datapoints. Stopping to sample. Looking for steady marker again."%counter_max)
                            # self.notify_all({'subject':'calibration marker sample completed','timestamp':self.g_pool.capture.get_timestamp(),'record':True,'network_propagate':True})
                # save all ref to look at pos on the images
                ref = {}
                ref["norm_pos"] = norm_center
                ref["screen_pos"] = center
                ref["timestamp"] = float(row[0])
                all_ref_list.append(ref)

        ref_list.sort(key=lambda d: d['timestamp'])
        all_ref_list.sort(key=lambda d: d['timestamp'])
        timebase = Value(c_double,0)
        capture_world = autoCreateCapture(os.path.join(data_path, 'world.mp4'), timebase=timebase)
        default_settings = {'frame_size':(1280,720),'frame_rate':30}
        capture_world.settings = default_settings
        # import cv2
        # video_capture = cv2.VideoCapture('/Developments/NCLUni/pupil_crowd4Jul16/recordings/2016_07_06/003/world.mp4')
        # pos_frame = video_capture.get(cv2.cv.CV_CAP_PROP_POS_FRAMES)
        save_crowd_detected = os.path.join(data_path, 'crowd_detected_cal')
        if not os.path.exists(save_crowd_detected):
            os.makedirs(save_crowd_detected)
        while True:
            try:
                # get frame by frame
                frame = capture_world.get_frame()
                r_idx, selected_frame = self.search(frame.timestamp, all_ref_list )
                if selected_frame:
                    # pos_frame = video_capture.get(cv2.cv.CV_CAP_PROP_POS_FRAMES)
                    center = (selected_frame["norm_pos"][0] * 1280, (1 - selected_frame["norm_pos"][1]) * 720)
                    self.save_image_from_array(frame.img, save_crowd_detected + '/%s.jpg'%repr(frame.timestamp), center=center)
            except EndofVideoFileError:
                logger.warning("World video file is done. Stopping")
                break
            except:
                break
        keys = all_ref_list[0].keys()
        with open(os.path.join(data_path, 'crowdpos/generated_ref_list.csv'),'wb') as f:
            dict_writer = csv.DictWriter(f, keys)
            dict_writer.writeheader()
            dict_writer.writerows(all_ref_list)
        finish_calibration.finish_calibration(self.g_pool,pupil_list,ref_list)
        return ref_list