python-opencv最大内切圆查找

本文探讨了使用OpenCV在Python中查找最大内切圆时遇到的效率问题。通过先在缩放后的图像上进行查找,然后再在原始图像上验证,可以显著提高算法的运行速度。
摘要由CSDN通过智能技术生成

用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
评论 7
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值