drone-rigide/doc/compte_rendu/scripts/test_find_targets.py
2019-06-07 15:29:39 +02:00

32 lines
776 B
Python

import matplotlib.pyplot as pl
from matplotlib.patches import Rectangle
from find_targets import find_targets, normalize_coordinates
ax = pl.subplot(211)
img = pl.imread('image.jpeg')
H, L, R, objects = find_targets(img, return_slices=True)
for o in objects:
x, y = o
r = Rectangle((y.start, x.start), y.stop-y.start, x.stop-x.start, linewidth=1,edgecolor='r',facecolor='none')
ax.add_patch(r)
ax.imshow(img)
ax.plot([H[0], L[0], R[0]], [H[1], L[1], R[1]], 'o', color='red')
ax = pl.subplot(212)
w = len(img[0])
h = len(img)
H = normalize_coordinates(H, w, h)
L = normalize_coordinates(L, w, h)
R = normalize_coordinates(R, w, h)
ax.plot([H[0], L[0], R[0]], [H[1], L[1], R[1]], 'o', color='red')
ax.grid()
ax.set_title("Positions normalisées")
pl.show()