ref: create vision_chunk
This commit is contained in:
51
main.py
51
main.py
@@ -1,9 +1,11 @@
|
||||
from simulator import Simulator
|
||||
from visualization import VisualizationManager
|
||||
from trajectory_drawer import TrajectoryDrawer
|
||||
from yandex_map import YandexMap
|
||||
from time import sleep
|
||||
from pathlib import Path
|
||||
from simulator import Simulator
|
||||
from time import sleep
|
||||
from trajectory_drawer import TrajectoryDrawer
|
||||
from visualization import VisualizationManager
|
||||
from yandex_map import YandexMap
|
||||
from vision_chunk import VisionChunk
|
||||
from utility import cv2_to_pil
|
||||
import random
|
||||
|
||||
import cv2
|
||||
@@ -37,16 +39,18 @@ def main():
|
||||
|
||||
# Для каждой точки сделаем приближенный снимок
|
||||
yandexMap = YandexMap()
|
||||
keypoints: list[(any, any)] = []
|
||||
chunks: list[VisionChunk] = []
|
||||
|
||||
plt.ion()
|
||||
for i in range(len(points)):
|
||||
point = points[i]
|
||||
yandexMap.scroll(point[0], point[1], 5, True)
|
||||
sleep(1)
|
||||
img = yandexMap.make_screenshot(point[0], point[1], 0.2, 0.2)
|
||||
cv2_img = yandexMap.make_screenshot(point[0], point[1], 0.2, 0.2)
|
||||
img = cv2_to_pil(cv2_img)
|
||||
chunk = VisionChunk(img)
|
||||
Path('chunks').mkdir(exist_ok=True)
|
||||
cv2.imwrite(Path('.') / 'chunks' / f'chunk_{i}.png', img)
|
||||
chunk.save_image(Path('.') / 'chunks' / f'chunk_{i}.png')
|
||||
plt.subplot(1, len(points), i+1)
|
||||
plt.imshow(img)
|
||||
plt.pause(0.25)
|
||||
@@ -56,20 +60,9 @@ def main():
|
||||
|
||||
# Выделим на каждой картинке ключевые точки
|
||||
for i in range(len(points)):
|
||||
orb = cv2.ORB_create(
|
||||
nfeatures=1000,
|
||||
scaleFactor=1.2,
|
||||
nlevels=8,
|
||||
edgeThreshold=31,
|
||||
firstLevel=0,
|
||||
WTA_K=2,
|
||||
patchSize=31,
|
||||
fastThreshold=20
|
||||
)
|
||||
img = cv2.imread(Path('chunks') / f'chunk_{i}.png')
|
||||
kp: list[cv2.KeyPoint]
|
||||
kp, des = orb.detectAndCompute(img, None)
|
||||
keypoints.append((kp, des))
|
||||
chunk = VisionChunk.load_image(Path('chunks') / f'chunk_{i}.png')
|
||||
chunks.append(chunk)
|
||||
kp, des = chunk.compute_keypoints()
|
||||
|
||||
plt.subplot(1, len(points), i+1)
|
||||
kp_coords = np.array([j.pt for j in kp])
|
||||
@@ -93,12 +86,12 @@ def main():
|
||||
(p[0] - points[0][0]) * width, (points[0][1] - p[1]) * height
|
||||
], points)))
|
||||
points_coords *= 2 ** 4
|
||||
pilot = autopilot.AutoPilot(points_coords, keypoints, vis_manager)
|
||||
pilot = autopilot.AutoPilot(points_coords, chunks, vis_manager)
|
||||
simulator = Simulator(yandexMap)
|
||||
pilot.target_idx = 0
|
||||
|
||||
photo = simulator.get_photo()
|
||||
command = pilot.handle(photo)
|
||||
chunk = simulator.get_chunk()
|
||||
command = pilot.handle(chunk)
|
||||
|
||||
vis_manager.update_display()
|
||||
vis_manager.pause(1)
|
||||
@@ -117,13 +110,13 @@ def main():
|
||||
simulator.change_zoom(direction)
|
||||
zoom_next_event = i + random.randint(20, 40)
|
||||
|
||||
photo = simulator.get_photo()
|
||||
command = pilot.handle(photo)
|
||||
chunk = simulator.get_chunk()
|
||||
command = pilot.handle(chunk)
|
||||
|
||||
proc_time = np.append(proc_time, command.proccessing_time)
|
||||
|
||||
# Save Image
|
||||
photo.save(Path('images') / f"photo_{i}.png")
|
||||
chunk.save_image(Path('images') / f"photo_{i}.png")
|
||||
|
||||
vis_manager.update_display()
|
||||
vis_manager.pause(0.2)
|
||||
@@ -142,7 +135,7 @@ def main():
|
||||
vis_manager.pause(0.2)
|
||||
|
||||
last_proc_times = proc_time[-10:]
|
||||
# print("Average FPS:", 1 / last_proc_times.mean())
|
||||
print("Average FPS:", 1 / last_proc_times.mean())
|
||||
|
||||
vis_manager.show_final()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user