def find_chessboard_corners(greyscale_image, neighborhood_size=10, candidate_threshold=.5):
candidates = find_candidates(greyscale_image, neighborhood_size, candidate_threshold)
bordered_image = cv2.copyMakeBorder(greyscale_image, neighborhood_size, neighborhood_size, neighborhood_size,
neighborhood_size, cv2.BORDER_CONSTANT, value=0)
detected_corners = []
windows = []
grad_mags = []
templates = []
ix_candidate = 0
for candidate in candidates:
print(ix_candidate)
coord = candidate
window = greyscale_image[coord[0] - neighborhood_size:coord[0] + neighborhood_size + 1,
coord[1] - neighborhood_size:coord[1] + neighborhood_size + 1]
hist, grad_mag = __filter_candidate(bordered_image, candidate, neighborhood_size)
win_b = cv2.copyMakeBorder(window, 5, 5, 5, 5, cv2.BORDER_CONSTANT, value=0)
windows.append(win_b)
grad_mags.append(prep_img_save(grad_mag))
angles = __find_dominant_directions(hist)
if angles is not None:
template = __build_corner_template(neighborhood_size * 2 + 1, angles)
templates.append(prep_img_save(template))
else:
templates.append(np.zeros_like(win_b))
ix_candidate += 1
# if __filter_candidate(bordered_image, candidate, neighborhood_size):
# detected_corners.append(candidate)
ch_test = np.vstack((np.hstack(windows), np.hstack(grad_mags), np.hstack(templates)))
cv2.imwrite("~/Desktop/TMP/ch_test01.png", ch_test)
detected_corners = np.array(detected_corners)
# return detected_corners
return candidates
评论列表
文章目录