Browse Source

添加注释

liweiquan 10 months ago
parent
commit
1dfaf07d80
1 changed files with 5 additions and 2 deletions
  1. 5 2
      server.py

+ 5 - 2
server.py

@@ -130,11 +130,14 @@ def detect_via_api(request: Request,
 
     # create a copy that corrects for cv2.imdecode generating BGR images instead of RGB,
     # using cvtColor instead of [...,::-1] to keep array contiguous in RAM
+    # 转换图片格式
     img_batch_rgb = [cv2.cvtColor(img, cv2.COLOR_BGR2RGB) for img in img_batch]
-
+    # 选用相关模型进行模版识别
     results = model_dict[model_name](img_batch_rgb, size=img_size)
+    # 处理结果数据
     json_results = results_to_json(results, model_dict[model_name])
 
+    # 如果需要下载图片,在图片上绘制框
     if download_image:
         for idx, (img, bbox_list) in enumerate(zip(img_batch, json_results)):
             for bbox in bbox_list:
@@ -168,7 +171,7 @@ def results_to_json(results, model):
         for result in results.xyxy
     ]
 
-
+# 在图像上绘制框
 def plot_one_box(x, im, color=(128, 128, 128), label=None, line_thickness=3):
     # Directly copied from: https://github.com/ultralytics/yolov5/blob/cd540d8625bba8a05329ede3522046ee53eb349d/utils/plots.py
     # Plots one bounding box on image 'im' using OpenCV