admin管理员组文章数量:1122826
I have a question. How I can find the maximum area rectangle inside a contours? Now I don't have an idea.
My approach to the problem is below.
Thanks for any help.
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()
本文标签: pythonhow to find the maximum area rectangle inside a contoursStack Overflow
版权声明:本文标题:python - how to find the maximum area rectangle inside a contours - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736312176a1935004.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论