如何在轮廓内查找最大面积矩形?技术实现求助
技术问题:如何在轮廓(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
相关产品推荐
相关产品推荐

