Spaces:
Running
Running
Update TheDistanceAssessor.py
Browse files- TheDistanceAssessor.py +11 -7
TheDistanceAssessor.py
CHANGED
@@ -836,7 +836,10 @@ def draw_classification(classification, id_map):
|
|
836 |
def get_result(classification, id_map, names, borders, image, regions):
|
837 |
image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
|
838 |
image = cv2.resize(image, (id_map.shape[1], id_map.shape[0]), interpolation = cv2.INTER_LINEAR)
|
839 |
-
|
|
|
|
|
|
|
840 |
plt.imshow(image, cmap='gray')
|
841 |
|
842 |
if classification:
|
@@ -863,8 +866,8 @@ def get_result(classification, id_map, names, borders, image, regions):
|
|
863 |
for line in side:
|
864 |
line = np.array(line)
|
865 |
plt.plot(line[:,1], line[:,0] ,'-', color='lightgrey', marker=None, linewidth=0.5)
|
866 |
-
plt.ylim(0, 1080)
|
867 |
-
plt.xlim(0, 1920)
|
868 |
plt.gca().invert_yaxis()
|
869 |
|
870 |
colors = ['yellow','orange','red']
|
@@ -874,10 +877,11 @@ def get_result(classification, id_map, names, borders, image, regions):
|
|
874 |
side = np.array(side)
|
875 |
if side.size > 0:
|
876 |
plt.plot(side[:,0],side[:,1] ,'-', color=colors[i], marker=None, linewidth=0.6) #color=colors[i]
|
877 |
-
plt.ylim(0, 1080)
|
878 |
-
plt.xlim(0, 1920)
|
879 |
plt.gca().invert_yaxis()
|
880 |
-
|
|
|
881 |
plt.tight_layout()
|
882 |
canvas = FigureCanvas(fig)
|
883 |
canvas.draw()
|
@@ -904,7 +908,7 @@ def run(input_image, model_seg, model_det, image_size, target_distances, num_ys
|
|
904 |
classification = classify_detections(boxes_moving, boxes_stationary, borders, image.shape, output_dims=segmentation_mask.shape)
|
905 |
|
906 |
output_image = get_result(classification, id_map, model.names, borders, image, regions)
|
907 |
-
|
908 |
return output_image
|
909 |
|
910 |
if __name__ == "__main__":
|
|
|
836 |
def get_result(classification, id_map, names, borders, image, regions):
|
837 |
image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
|
838 |
image = cv2.resize(image, (id_map.shape[1], id_map.shape[0]), interpolation = cv2.INTER_LINEAR)
|
839 |
+
|
840 |
+
ratio = image.shape[0] / image.shape[1]
|
841 |
+
|
842 |
+
fig = plt.figure(figsize=(16, 16*ratio), dpi=100)
|
843 |
plt.imshow(image, cmap='gray')
|
844 |
|
845 |
if classification:
|
|
|
866 |
for line in side:
|
867 |
line = np.array(line)
|
868 |
plt.plot(line[:,1], line[:,0] ,'-', color='lightgrey', marker=None, linewidth=0.5)
|
869 |
+
#plt.ylim(0, 1080)
|
870 |
+
#plt.xlim(0, 1920)
|
871 |
plt.gca().invert_yaxis()
|
872 |
|
873 |
colors = ['yellow','orange','red']
|
|
|
877 |
side = np.array(side)
|
878 |
if side.size > 0:
|
879 |
plt.plot(side[:,0],side[:,1] ,'-', color=colors[i], marker=None, linewidth=0.6) #color=colors[i]
|
880 |
+
#plt.ylim(0, 1080)
|
881 |
+
#plt.xlim(0, 1920)
|
882 |
plt.gca().invert_yaxis()
|
883 |
+
|
884 |
+
plt.xlim(left=0) # Ensure only positive X values are displayed
|
885 |
plt.tight_layout()
|
886 |
canvas = FigureCanvas(fig)
|
887 |
canvas.draw()
|
|
|
908 |
classification = classify_detections(boxes_moving, boxes_stationary, borders, image.shape, output_dims=segmentation_mask.shape)
|
909 |
|
910 |
output_image = get_result(classification, id_map, model.names, borders, image, regions)
|
911 |
+
cropped_image = output_image[22:output_image.shape[0] - 40, 74:output_image.shape[1] - 33]
|
912 |
return output_image
|
913 |
|
914 |
if __name__ == "__main__":
|