Created
August 20, 2021 13:38
-
-
Save alex-luxonis/464c6cc1611ea4adc64f56ac89cd15ae to your computer and use it in GitHub Desktop.
Draw horizontal epipolar lines - rectification check
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sys | |
import cv2 | |
import numpy as np | |
if len(sys.argv) < 3: | |
raise RuntimeError('Please provide left and right image files as params') | |
print('Use left-click, `w` and `s` to move line drawn') | |
img1 = cv2.imread(sys.argv[1]) | |
img2 = cv2.imread(sys.argv[2]) | |
stacked = np.concatenate((img1, img2), axis=1) | |
def draw_line(img, row, color): | |
cv2.line(img, (0, row), (img.shape[1], row), color, 1) | |
if 1: # Draw epipolar lines every N rows | |
line_row = 0 | |
while line_row < stacked.shape[0]: | |
draw_line(stacked, line_row, (255, 0, 0)) | |
line_row += 30 | |
fname = 'out.png' | |
cv2.imwrite(fname, stacked) | |
print('Stacked frame saved to:', fname) | |
current_row = -1 | |
window = 'stacked' | |
cv2.namedWindow(window) | |
cv2.imshow(window, stacked) | |
def click(event, x, y, flags, param): | |
if event == cv2.EVENT_LBUTTONDOWN: | |
# print('Clicked:', x, y) | |
global current_row | |
current_row = y | |
cv2.setMouseCallback(window, click) | |
prev_row = current_row | |
while True: | |
if prev_row != current_row: | |
# print('Draw on line:', current_row) | |
prev_row = current_row | |
img = stacked.copy() | |
draw_line(img, current_row, (0, 255, 0)) | |
cv2.imshow(window, img) | |
key = cv2.waitKey(10) | |
if key == ord('q'): | |
break | |
elif key == ord('w'): | |
current_row -= 1 | |
elif key == ord('s'): | |
current_row += 1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment