浏览代码

Merge remote-tracking branch 'origin/master'

fangjiasheng 2 年之前
父节点
当前提交
a15b4f368e
共有 1 个文件被更改,包括 12 次插入2 次删除
  1. 12 2
      isr/pre_process.py

+ 12 - 2
isr/pre_process.py

@@ -3,7 +3,7 @@ import time
 import numpy as np
 import cv2
 
-
+from skimage import measure
 def count_red_pixel(image_np, cnt=1000):
     # 红色像素计数
     start_time = time.time()
@@ -14,8 +14,18 @@ def count_red_pixel(image_np, cnt=1000):
     red_mask = ((image_hsv[:, :, 0] >= 0) & (image_hsv[:, :, 0] <= 10) | (image_hsv[:, :, 0] <= 180) & (image_hsv[:, :, 0] >= 156)) \
                & (image_hsv[:, :, 1] <= 255) & (image_hsv[:, :, 1] >= 43) \
                & (image_hsv[:, :, 2] <= 255) & (image_hsv[:, :, 2] >= 100)
+    red_cnt = 0
+    labels = measure.label(red_mask, connectivity=2)  # 8连通区域标记
+    regions = measure.regionprops(labels)
     red_cnt = np.sum(red_mask != 0)
-    print("red_cnt", red_cnt, time.time()-start_time)
+    print("red_cnt regions", len(regions),red_cnt, time.time()-start_time)
+    if regions and len(regions)>0:
+        _max_area = max([r.bbox_area for r in regions])
+        if _max_area>100:
+            print("red_cnt max_area", _max_area, time.time()-start_time)
+            return True
+    return False
+
     if red_cnt >= cnt:
         return True
     else: