def find_board_corners(board_directories): """Returns an array of chessboard corners in an image from each distance of 50cm, 100cm and 450cm in that order.""" print "Finding board corners..." flags = cv2.CALIB_CB_ADAPTIVE_THRESH pattern_size = (7,5) image_coords = [] corner_images = [] for directory in board_directories: img_name = 'cam1_frame_1.bmp' print "Finding corners in", os.path.join(directory, img_name) #board_image = cv2.imread(os.path.join(directory, img_name), cv2.CV_LOAD_IMAGE_COLOR) board_image = cv2.imread(os.path.join(directory, img_name),0) (pattern_was_found, corners) = cv2.findChessboardCorners(board_image, pattern_size, flags=flags) if pattern_was_found: cv2.cornerSubPix(board_image, corners, (4, 4), (-1, -1), (cv2.TERM_CRITERIA_EPS | cv2.TERM_CRITERIA_COUNT, 100, 1e-7)) if not pattern_was_found and corners == None: try: corners = np.loadtxt(os.path.join(directory, 'cam1_frame_1_corners.txt'),delimiter=',') pattern_was_found = True corners = corners.astype('float32') except IndexError: print 'No corners found! Please find them yourself in Photoshop' sys.exit(-1) if not pattern_was_found and not corners==None: print "Not all corners found! Find them yourself!" corners = CornerPicker.main(board_image.copy(), corners) corner_image = board_image.copy() corners = corners.squeeze() cv2.drawChessboardCorners(corner_image, pattern_size, corners, pattern_was_found) image_coords.append(corners) corner_images.append(corner_image) return np.concatenate(image_coords), corner_images
def find_circle_centers(board_directories): """Returns an array of chessboard corners in an image from each distance of 50cm, 100cm and 450cm in that order.""" print "Finding board corners..." pattern_size = (4,11) image_coords = [] corner_images = [] for directory in board_directories: img_name = 'cam1_frame_1.bmp' print "Finding circles in", os.path.join(directory, img_name) board_image = cv2.imread(os.path.join(directory, img_name),1) # CHANGED: Loading as RGB [pattern_was_found,corners] = cv2.findCirclesGridDefault(board_image,pattern_size,flags=cv2.CALIB_CB_ASYMMETRIC_GRID) corners = corners.squeeze() # CHANGED: moved squeeze to before corner checking instead of after if not pattern_was_found and corners == None: try: corners = np.loadtxt(os.path.join(directory, 'cam1_frame_1_corners.txt'),delimiter=',') pattern_was_found = True corners = corners.astype('float32') except IndexError: print 'No corners found! Please find them yourself in Photoshop' sys.exit(-1) if not pattern_was_found and not corners==None: print "Not all corners found! Find them yourself!" corners = CornerPicker.main(board_image.copy(), corners, pattern_size) corner_image = board_image.copy() cv2.drawChessboardCorners(corner_image, pattern_size, corners, pattern_was_found) cv2.imwrite('./tmp.png',corner_image) image_coords.append(corners) corner_images.append(corner_image) return np.concatenate(image_coords), corner_images