Utilities/video_and_plotting/Calibrate_Fisheye.py
def find_checkerboard(self, display=True):
        '''find_checkerboard [goes through calibration images and detectes checkerboard in them, returns identified points]
        
        Keyword Arguments:
            display {bool} -- [display images as computation takes over yes/no] (default: {True})
        
        Returns:
            last calibration image used
            object points - ?
            image points - ?
        '''

        # Find checkerboard corners -- set up for .pngs
        # //CHECKERFLIP = tuple(np.flip(self.CHECKERBOARD, 0))
        subpix_criteria = (cv2.TERM_CRITERIA_EPS+cv2.TERM_CRITERIA_MAX_ITER, 30, 0.1)
        objp = np.zeros((1, self.CHECKERBOARD[0]*self.CHECKERBOARD[1], 3), np.float32)
        objp[0, :, :2] = np.mgrid[0:self.CHECKERBOARD[0], 0:self.CHECKERBOARD[1]].T.reshape(-1, 2)

        # Loop over images
        self._img_shape = None
        objpoints = [] # 3d point in real world space
        imgpoints = [] # 2d points in image plane.

        images = [os.path.join(self.images_fld, i) for i in os.listdir(self.images_fld) if 'png' in i or 'jpg' in i]
        for fname in images:
            img = cv2.imread(fname)
            if self._img_shape == None:
                self._img_shape = img.shape[:2]
            else:
                assert self._img_shape == img.shape[:2], "All images must share the same size."
            

            calib_image_pre = cv2.cvtColor(img.astype(np.uint8),cv2.COLOR_BGR2GRAY)
            #increase contrast
            for light_threshold in self.light_thresholds:
                calib_image = calib_image_pre
                
                calib_image[calib_image<dark_threshold] = 0
                calib_image[calib_image>light_threshold] = 255

                if display:
                    cv2.imshow('calibration image',calib_image)  # <- display thresholded image
                    if cv2.waitKey(5) & 0xFF == ord('q'): break

                # Find the chess board corners, if succesful -> stop
                ret, corners = cv2.findChessboardCorners(
                    calib_image, self.CHECKERBOARD, cv2.CALIB_CB_ADAPTIVE_THRESH+cv2.CALIB_CB_NORMALIZE_IMAGE+cv2.CALIB_CB_FAST_CHECK)
                if ret: break
            print(ret)

            # If found, add object points, image points (after refining them)
            if ret:
                objpoints.append(objp)
                corners2 = cv2.cornerSubPix(calib_image,corners,(11,11),(-1,-1),subpix_criteria)
                imgpoints.append(corners)

                # Draw and display the corners
                if display:
                    cv2.drawChessboardCorners(calib_image, self.CHECKERBOARD, corners2, ret)
                    cv2.imshow('calibration image', calib_image)
                    cv2.waitKey(500)
        return calib_image, objpoints, imgpoints
find_checkerboard [goes through calibration images and detectes checkerboard in them, returns identified points]
        
        Keyword Arguments:
            display {bool} -- [display images as computation takes over yes/no] (default: {True})
        
        Returns:
            last calibration image used
            object points - ?
            image points - ?
        
find_checkerboard [goes through calibration images and detectes checkerboard in them, returns identified points]
Keyword Arguments:
display {bool} -- [display images as computation takes over yes/no] (default: {True})
find_checkerboard [ goes through calibration images and detectes checkerboard in them returns identified points ] Keyword Arguments : display { bool } -- [ display images as computation takes over yes / no ] ( default : { True } )
def find_checkerboard(self, display=True):
        subpix_criteria = (cv2.TERM_CRITERIA_EPS+cv2.TERM_CRITERIA_MAX_ITER, 30, 0.1)
        objp = np.zeros((1, self.CHECKERBOARD[0]*self.CHECKERBOARD[1], 3), np.float32)
        objp[0, :, :2] = np.mgrid[0:self.CHECKERBOARD[0], 0:self.CHECKERBOARD[1]].T.reshape(-1, 2)
        self._img_shape = None
        objpoints = [] 
        imgpoints = [] 
        images = [os.path.join(self.images_fld, i) for i in os.listdir(self.images_fld) if 'png' in i or 'jpg' in i]
        for fname in images:
            img = cv2.imread(fname)
            if self._img_shape == None:
                self._img_shape = img.shape[:2]
            else:
                assert self._img_shape == img.shape[:2], "All images must share the same size."
            calib_image_pre = cv2.cvtColor(img.astype(np.uint8),cv2.COLOR_BGR2GRAY)
            for light_threshold in self.light_thresholds:
                calib_image = calib_image_pre
                calib_image[calib_image<dark_threshold] = 0
                calib_image[calib_image>light_threshold] = 255
                if display:
                    cv2.imshow('calibration image',calib_image)  
                    if cv2.waitKey(5) & 0xFF == ord('q'): break
                ret, corners = cv2.findChessboardCorners(
                    calib_image, self.CHECKERBOARD, cv2.CALIB_CB_ADAPTIVE_THRESH+cv2.CALIB_CB_NORMALIZE_IMAGE+cv2.CALIB_CB_FAST_CHECK)
                if ret: break
            print(ret)
            if ret:
                objpoints.append(objp)
                corners2 = cv2.cornerSubPix(calib_image,corners,(11,11),(-1,-1),subpix_criteria)
                imgpoints.append(corners)
                if display:
                    cv2.drawChessboardCorners(calib_image, self.CHECKERBOARD, corners2, ret)
                    cv2.imshow('calibration image', calib_image)
                    cv2.waitKey(500)
        return calib_image, objpoints, imgpoints
def find_checkerboard ( self , display = True ) : subpix_criteria = ( cv2 . TERM_CRITERIA_EPS + cv2 . TERM_CRITERIA_MAX_ITER , 30 , 0.1 ) objp = np . zeros ( ( 1 , self . CHECKERBOARD [ 0 ] * self . CHECKERBOARD [ 1 ] , 3 ) , np . float32 ) objp [ 0 , : , : 2 ] = np . mgrid [ 0 : self . CHECKERBOARD [ 0 ] , 0 : self . CHECKERBOARD [ 1 ] ] . T . reshape ( - 1 , 2 ) self . _img_shape = None objpoints = [ ] imgpoints = [ ] images = [ os . path . join ( self . images_fld , i ) for i in os . listdir ( self . images_fld ) if 'png' in i or 'jpg' in i ] for fname in images : img = cv2 . imread ( fname ) if self . _img_shape == None : self . _img_shape = img . shape [ : 2 ] else : assert self . _img_shape == img . shape [ : 2 ] , "All images must share the same size." calib_image_pre = cv2 . cvtColor ( img . astype ( np . uint8 ) , cv2 . COLOR_BGR2GRAY ) for light_threshold in self . light_thresholds : calib_image = calib_image_pre calib_image [ calib_image < dark_threshold ] = 0 calib_image [ calib_image > light_threshold ] = 255 if display : cv2 . imshow ( 'calibration image' , calib_image ) if cv2 . waitKey ( 5 ) & 0xFF == ord ( 'q' ) : break ret , corners = cv2 . findChessboardCorners ( calib_image , self . CHECKERBOARD , cv2 . CALIB_CB_ADAPTIVE_THRESH + cv2 . CALIB_CB_NORMALIZE_IMAGE + cv2 . CALIB_CB_FAST_CHECK ) if ret : break print ( ret ) if ret : objpoints . append ( objp ) corners2 = cv2 . cornerSubPix ( calib_image , corners , ( 11 , 11 ) , ( - 1 , - 1 ) , subpix_criteria ) imgpoints . append ( corners ) if display : cv2 . drawChessboardCorners ( calib_image , self . CHECKERBOARD , corners2 , ret ) cv2 . imshow ( 'calibration image' , calib_image ) cv2 . waitKey ( 500 ) return calib_image , objpoints , imgpoints
find_checkerboard [goes through calibration images and detectes checkerboard in them, returns identified points]
Keyword Arguments:
display {bool} -- [display images as computation takes over yes/no] (default: {True})
find_checkerboard [ goes through calibration images and detectes checkerboard in them returns identified points ] Keyword Arguments : display { bool } -- [ display images as computation takes over yes / no ] ( default : { True } )
'''find_checkerboard [goes through calibration images and detectes checkerboard in them, returns identified points]
        
        Keyword Arguments:
            display {bool} -- [display images as computation takes over yes/no] (default: {True})
        
        Returns:
            last calibration image used
            object points - ?
            image points - ?
        ''' # Find checkerboard corners -- set up for .pngs # //CHECKERFLIP = tuple(np.flip(self.CHECKERBOARD, 0)) # Loop over images # 3d point in real world space # 2d points in image plane. #increase contrast # <- display thresholded image # Find the chess board corners, if succesful -> stop # If found, add object points, image points (after refining them) # Draw and display the corners
last calibration image used
object points - .
last calibration image used object points - .
self
display