Exemplo n.º 1
0
 def change_resize_undist_mode(val):
     self.resize_distord = val
     if val:  #find the right value to crop
         self.affine_roi()
     else:    #find the original roi
         _, self.roi = cv2.getOptimalNewCameraMatrix(cameraMatrix= self.camera_intrinsics[0], distCoeffs=self.camera_intrinsics[1], imageSize=self.camera_intrinsics[2], alpha=0.7,newImgSize=self.camera_intrinsics[2],centerPrincipalPoint=1)
         self.roi += 0., 0.
     init_prev_img()
Exemplo n.º 2
0
    def __init__(self,g_pool,mode="Show marker IDs",min_marker_perimeter = 40):
        super(World_Interaction, self).__init__(g_pool)
        self.order = .2

        # all markers that are detected in the most recent frame
        self.markers = []
        init_prev_img()

        #load camera intrinsics
        try:
            camera_calibration = load_object(os.path.join(self.g_pool.user_dir,'camera_calibration'))
        except:
            self.camera_intrinsics = None
        else:
            same_name = camera_calibration['camera_name'] == self.g_pool.capture.name
            same_resolution =  camera_calibration['resolution'] == self.g_pool.capture.frame_size
            if same_name and same_resolution:
                logger.info('Loaded camera calibration.')
                A = camera_calibration['camera_matrix']
                dist_coefs = camera_calibration['dist_coefs']
                resolution = camera_calibration['resolution']
                error = camera_calibration['error']
                #roi = region of interrest, where the image have been crop
                new_cm, self.roi = cv2.getOptimalNewCameraMatrix(cameraMatrix= A, distCoeffs=dist_coefs, imageSize=resolution, alpha=0.7, newImgSize=resolution, centerPrincipalPoint=1)
                self.roi += 0., 0.
                self.affine_roi()
                self.camera_intrinsics = A,dist_coefs,resolution,error,new_cm
            else:
                logger.info('Loaded camera calibration but camera name and/or resolution has changed. Please re-calibrate.')
                self.camera_intrinsics = None

        # all registered markers
        self.markers_definitions = Persistent_Dict(os.path.join(g_pool.user_dir,'markers_definitions') )
        self.markers = [d for d in  self.markers_definitions.get('realtime_square_marker',[]) if isinstance(d,dict)]

        #quit if no calibrations
        if self.camera_intrinsics == None:
            logger.info('Please calibrate first')
            self.close()

        #plugin state
        self.mode = mode
        self.running = True

        self.criteria = (cv2.TERM_CRITERIA_EPS + cv2.TERM_CRITERIA_MAX_ITER, 30, 0.001)

        #self.axis = np.float32([[40,0,0], [0,40,0], [0,0,40]]).reshape(-1,3)

        self.robust_detection = 1
        self.min_marker_perimeter = min_marker_perimeter
        self.nb_frame_detection = 10

        #for display
        self.only_visible_m = True
        self.config_markers = 0
        self.glIsInit = False
        self.show_undistord = False
        self.resize_distord = False

        #debug vars
        self.img_shape = None
        self.frame_img = None
        self.camera_coord = None  #3D position
        self.current_gaze_pos = None # in pixel coordinate

        self.menu= None
        self.button=  None
Exemplo n.º 3
0
 def change_undist_mode(val):
     self.show_undistord = val
     init_prev_img()