Home>

In preparation for machine learning images, we are trying to trim and save only the face part from a large number of images.
The image before trimming is saved in the model folder, and the trimmed face image is going to be saved in the save folder.
When I executed the following program code, no error message was displayed, but no trimmed face images were saved in the save folder.

Error message
C: \ Users \ Taisei \ Anaconda3 \ envs \ opencv \ lib \ site-packages \ numpy \ _distributor_init.py: 32: UserWarning: loaded more than 1 DLL from .libs:
C: \ Users \ Taisei \ Anaconda3 \ envs \ opencv \ lib \ site-packages \ numpy \ .libs \ libopenblas.PYQHXLVVQ7VESDPUVUADXEVJOBGHJPAY.gfortran-win_amd64.dll
C: \ Users \ Taisei \ Anaconda3 \ envs \ opencv \ lib \ site-packages \ numpy \ .libs \ libopenblas.TXA6YQSD3GCQQC22GEQ54J2UDCXDXHWN.gfortran-win_amd64.dll
  stacklevel = 1)
↑ Execution ends here.
Source code
import cv2
import matplotlib.pyplot as plt
import numpy as np
import sys, os
from PIL import Image

#Specify input file path
in_jpg = "C: \ python code \ model"
out_jpg = "C: \ python code \ save"
#Functions that return results in a list
def get_file (dir_path):
    filenames = os.listdir (dir_path)
    return filenames
pic = get_file (in_jpg)
for i in pic:
    # Load image
    image_gs = cv2.imread (in_jpg + i)
    # Load face recognition feature file --- (Specify cascade file path)
    cascade = cv2.CascadeClassifier ('C: \\ Users \\ Taisei \\ Anaconda3 \\ envs \\ OpenCV \\ Lib \\ site-packages \\ cv2 \\ data \\ haarcascade_frontalface_default.xml')
    # Perform face recognition
    face_list = cascade.detectMultiScale (image_gs, scaleFactor = 1.1, minNeighbors = 1, minSize = (1,1))
    # Cut out only face and save
    no = 1;
    for rect in face_list:
        x = rect [0]
        y = rect [1]
        width = rect [2]
        height = rect [3]
        dst = image_gs [y: y + height, x: x + width]
        save_path = out_jpg + '/' + 'out_ (' + str (i) + ')' + str (no) + '.jpg'
        #Save recognition result
        a = cv2.imwrite (save_path, dst)
        plt.show (plt.imshow (np.asarray (Image.open (save_path)))))
        print (no)
        no + = 1

Please describe what you tried for the problem here.

Supplemental information (FW/tool version etc.)

The referenced site was macOS, but I'm Windows10, so there may be a problem.