簡體   English   中英

保存裁剪的邊界框

[英]save the cropped bounding box

我想從包含多類的所有數據集中裁剪和保存圖像。 但沒有 output。 謝謝。

def detect_face(img):
    detector = MTCNN()
    faces = detector.detect_faces(image) 
return faces     
                                                                               
dataset = '/content/drive/MyDrive/data_LFW/'

for img in glob.glob(dataset+'/*.*'):
    var_img = cv2.imread(img)
    face = detect_face(var_img)

    if (len(face) == 0):
       continue

    for(ex, ey, ew, eh) in face:
        crop_image = var_img[ey:ey+eh, ex:ex+ew]
                                                                                                           
     
   cv2.imwrite(os.path.join("/content/drive/MyDrive/data_crop",str(img)) ,crop_image)

假設其他一切都是正確的(因為我沒有你的數據集和檢測器代碼),你可能想嘗試糾正幾個縮進,看看你是否能得到一些不同的結果:

if (len(face) == 0):
    continue #correct the indentation and try again

如果您想保存每個檢測,請更正 cv2.imwrite 縮進:

for img in glob.glob(dataset+'/*.*'):
    var_img = cv2.imread(img)
    face = detect_face(var_img)

    if (len(face) == 0):
        continue

    for(ex, ey, ew, eh) in face:
        crop_image = var_img[ey:ey+eh, ex:ex+ew]
      
    cv2.imwrite(os.path.join("/content/drive/MyDrive/data_crop",str(img)),crop_image)
    
    

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM