We want to cut out a face from a large number of photos and create a dataset — Automatic processing with OpenCV

MLBoy
2 min readJan 24, 2022

--

It is a method to cut out the face with OpenCV

We want to create a machine learning dataset

Many computer vision tasks use images containing human faces as datasets.
In order to create such a dataset, there are times when we want to detect and crop faces from a large number of images.

We can use dlib’s face detection

With python, we can get faces without any special settings.

Code

This time we will cut out this image.

Import the face detector.

Take the square coordinates of the face in the image with the face detector.

Crop from the original image for each detected face.

If you want to cut out a little wider, add padding to the face rectangle.

When I took the padding of the face square * 1 on all sides, I got an image of bust-up.

The entire code.

Get through a large amount of data with automatic processing

If you loop the original data with the above code, you can automatically crop a large number of images.

🐣

I’m a freelance engineer.
Work consultation
Please feel free to contact us with a brief development description.
rockyshikoku@gmail.com

I am making an app that uses Core ML and ARKit.
We send machine learning / AR related information.

GitHub

Twitter
Medium

Sign up to discover human stories that deepen your understanding of the world.

--

--

MLBoy
MLBoy

No responses yet

Write a response