feat: statistics
This commit is contained in:
64
main.py
64
main.py
@@ -31,11 +31,39 @@ def main():
|
||||
# make_global_photo('map.jpg')
|
||||
|
||||
# Получаем траекторию от пользователя
|
||||
points = get_trajectory_points('map.jpg')
|
||||
# points = [np.float64(0.5443937502226799), np.float64(0.4030424838774785)], [np.float64(0.18517133490120316), np.float64(0.4586935604608052)], [np.float64(0.1641887171838272), np.float64(0.5586383510594329)], [np.float64(0.587198290366127),
|
||||
# np.float64(0.5699957136274587)]
|
||||
# points = [[np.float64(0.5028362002950056), np.float64(0.508463417020251)], [np.float64(0.5079239482442035), np.float64(0.508463417020251)], [np.float64(0.5045321162780716), np.float64(0.5210964284169014)], [np.float64(0.509054558899581), np.float64(0.5200436774671806)]]
|
||||
# print(points)
|
||||
# points = get_trajectory_points('map.jpg')
|
||||
|
||||
# Trajectory #1
|
||||
points = [[np.float64(0.5384504359393909), np.float64(0.4084520767967683)], [np.float64(0.4451750568707629), np.float64(0.38213330305374654)], [np.float64(0.49266070439660997), np.float64(0.2789637099811013)], [np.float64(0.36377108968359656), np.float64(0.3263375027185404)], [np.float64(0.3535955937852008), np.float64(0.4337180995900692)]]
|
||||
|
||||
# Trajectory #2
|
||||
# points = [[np.float64(0.29197731306713737), np.float64(0.3452870198135161)], [np.float64(0.33494051797147517), np.float64(0.2010601397017569)], [np.float64(0.39768940934491587), np.float64(0.25369768718780034)], [np.float64(0.4027771572941138), np.float64(0.4158213334448144)], [np.float64(0.2914120077394487), np.float64(0.5547844588079692)]]
|
||||
|
||||
# Trajectory #3
|
||||
# points = [[np.float64(0.2755834585641664), np.float64(0.45687862048392835)], [np.float64(0.295934450360958), np.float64(0.5021469113219258)], [np.float64(0.32872215936689997), np.float64(0.4810918923275084)], [np.float64(0.3649017003389739), np.float64(0.5295184360146684)], [np.float64(0.3999506306556705), np.float64(0.49477765467387963)]]
|
||||
|
||||
# Trajectory #4
|
||||
# points = [[np.float64(0.42143223310783934), np.float64(0.6663760594783815)], [np.float64(0.4253893704016599), np.float64(0.5537317078582484)], [np.float64(0.5124463908657128), np.float64(0.5621537154560153)], [np.float64(0.5124463908657128), np.float64(0.6684815613778233)], [np.float64(0.42143223310783934), np.float64(0.6663760594783815)]]
|
||||
|
||||
# Trajectory #5
|
||||
# points = [[np.float64(0.5983728006743884), np.float64(0.7348048712102382)], [np.float64(0.5966768846913225), np.float64(0.5453097002604814)], [np.float64(0.6345523416464622), np.float64(0.7190136069644251)], [np.float64(0.6402053949233488), np.float64(0.5495207040593649)], [np.float64(0.5983728006743884), np.float64(0.7348048712102382)]]
|
||||
|
||||
# Trajectory #6
|
||||
# points = [[np.float64(0.4406526142492536), np.float64(0.28106921188054296)], [np.float64(0.38581799746345413), np.float64(0.2968604761263561)], [np.float64(0.3931669667234066), np.float64(0.353709027411283)], [np.float64(0.4248240650739713), np.float64(0.35265627646156217)], [np.float64(0.40616898926024564), np.float64(0.3179154951207735)]]
|
||||
|
||||
# Trajectory #7
|
||||
# points = [[np.float64(0.5491912371654754), np.float64(0.7505961354560512)], [np.float64(0.5537136797869846), np.float64(0.6863783275230781)], [np.float64(0.5017055896396284), np.float64(0.6653233085286606)], [np.float64(0.5520177638039186), np.float64(0.6042637534448503)], [np.float64(0.5593667330638712), np.float64(0.516885424618018)]]
|
||||
|
||||
# Trajectory #8
|
||||
# points =
|
||||
|
||||
# Trajectory #9
|
||||
# points =
|
||||
|
||||
# Trajectory #10
|
||||
# points =
|
||||
|
||||
print(points)
|
||||
|
||||
# Для каждой точки сделаем приближенный снимок
|
||||
yandexMap = YandexMap()
|
||||
@@ -102,6 +130,12 @@ def main():
|
||||
|
||||
zoom_next_event = random.randint(5, 10)
|
||||
|
||||
errors = []
|
||||
chunk_errors = []
|
||||
chunk_improves = []
|
||||
|
||||
last_chunk_index = 0
|
||||
|
||||
for i in range(10000000000):
|
||||
print(f"Image #{i}")
|
||||
if i == zoom_next_event:
|
||||
@@ -121,14 +155,20 @@ def main():
|
||||
vis_manager.update_display()
|
||||
vis_manager.pause(0.2)
|
||||
|
||||
if command.stop:
|
||||
break
|
||||
|
||||
vis_manager.set_target_index(pilot.target_idx)
|
||||
vis_manager.update_drone_trajectory(pilot.geo.x, pilot.geo.y)
|
||||
vis_manager.update_global_map(simulator.geo.x, simulator.geo.y)
|
||||
vis_manager.update_error_plot(i, pilot.geo.x, pilot.geo.y, simulator.geo.x, simulator.geo.y)
|
||||
|
||||
errors.append(np.hypot(pilot.geo.x - simulator.geo.x, pilot.geo.y - simulator.geo.y))
|
||||
if last_chunk_index != pilot.target_idx:
|
||||
last_chunk_index = pilot.target_idx
|
||||
chunk_errors.append(errors[-1])
|
||||
chunk_improves.append(errors[-1] - errors[max(len(errors) - 2, 0)])
|
||||
|
||||
if command.stop:
|
||||
break
|
||||
|
||||
simulator.handle(command.dangle, command.velocity)
|
||||
|
||||
vis_manager.update_display()
|
||||
@@ -137,7 +177,13 @@ def main():
|
||||
last_proc_times = proc_time[-10:]
|
||||
print("Average FPS:", 1 / last_proc_times.mean())
|
||||
|
||||
print("Errors:", errors)
|
||||
print("MSE:", (np.array(errors) ** 2).mean())
|
||||
print("RMSE:", (np.array(errors) ** 2).mean() ** 0.5)
|
||||
print("Chunk errors:", chunk_errors)
|
||||
print("Chunk error improves:", chunk_improves)
|
||||
print("Average FPS:", 1 / proc_time.mean())
|
||||
vis_manager.show_final()
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
main()
|
||||
|
||||
@@ -6,7 +6,7 @@ from pathlib import Path
|
||||
from typing import Literal, Optional, Tuple
|
||||
from PIL import Image
|
||||
|
||||
FeatureMethod = Literal["orb", "sift", "surf"]
|
||||
FeatureMethod = Literal["orb", "sift", "surf", "akaze", "brisk"]
|
||||
|
||||
@dataclass
|
||||
class VisionChunk:
|
||||
@@ -33,6 +33,36 @@ class VisionChunk:
|
||||
patchSize=31,
|
||||
fastThreshold=20,
|
||||
)
|
||||
elif self.feature_method == "sift":
|
||||
self._detector = cv2.SIFT_create(
|
||||
nfeatures=1000,
|
||||
nOctaveLayers=3,
|
||||
contrastThreshold=0.04,
|
||||
edgeThreshold=10,
|
||||
sigma=1.6
|
||||
)
|
||||
elif self.feature_method == "surf":
|
||||
self._detector = cv2.xfeatures2d.SURF_create(
|
||||
hessianThreshold=400.0,
|
||||
nOctaveLayers=3,
|
||||
# nOctaveLayers=4,
|
||||
upright=False
|
||||
)
|
||||
elif self.feature_method == "akaze":
|
||||
self._detector = cv2.AKAZE_create(
|
||||
descriptor_type=cv2.AKAZE_DESCRIPTOR_MLDB,
|
||||
descriptor_size=0,
|
||||
descriptor_channels=3,
|
||||
threshold=0.001,
|
||||
nOctaves=4,
|
||||
diffusivity=cv2.KAZE_DIFF_PM_G2
|
||||
)
|
||||
elif self.feature_method == "brisk":
|
||||
self._detector = cv2.BRISK_create(
|
||||
thresh=30,
|
||||
octaves=3,
|
||||
patternScale=1.0
|
||||
)
|
||||
else:
|
||||
raise ValueError(f"Unsupported feature method: {self.feature_method}")
|
||||
return self._detector
|
||||
@@ -40,6 +70,14 @@ class VisionChunk:
|
||||
def _get_matcher(self) -> cv2.DescriptorMatcher:
|
||||
if self._matcher is None:
|
||||
self._matcher = cv2.BFMatcher(cv2.NORM_HAMMING, crossCheck=False)
|
||||
return self._matcher
|
||||
if self.feature_method == 'orb':
|
||||
self._matcher = cv2.BFMatcher(cv2.NORM_HAMMING, crossCheck=False)
|
||||
elif self.feature_method == 'sift':
|
||||
FLANN_INDEX_LSH = 6
|
||||
index_params = dict(algorithm=FLANN_INDEX_LSH, table_number=6, key_size=12, multi_probe_level=1)
|
||||
search_params = dict(checks=50)
|
||||
self._matcher = cv2.FlannBasedMatcher(index_params, search_params)
|
||||
return self._matcher
|
||||
|
||||
def _preprocess(self, img_np: np.ndarray) -> np.ndarray:
|
||||
|
||||
Reference in New Issue
Block a user