|
@@ -3,7 +3,7 @@ import time
|
|
import numpy as np
|
|
import numpy as np
|
|
import cv2
|
|
import cv2
|
|
|
|
|
|
-
|
|
|
|
|
|
+from skimage import measure
|
|
def count_red_pixel(image_np, cnt=1000):
|
|
def count_red_pixel(image_np, cnt=1000):
|
|
# 红色像素计数
|
|
# 红色像素计数
|
|
start_time = time.time()
|
|
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)) \
|
|
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[:, :, 1] <= 255) & (image_hsv[:, :, 1] >= 43) \
|
|
& (image_hsv[:, :, 2] <= 255) & (image_hsv[:, :, 2] >= 100)
|
|
& (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)
|
|
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:
|
|
if red_cnt >= cnt:
|
|
return True
|
|
return True
|
|
else:
|
|
else:
|