我需要捕获所有应用程序图标,我发现了一些代码,但是 它捕获也锁定收藏集中,我需要排除它们。 我的代码是:
def identify_objects_and_crop(image):
image = cv2.imread(str(image))
edged = cv2.Canny(image, 10, 250)
kernel = cv2.getStructuringElement(cv2.MORPH_RECT, (7, 7))
closed = cv2.morphologyEx(edged, cv2.MORPH_CLOSE, kernel)
# finding_contours
cnts, contours, hierarchy = cv2.findContours(closed.copy(),
cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)
idx = 1
for c in contours:
x, y, w, h = cv2.boundingRect(c)
if w > 50 and h > 50:
new_img = image[y:y + h, x:x + w]
cv2.imwrite(str(idx) + '.png', new_img)
idx += 1
identify_objects_and_crop("some img path")
有什么想法吗?