Ejemplo n.º 1
0
def gaze_mapping_result_2d(img_path,
                           calibration="dummy",
                           calibration_path="",
                           calibration_ground_truth=True):

    ##### prepare data #####
    img = cv2.imread(img_path)
    frame = Frame(1, img, 1)
    u_r = Roi(frame.img.shape)

    detector2d = detector_2d.Detector_2D()
    pupil_datum = detector2d.detect(frame, user_roi=u_r, visualize=False)
    pupil_datum['id'] = 0
    #print(pupil_datum)

    pool = SimpleNamespace()
    pool.active_gaze_mapping_plugin = None
    ##### prepare data #####

    ##### map gaze #####
    if calibration == "dummy":
        pool.active_gaze_mapping_plugin = gaze_mappers.Dummy_Gaze_Mapper(pool)
    elif calibration == "monocular":
        cal_pt_cloud = read_monocular_calibration_data_from_file(
            calibration_path, calibration_ground_truth)
        #cal_pt_cloud = read_monocular_calibration_data(calibration_path, calibration_ground_truth)
        _, _, params = calibrate.calibrate_2d_polynomial(cal_pt_cloud)
        #print(params)
        pool.active_gaze_mapping_plugin = gaze_mappers.Monocular_Gaze_Mapper(
            pool, params)

    gaze_data = pool.active_gaze_mapping_plugin.on_pupil_datum(pupil_datum)
    #print(gaze_data)
    ##### map gaze #####
    return gaze_data[0]['norm_pos']
Ejemplo n.º 2
0
def gaze_mapping_with_gt_pupil_2d(img_path,
                                  calibration="dummy",
                                  calibration_path="",
                                  calibration_ground_truth=True):

    ##### prepare data #####
    img = cv2.imread(img_path)
    frame = Frame(1, img, 1)
    u_r = Roi(frame.img.shape)

    detector2d = detector_2d.Detector_2D()
    pupil_datum = detector2d.detect(frame, user_roi=u_r, visualize=False)

    center, degree, axes = gt_pupil_info(img_path)
    pupil_datum['confidence'] = 1.0
    pupil_datum['diameter'] = max(axes)
    pupil_datum['ellipse']['center'] = center
    pupil_datum['ellipse']['angle'] = degree
    pupil_datum['ellipse']['axes'] = axes
    pupil_datum['norm_pos'] = [center[0] / 320, (240 - center[1]) / 240]
    pupil_datum['id'] = 0

    #print(pupil_datum)

    pool = SimpleNamespace()
    pool.active_gaze_mapping_plugin = None
    ##### prepare data #####

    ##### map gaze #####
    if calibration == "dummy":
        pool.active_gaze_mapping_plugin = gaze_mappers.Dummy_Gaze_Mapper(pool)
    elif calibration == "monocular":
        cal_pt_cloud = read_monocular_calibration_data_from_file(
            calibration_path, calibration_ground_truth)
        #cal_pt_cloud = read_monocular_calibration_data(calibration_path, calibration_ground_truth)
        _, _, params = calibrate.calibrate_2d_polynomial(cal_pt_cloud)
        #print(params)
        pool.active_gaze_mapping_plugin = gaze_mappers.Monocular_Gaze_Mapper(
            pool, params)

    gaze_data = pool.active_gaze_mapping_plugin.on_pupil_datum(pupil_datum)
    #print(gaze_data)
    ##### map gaze #####
    return gaze_data[0]['norm_pos']
Ejemplo n.º 3
0
        self.g_pool.gui.append(self.menu)

    def deinit_gui(self):
        if self.menu:
            self.g_pool.gui.remove(self.menu)


    def gl_display(self):
        if self.inliers is not None:
            draw_polyline_norm(self.inliers,1,RGBA(1.,.5,0.,.5),line_type=GL_LINES)
            draw_polyline_norm(self.outliers,1,RGBA(1.,0.,0.,.5),line_type=GL_LINES)
            draw_polyline_norm(self.calib_bounds[:,0],1,RGBA(.0,1.,0,.5),line_type=GL_LINE_LOOP)

    def close(self):
        self.alive = False

    def cleanup(self):
        self.deinit_gui()



if __name__ == '__main__':
    cal_pt_cloud = np.load("cal_pt_cloud.npy")
    map_fn,inlier_map = calibrate_2d_polynomial(cal_pt_cloud,(1280,720),return_inlier_map=True)
    # print cal_pt_cloud[inlier_map][:,0:2].shape
    # print cal_pt_cloud[inlier_map][0,2:4]
    inlier = np.concatenate((cal_pt_cloud[inlier_map][:,0:2],cal_pt_cloud[inlier_map][:,2:4]),axis=1)
    print inlier
    print inlier.reshape(-1,2)