(event, x, y, flags, param)
This callback function calibrates the image perspective transform
This callback function calibrates the image perspective transform
This callback function calibrates the image perspective transform
def print_point_callback(event, x, y, flags, param):
    """
    This callback function calibrates the image perspective transform
    """
    global point_num
    global image_calibrated
    global calibration_pts
    global transformation
    global image_processor_global
    
    if event == cv2.EVENT_LBUTTONDOWN:
        point_num = point_num + 1
        if (point_num == 1):
            print('Start at upper left corner. Select points clockwise.')
            calibration_pts = np.float32([[x + 0.0,y + 0.0]])
        elif (point_num <= 4):
            calibration_pts = np.append(calibration_pts, np.float32([[x + 0.0,y + 0.0]]),axis = 0)
        
        if (point_num == 4):
            # Apply Projection Transform
            # ref points [TOPLEFT, TOPRIGHT, BOTTOMRIGHT, BOTTOMLEFT]
            ref_pts = np.float32([[image_processor_global.x_offset,0], \
                [image_processor_global.x_width + image_processor_global.x_offset,0], \
                [image_processor_global.x_width + image_processor_global.x_offset, image_processor_global.y_height], \
                [image_processor_global.x_offset, image_processor_global.y_height]])

            image_processor_global.projection_dim = (image_processor_global.x_width + image_processor_global.x_offset * 2, image_processor_global.y_height)
            image_processor_global.projection_transform = cv2.getPerspectiveTransform(calibration_pts, ref_pts) 
            image_calibrated = True
            cv2.destroyWindow("Calibrate Image Transform")
        display_val ='Pt{}: x:{} y:{}'.format(point_num, x, y)
        print(display_val)
def print_point_callback ( event , x , y , flags , param ) : global point_num global image_calibrated global calibration_pts global transformation global image_processor_global if event == cv2 . EVENT_LBUTTONDOWN : point_num = point_num + 1 if ( point_num == 1 ) : print ( 'Start at upper left corner. Select points clockwise.' ) calibration_pts = np . float32 ( [ [ x + 0.0 , y + 0.0 ] ] ) elif ( point_num <= 4 ) : calibration_pts = np . append ( calibration_pts , np . float32 ( [ [ x + 0.0 , y + 0.0 ] ] ) , axis = 0 ) if ( point_num == 4 ) : # Apply Projection Transform # ref points [TOPLEFT, TOPRIGHT, BOTTOMRIGHT, BOTTOMLEFT] ref_pts = np . float32 ( [ [ image_processor_global . x_offset , 0 ] , [ image_processor_global . x_width + image_processor_global . x_offset , 0 ] , [ image_processor_global . x_width + image_processor_global . x_offset , image_processor_global . y_height ] , [ image_processor_global . x_offset , image_processor_global . y_height ] ] ) image_processor_global . projection_dim = ( image_processor_global . x_width + image_processor_global . x_offset * 2 , image_processor_global . y_height ) image_processor_global . projection_transform = cv2 . getPerspectiveTransform ( calibration_pts , ref_pts ) image_calibrated = True cv2 . destroyWindow ( "Calibrate Image Transform" ) display_val = 'Pt{}: x:{} y:{}' . format ( point_num , x , y ) print ( display_val )