如何仅查找彩色图像,不包括空心图像?

时间:2017-10-23 16:10:26

标签: python opencv image-processing automation ui-automation

我需要捕获所有应用程序图标,我发现了一些代码,但是 它捕获也锁定收藏集中,我需要排除它们。 我的代码是:

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") 

screenshot

有什么想法吗?

0 个答案:

没有答案