diff --git a/PAR 152/Yolo V3/TensorFlow-2.x-YOLOv3-master/Calibration_cam/0.5_detect.jpg b/PAR 152/Yolo V3/TensorFlow-2.x-YOLOv3-master/Calibration_cam/0.5_detect.jpg index 3b2f09ab135d9b1029dc1fb1a6fdbe3e40c5a5f9..5be80f575311b7c6a9a2b3d4e6fcda4b290fd54e 100644 Binary files a/PAR 152/Yolo V3/TensorFlow-2.x-YOLOv3-master/Calibration_cam/0.5_detect.jpg and b/PAR 152/Yolo V3/TensorFlow-2.x-YOLOv3-master/Calibration_cam/0.5_detect.jpg differ diff --git a/PAR 152/Yolo V3/TensorFlow-2.x-YOLOv3-master/Calibration_cam/out.jpg b/PAR 152/Yolo V3/TensorFlow-2.x-YOLOv3-master/Calibration_cam/out.jpg new file mode 100644 index 0000000000000000000000000000000000000000..3b2f09ab135d9b1029dc1fb1a6fdbe3e40c5a5f9 Binary files /dev/null and b/PAR 152/Yolo V3/TensorFlow-2.x-YOLOv3-master/Calibration_cam/out.jpg differ diff --git a/PAR 152/Yolo V3/TensorFlow-2.x-YOLOv3-master/MCL.py b/PAR 152/Yolo V3/TensorFlow-2.x-YOLOv3-master/MCL.py index ee5961f9bd32efd43fdd74c993594a22eef03cbb..9662f29d2c6c849d9370bceb6ac7d00c0b5b527e 100644 --- a/PAR 152/Yolo V3/TensorFlow-2.x-YOLOv3-master/MCL.py +++ b/PAR 152/Yolo V3/TensorFlow-2.x-YOLOv3-master/MCL.py @@ -4,7 +4,9 @@ #import tensorflow as tf #from yolov3.utils import detect_image, detect_realtime, detect_video, Load_Yolo_model, detect_video_realtime_mp #from yolov3.configs import * -#import matplotlib.pyplot as plt +import matplotlib.pyplot as plt +#from mpl_toolkits.mplot3d import axes3d +#from matplotlib import cm import numpy as np import random as rd @@ -26,8 +28,8 @@ coord_ext = [(i/diametre , j/diametre) for i,j in zip(pixel_x_ext, pixel_y_ext)] coord_int = [(i/diametre , j/diametre) for i,j in zip(pixel_x_int, pixel_y_int)] ### Paramètres ### -sigma_position = 0.1 -sigma_direction = 30*3.1415/180 +sigma_position = 0.02 +sigma_direction = 15*3.1415/180 seuil_cone = 0.6 @@ -35,9 +37,9 @@ dep_x, dep_y, dep_theta = 1.314, 1.162, 3.14/3.6 nb_particule = 30 pos = [[dep_x, dep_y, dep_theta] for i in range(nb_particule)] -F = 3951 #Focale camera -h_reel = 0.24 #Hauteur d'un plot -y_0 = 2000 #Milieu de l'image +F = 3951/3 #Focale camera +h_reel = 0.27 #Hauteur d'un plot +y_0 = 1500 #Milieu de l'image dist_roue = 0.25 #Distance entre les roues avant et les roues arrieres @@ -136,6 +138,7 @@ def sensor_update(observation, position): vision_x.append((pt[0]-x)*cos(theta) + (pt[1]-y)*sin(theta)) vision_y.append(-(pt[0]-x)*sin(theta) + (pt[1]-y)*cos(theta)) + for pt in coord_ext: vision_x_ext.append((pt[0]-x)*cos(theta) + (pt[1]-y)*sin(theta)) vision_y_ext.append(-(pt[0]-x)*sin(theta) + (pt[1]-y)*cos(theta)) @@ -143,22 +146,25 @@ def sensor_update(observation, position): cones_vu_x = [] cones_vu_y = [] for i in range(len(vision_x)): - if vision_x[i]>0 and abs(vision_y[i])<vision_x[i]: + if vision_x[i]>0 and abs(vision_y[i])<0.67*vision_x[i]: cones_vu_x.append(vision_x[i]) cones_vu_y.append(vision_y[i]) for i in range(len(vision_x_ext)): - if vision_x_ext[i]>0 and abs(vision_y_ext[i])<vision_x_ext[i]: + if vision_x_ext[i]>0 and abs(vision_y_ext[i])<0.67*vision_x_ext[i]: cones_vu_x.append(vision_x_ext[i]) cones_vu_y.append(vision_y_ext[i]) - - obs_x = [] - obs_y = [] - for i in observation: - obs_x.append(i[0]) - obs_y.append(i[1]) - - return 1/distance_Chamfer(cones_vu_x, cones_vu_y, obs_x, obs_y) + + if len(cones_vu_x) == 0: + return 0 + else: + obs_x = [] + obs_y = [] + for i in observation: + obs_x.append(i[0]) + obs_y.append(i[1]) + + return 1/distance_Chamfer(cones_vu_x, cones_vu_y, obs_x, obs_y)**4 @@ -234,7 +240,106 @@ def get_position(boxes,commande,pos): return pos_calc, pos, cone_x, cone_y +if __name__ == "__main__": + # detection = [[2.18939087e+03, 1.48177417e+03, 2.86449023e+03, 2.54427783e+03, 9.66490030e-01, 0.00000000e+00], + # [4.22634644e+02, 1.44312561e+03, 1.08822302e+03, 2.31131567e+03, 9.36378121e-01, 0.00000000e+00], + # [1.33116504e+03, 1.42764783e+03, 1.70783643e+03, 1.98202075e+03, 9.03878212e-01, 0.00000000e+00], + # [2.11831836e+03, 1.41914294e+03, 2.43602563e+03, 1.87002930e+03, 9.03337121e-01, 0.00000000e+00], + # [2.24867358e+03, 1.59305701e+03, 2.99900000e+03, 3.76038647e+03, 8.82729828e-01, 0.00000000e+00], + # [2.64460254e+03, 1.44378406e+03, 2.91649780e+03, 2.14795459e+03, 3.62023830e-01, 0.00000000e+00]] + + # detection = [[0.00000000e+00, 1.85167456e+03, 9.15495361e+02, 3.25824146e+03, 9.37295914e-01, 0.00000000e+00], + # [2.41986987e+03, 1.86332446e+03, 2.86713550e+03, 2.42170972e+03, 9.23870742e-01, 0.00000000e+00], + # [1.36284387e+03, 1.83517468e+03, 1.92408057e+03, 2.59739648e+03, 9.17667687e-01, 0.00000000e+00]] + + detection = [[1.28486133e+03, 1.79538904e+03, 1.78743445e+03, 2.45994067e+03, 9.39055085e-01, 0.00000000e+00], + [0.00000000e+00, 1.87250220e+03, 7.69682068e+02, 3.12636377e+03, 9.35593545e-01, 0.00000000e+00], + [2.12719995e+03, 1.72824695e+03, 2.48698218e+03, 2.24433813e+03, 9.07173812e-01, 0.00000000e+00], + [2.72219897e+03, 2.18795605e+03, 2.99900000e+03, 3.47306348e+03, 3.55658233e-01, 0.00000000e+00]] + + # detection = [[1.12150806e+03, 1.82397412e+03, 1.71230017e+03, 2.59400610e+03, 9.47640836e-01, 0.00000000e+00], + # [2.17284106e+03, 1.79985144e+03, 2.59600366e+03, 2.34515747e+03, 9.44890141e-01, 0.00000000e+00], + # [2.78233301e+03, 1.75100500e+03, 2.99900000e+03, 2.26862329e+03, 9.10233915e-01, 0.00000000e+00], + # [0.00000000e+00, 1.92825171e+03, 5.37962524e+02, 3.36087646e+03, 8.53242218e-01, 0.00000000e+00], + # [2.80115698e+03, 3.22995215e+03, 2.99900000e+03, 3.76810620e+03, 3.35420161e-01, 0.00000000e+00], + # [6.21354027e+01, 1.80441516e+03, 3.51005554e+02, 2.08294287e+03, 3.16491544e-01, 0.00000000e+00]] + + z_t = [] + liste_x = [] + liste_y = [] + nb_particle = 100 + pos = [(2.5*rd.random(), 1.6*rd.random(), 2*3.14*rd.random()) for i in range(nb_particle)] + #pos = [(1.5, 1.180, 3.14/3) for i in range(nb_particle)] + + for i in detection: + if i[4] >= seuil_cone: + x,y = boite2coord(i[0],i[1],i[2],i[3]) + liste_x.append(x*2/3) + liste_y.append(y*2/3) + + for i in range(len(liste_x)): + z_t.append((liste_x[i], liste_y[i])) + + + # x = np.linspace(0,2.5,100) + # y = np.linspace(0,1.6,100) + # X, Y = np.meshgrid(x,y) + # Z = np.zeros((100,100)) + # for i in range(100): + # for j in range(100): + # Z[i,j] = sensor_update(z_t, (X[i,j],Y[i,j], 3.14/3)) + + # fig, ax = plt.subplots(subplot_kw={"projection": "3d"}) + # surf = ax.plot_surface(X, Y, Z, cmap=cm.coolwarm, + # linewidth=0, antialiased=False) + + plt.ion() + fig = plt.figure() + ax = fig.add_subplot(111) + exterieur = ax.plot(coord_x_ext, coord_y_ext,'+') + interieur = ax.plot(coord_x_int, coord_y_int,'+') + + + pos_x = [elt[0] for elt in pos] + pos_y = [elt[1] for elt in pos] + line1, = ax.plot(pos_x, pos_y, '.') + line2, = ax.plot(0,0,'o') + line3, = ax.plot(0,0,'o') + + for i in range(100): + + + pos, W = particle_filter(pos, (0,0,1), z_t) + #W = [0.01 for i in range(100)] + + pos_x = [0.0 for i in range(nb_particle)] + pos_y = [0.0 for i in range(nb_particle)] + pos_moy_x, pos_moy_y, pos_moy_theta = 0,0,0 + cone_x, cone_y = [], [] + + for i in range(nb_particle): + pos_x[i] = pos[i][0] + pos_y[i] = pos[i][1] + pos_moy_x += W[i]*pos[i][0] + pos_moy_y += W[i]*pos[i][1] + pos_moy_theta += W[i]*pos[i][2] + + for i in range(len(liste_x)): + x,y = rotation((liste_x[i] ,liste_y[i]), (0,0), pos_moy_theta) + cone_x.append(x+pos_moy_x) + cone_y.append(y+pos_moy_y) + + line1.set_xdata(pos_x) + line1.set_ydata(pos_y) + line2.set_xdata(pos_moy_x) + line2.set_ydata(pos_moy_y) + line3.set_xdata(cone_x) + line3.set_ydata(cone_y) + + fig.canvas.draw() + + plt.pause(0.1) ''' if __name__ == "__main__": # pos = [(1.314, 1.162, 3.14/3.6) for i in range(10)] diff --git a/PAR 152/Yolo V3/TensorFlow-2.x-YOLOv3-master/__pycache__/MCL.cpython-38.pyc b/PAR 152/Yolo V3/TensorFlow-2.x-YOLOv3-master/__pycache__/MCL.cpython-38.pyc index 3e9abd002e9cc0c5fc737a5ac50d3617e1d791de..143a98a285fc8e618c677c725b1ffde81f4d5358 100644 Binary files a/PAR 152/Yolo V3/TensorFlow-2.x-YOLOv3-master/__pycache__/MCL.cpython-38.pyc and b/PAR 152/Yolo V3/TensorFlow-2.x-YOLOv3-master/__pycache__/MCL.cpython-38.pyc differ diff --git a/PAR 152/Yolo V3/TensorFlow-2.x-YOLOv3-master/calibration.py b/PAR 152/Yolo V3/TensorFlow-2.x-YOLOv3-master/calibration.py new file mode 100644 index 0000000000000000000000000000000000000000..bb816ef09810d906c95ea7628edc4b0e91ec79b6 --- /dev/null +++ b/PAR 152/Yolo V3/TensorFlow-2.x-YOLOv3-master/calibration.py @@ -0,0 +1,36 @@ +# -*- coding: utf-8 -*- +""" +Created on Mon Mar 6 08:43:27 2023 + +@author: paull +""" + +import os +os.environ['CUDA_VISIBLE_DEVICES'] = '0' +import cv2 +import numpy as np +import tensorflow as tf +from yolov3.utils import detect_image, detect_realtime, detect_video, Load_Yolo_model, detect_video_realtime_mp +from yolov3.configs import * + +image_path = "./Calibration_cam/" #".jpg" +video_path = "./IMAGES/test.mp4" + +yolo = Load_Yolo_model() + +distances = [0.5, 1, 2] +h_pixel = [] +F = 0 +h_cone = 0.27 + +for dist in distances: + path = image_path + str(dist) + "m.jpg" + + print(path) + + _, boxes = detect_image(yolo, path, "./Calibration_cam/out.jpg", input_size=YOLO_INPUT_SIZE, show=False, CLASSES=TRAIN_CLASSES, rectangle_colors=(255,0,0)) + + h_pixel.append(abs(boxes[0][1] - boxes[0][3])) + F += abs(boxes[0][1] - boxes[0][3])*dist/h_cone + +print(F/len(distances)) \ No newline at end of file diff --git a/PAR 152/Yolo V3/TensorFlow-2.x-YOLOv3-master/detection_custom.py b/PAR 152/Yolo V3/TensorFlow-2.x-YOLOv3-master/detection_custom.py index 85cb50e7f38a5f4520422f199e900e484fa09459..c74a967a33cfbf7bf761f0574870f2ed44ab2871 100644 --- a/PAR 152/Yolo V3/TensorFlow-2.x-YOLOv3-master/detection_custom.py +++ b/PAR 152/Yolo V3/TensorFlow-2.x-YOLOv3-master/detection_custom.py @@ -16,14 +16,14 @@ import tensorflow as tf from yolov3.utils import detect_image, detect_realtime, detect_video, Load_Yolo_model, detect_video_realtime_mp from yolov3.configs import * -image_path = "./Calibration_cam/2m.jpg" +image_path = "./Calibration_cam/0.5m.jpg" video_path = "./IMAGES/test.mp4" yolo = Load_Yolo_model() -#_, boxes = detect_image(yolo, image_path, "./Calibration_cam/0.5_detect.jpg", input_size=YOLO_INPUT_SIZE, show=True, CLASSES=TRAIN_CLASSES, rectangle_colors=(255,0,0)) +_, boxes = detect_image(yolo, image_path, "./images test/test2_pred.jpg", input_size=YOLO_INPUT_SIZE, show=True, CLASSES=TRAIN_CLASSES, rectangle_colors=(255,0,0)) #detect_video(yolo, video_path, './IMAGES/detected.mp4', input_size=YOLO_INPUT_SIZE, show=False, CLASSES=TRAIN_CLASSES, rectangle_colors=(255,0,0)) -detect_realtime(yolo, '', input_size=YOLO_INPUT_SIZE, show=True, CLASSES=TRAIN_CLASSES, rectangle_colors=(255, 0, 0)) +#detect_realtime(yolo, '', input_size=YOLO_INPUT_SIZE, show=True, CLASSES=TRAIN_CLASSES, rectangle_colors=(255, 0, 0)) #detect_video_realtime_mp(video_path, "Output.mp4", input_size=YOLO_INPUT_SIZE, show=True, CLASSES=TRAIN_CLASSES, rectangle_colors=(255,0,0), realtime=False) -print(boxes[0][3]-boxes[0][1]) \ No newline at end of file +print(boxes) \ No newline at end of file diff --git a/PAR 152/Yolo V3/TensorFlow-2.x-YOLOv3-master/images test/IMG_20230228_164314.jpg b/PAR 152/Yolo V3/TensorFlow-2.x-YOLOv3-master/images test/test.jpg similarity index 100% rename from PAR 152/Yolo V3/TensorFlow-2.x-YOLOv3-master/images test/IMG_20230228_164314.jpg rename to PAR 152/Yolo V3/TensorFlow-2.x-YOLOv3-master/images test/test.jpg diff --git a/PAR 152/Yolo V3/TensorFlow-2.x-YOLOv3-master/images test/IMG_20230228_164310.jpg b/PAR 152/Yolo V3/TensorFlow-2.x-YOLOv3-master/images test/test2.jpg similarity index 100% rename from PAR 152/Yolo V3/TensorFlow-2.x-YOLOv3-master/images test/IMG_20230228_164310.jpg rename to PAR 152/Yolo V3/TensorFlow-2.x-YOLOv3-master/images test/test2.jpg diff --git a/PAR 152/Yolo V3/TensorFlow-2.x-YOLOv3-master/images test/test2_pred.jpg b/PAR 152/Yolo V3/TensorFlow-2.x-YOLOv3-master/images test/test2_pred.jpg new file mode 100644 index 0000000000000000000000000000000000000000..52004145ecfc3fd10f5d3c196c1e0a43215ab5db Binary files /dev/null and b/PAR 152/Yolo V3/TensorFlow-2.x-YOLOv3-master/images test/test2_pred.jpg differ diff --git a/PAR 152/Yolo V3/TensorFlow-2.x-YOLOv3-master/images test/IMG_20230228_164321.jpg b/PAR 152/Yolo V3/TensorFlow-2.x-YOLOv3-master/images test/test3.jpg similarity index 100% rename from PAR 152/Yolo V3/TensorFlow-2.x-YOLOv3-master/images test/IMG_20230228_164321.jpg rename to PAR 152/Yolo V3/TensorFlow-2.x-YOLOv3-master/images test/test3.jpg diff --git a/PAR 152/Yolo V3/TensorFlow-2.x-YOLOv3-master/images test/IMG_20230228_164327.jpg b/PAR 152/Yolo V3/TensorFlow-2.x-YOLOv3-master/images test/test4.jpg similarity index 100% rename from PAR 152/Yolo V3/TensorFlow-2.x-YOLOv3-master/images test/IMG_20230228_164327.jpg rename to PAR 152/Yolo V3/TensorFlow-2.x-YOLOv3-master/images test/test4.jpg diff --git a/PAR 152/Yolo V3/TensorFlow-2.x-YOLOv3-master/images test/IMG_20230228_164332.jpg b/PAR 152/Yolo V3/TensorFlow-2.x-YOLOv3-master/images test/test5.jpg similarity index 100% rename from PAR 152/Yolo V3/TensorFlow-2.x-YOLOv3-master/images test/IMG_20230228_164332.jpg rename to PAR 152/Yolo V3/TensorFlow-2.x-YOLOv3-master/images test/test5.jpg diff --git a/PAR 152/Yolo V3/TensorFlow-2.x-YOLOv3-master/yolov3/__pycache__/utils.cpython-38.pyc b/PAR 152/Yolo V3/TensorFlow-2.x-YOLOv3-master/yolov3/__pycache__/utils.cpython-38.pyc index 24998a2546bac92ce81cd7aab30ab4b1fb254fc3..85d639dd599df3056aa50cd8831f9a516beeb23f 100644 Binary files a/PAR 152/Yolo V3/TensorFlow-2.x-YOLOv3-master/yolov3/__pycache__/utils.cpython-38.pyc and b/PAR 152/Yolo V3/TensorFlow-2.x-YOLOv3-master/yolov3/__pycache__/utils.cpython-38.pyc differ