用pointPolygonTest查找内切圆在大图像上效率太低,先查找缩放后图像的内切圆,再去原图上查找可以大幅降低算法时间
import cv2
import numpy as np
import time
t0 = time.time()
mask_gray = cv2.imread("E:/20220519154514.bmp",0)
rows,cols = mask_gray.shape
# Get the contours
print(f'原图尺寸{mask_gray.shape}')
# 识别轮廓
_,mask_grayqqqq = cv2.threshold(mask_gray,50,255,cv2.THRESH_BINARY)
contours2, _ = cv2.findContours(mask_grayqqqq, cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE)
mm = cv2.resize(mask_grayqqqq,(int(cols/8/4),int(rows/8/4)))
contours, _ = cv2.findContours(mm, cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE)
for i in contours:
if 100 < cv2.contourArea(i):
# print(cv2.contourArea(i))
cont = i
for i in contours2:
if 5000 < cv2.contourArea(i):
# print(cv2.contourArea(i))
cont2 = i
# 计算到轮廓的距离
x, y, w, h = cv2.boundingRect(cont)
raw_dist = np.zeros_like(mm, dtype=np.float32)
raw_dist2 = np.zeros_li