def draw_colored_point_cloud_on_charuco_image_directory( input_image_directory, output_image_directory, charuco_board_settings_file, camera_matrix, dist_coeffs, model_point_cloud, color_descriptor_matrix): """ draw the colored point cloud on every image in a directory after determining pose and projecting the model points. :param input_image_directory: Image directory. :param output_image_directory: Image directory. :param charuco_board_settings_file: :param model_point_cloud: point cloud (float) using model coordinates. \ Columns correspond to x,y,z, and rows to points. :param color_descriptor_matrix: Columns correspond to b,g,r """ # get sorted frame numbers list of raw (unedited) image files frame_numbers_list = image_directory_handler.frame_number_list( input_image_directory) # loop through frames for frame_number in frame_numbers_list: # load image frame_image = image_directory_handler.load_frame( input_image_directory, frame_number) # draw colored point cloud on image frame_image = draw_colored_point_cloud_charuco( frame_image, charuco_board_settings_file, camera_matrix, dist_coeffs, model_point_cloud, color_descriptor_matrix) # write image image_directory_handler.write_frame(output_image_directory, frame_number, frame_image)
def get_selected_image(self): #raw_value = cv2.getTrackbarPos(self.tracker_name, self.window_name) #frame_number = self.get_closest_available_value(raw_value) frame_number = self.get_selected_frame() selected_image = image_directory_handler.load_frame( self.image_directory, frame_number) return selected_image
def draw_colored_point_cloud_on_image_directory(input_image_directory, output_image_directory, camera_matrix, dist_coeffs, rvecs_tvecs_frame_map, model_point_cloud, color_descriptor_matrix): """ draw the colored point cloud on every image in a directory after determining pose and projecting the model points. :param input_image_directory: Image directory. :param output_image_directory: Image directory. :param camera_matrix: :param dist_coeffs: :param rvecs_tvecs_frame_map: dictonary of frame number to rvecs, tvecs matrices or None :param model_point_cloud: point cloud (float) using model coordinates. \ Columns correspond to x,y,z, and rows to points. :param color_descriptor_matrix: Columns correspond to b,g,r """ # get sorted frame numbers list of raw (unedited) image files frame_numbers_list = image_directory_handler.frame_number_list( input_image_directory) # loop through frames for frame_number in frame_numbers_list: # load image frame_image = image_directory_handler.load_frame( input_image_directory, frame_number) # get corresponding transformation vectors rvec = rvecs_tvecs_frame_map[frame_number]['rvec'] tvec = rvecs_tvecs_frame_map[frame_number]['tvec'] if rvec is not None and tvec is not None: # draw colored point cloud on image frame_image = draw_colored_point_cloud(frame_image, camera_matrix, dist_coeffs, rvec, tvec, model_point_cloud, color_descriptor_matrix) # write image image_directory_handler.write_frame(output_image_directory, frame_number, frame_image)
def gui(image_directory, available_frames_list, rvec_tvec_frame_map, camera_matrix, dist_coeffs): # SETTINGS [NEW] M, N = 300, 400 window_one_start_frame = min(available_frames_list) window_one_name = "one" window_one_size = (N, M) window_one_position = (5, 5) window_one_chessboard_corners_image_points = [] window_one = selection_window(window_one_name, image_directory, available_frames_list, window_one_start_frame, window_one_size, window_one_position, window_one_chessboard_corners_image_points) window_one_image = window_one.get_selected_image() window_two_start_frame = max(available_frames_list) window_two_name = "two" window_two_size = window_one_size window_two_position = (window_one_position[0] + window_one_size[0], window_one_position[1]) window_two_chessboard_corners_image_points = [] window_two = selection_window(window_two_name, image_directory, available_frames_list, window_two_start_frame, window_two_size, window_two_position, window_two_chessboard_corners_image_points) window_two_image = window_two.get_selected_image() while True: cv2.imshow(window_one.window_name, window_one_image) cv2.imshow(window_two.window_name, window_two_image) # tmp*** print(window_one_chessboard_corners_image_points) global UPDATE_WINDOWS key = cv2.waitKey(1) if key == ord("u") or UPDATE_WINDOWS: UPDATE_WINDOWS = False window_one_frame = window_one.get_selected_frame() window_one_image = window_one.get_selected_image() window_one_chessboard_corners_image_points = window_one.get_chessboard_corners_image_points( ) window_two_frame = window_two.get_selected_frame() window_two_image = window_two.get_selected_image() window_two_chessboard_corners_image_points = window_two.get_chessboard_corners_image_points( ) window_one_image, window_two_image = draw_selected_points( image_directory, window_one_frame, window_one_chessboard_corners_image_points, window_two_frame, window_two_chessboard_corners_image_points, rvec_tvec_frame_map, camera_matrix, dist_coeffs) cv2.destroyAllWindows() window_one.deploy_window(window_one_frame, window_one_size, window_one_position) window_two.deploy_window(window_two_frame, window_two_size, window_two_position) if key == ord("r"): window_one_chessboard_corners_image_points = [] window_two_chessboard_corners_image_points = [] window_one_frame = window_one.get_selected_frame() window_one_image = image_directory_handler.load_frame( image_directory, window_one_frame) window_two_frame = window_two.get_selected_frame() window_two_image = image_directory_handler.load_frame( image_directory, window_two_frame) if key == ord("q"): cv2.destroyAllWindows() return """
def draw_selected_points(input_image_directory, frame1, points1, frame2, points2, rvec_tvec_frame_map, camera_matrix, dist_coeffs): """ # find c1 -> c2 rvec and tvec and c2 -> c1 rvec and tvec rvec1, tvec1 = rvec_tvec_frame_map[frame1]['rvec'], rvec_tvec_frame_map[frame1]['tvec'] rvec_inv1, tvec_inv1 = coordinate_transformations.inverse_rvec_and_tvec(rvec1, tvec1) rvec2, tvec2 = rvec_tvec_frame_map[frame2]['rvec'], rvec_tvec_frame_map[frame2]['tvec'] rvec_inv2, tvec_inv2 = coordinate_transformations.inverse_rvec_and_tvec(rvec2, tvec2) #rvec_1_to_2, tvec_1_to_2, jacobian = cv2.composeRT(rvec1, tvec1, rvec_inv2, tvec_inv2) #rvec_2_to_1, tvec_2_to_1, jacobian = cv2.composeRT(rvec2, tvec2, rvec_inv1, tvec_inv1) rt_1_to_2_bundel = cv2.composeRT(rvec2, tvec2, rvec_inv1, tvec_inv1) rvec_1_to_2, tvec_1_to_2 = rt_1_to_2_bundel[0], rt_1_to_2_bundel[1] # undistort not implimented c1_points = coordinate_transformations.image_points_to_camera_vectors(points1, camera_matrix, dist_coeffs) print(c1_points) # try building transformation matrix rmat_1_to_2 = cv2.Rodrigues(rvec_1_to_2)[0] print(rmat_1_to_2) h_rmat_1_to_2 = cv2.convertPointsToHomogeneous(rmat_1_to_2.T).T print(h_rmat_1_to_2) print("Batman") print(tvec_1_to_2) h_tvec_1_to_2 = cv2.convertPointsToHomogeneous(tvec_1_to_2.T) print(h_tvec_1_to_2.T) print("Trex") print(np.concatenate((h_rmat_1_to_2, h_tvec_1_to_2), axis=1)) # fundemental matrix #F, mask = cv2.findFundamentalMat(pts1, pts2, cv2.FM_LMEDS) # only inlier points # pts1 = pts1[mask.ravel() == 1] # pts2 = pts2[mask.ravel() == 1] # Find epilines corresponding to points in right image (second image) and # drawing its lines on left image #lines1 = cv2.computeCorrespondEpilines(pts2.reshape(-1,1,2), 2,F) #lines1 = lines1.reshape(-1,3) #img5,img6 = drawlines(img1,img2,lines1,pts1,pts2) """ # draw selected points on frame from given window B1 = np.array(points1) original_frame_1 = image_directory_handler.load_frame( input_image_directory, frame1) frame_1_copy = np.copy(original_frame_1) edited_image_1 = graphics.draw_point_matrix(B1, frame_1_copy, color=None, lineThickness=15) B2 = np.array(points2) original_frame_2 = image_directory_handler.load_frame( input_image_directory, frame2) frame_2_copy = np.copy(original_frame_2) edited_image_2 = graphics.draw_point_matrix(B2, frame_2_copy, color=None, lineThickness=15) return edited_image_1, edited_image_2