You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在轮廓内查找最大面积矩形?技术实现求助

技术问题:如何在轮廓(Contour)内查找最大面积矩形?

我目前毫无头绪,以下是我当前的实现思路与代码,恳请各位提供帮助。

轮廓示意图
原始图像

import cv2
import numpy as np
import math


image_path = r"\\acvnas03\ACVNAS03_DATA\60.pd\03. SMT\3. Method\9. File tam\python_k-xoa_T.anh\New folder\kiem_truoc_lo\ROI\H9300600\Bside\IC3.jpg" 
image = cv2.imread(image_path)

gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
_, thresh = cv2.threshold(gray, 20, 255, cv2.THRESH_BINARY_INV + cv2.THRESH_OTSU)
#cv2.imshow("thresh",thresh)

contours, _ = cv2.findContours(thresh, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)
gg = cv2.drawContours(thresh, contours, -1, (0,255,0), 3)  
#cv2.imshow("thres6h",gg)
   
edges = cv2.Canny(gg, 100, 200)   
#cv2.imshow("edges",edges)

kernel = np.ones((3, 3), np.uint8)
closed_edges = cv2.morphologyEx(edges, cv2.MORPH_CLOSE, kernel)

cv2.imshow("Origin6546 al image", closed_edges)
#cv2.imwrite("Origin6546.jpg",closed_edges)

contours2, _ = cv2.findContours(closed_edges, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)

gg2 = cv2.drawContours(thresh, contours2, -1, (0,255,0), 2)
#cv2.imshow("gg2",gg2)
  

cv2.waitKey(0)
cv2.destroyAllWindows()

内容的提问来源于stack exchange,提问作者tuan anh

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.16 05:13:10