- Make sure you have Python (latest) installed in your system.
- Open the folder in CMD or terminal and type
pip install opencv-python
to install OpenCV. - Now edit the main.py file using your favorite code editor(Example: Sublime text editor, VSCode, Vim).
- Place the desired photo in the directory.
- Change
image= cv2.imread('1.jpg')
according to your photo name. (Example:image= cv2.imread('example.jpg')
- Now save the file, close the editor and run main.py.
You can always tweak the program by just changing the values here:(line 16)
faces = face_cascade.detectMultiScale(imgGray, 1.2, 5)
Where detectMultiScale function is used to detect the faces. It takes 3 arguments — the input image, scaleFactor and minNeighbours. scaleFactor specifies how much the image size is reduced with each scale. minNeighbours specifies how many neighbors each candidate rectangle should have to retain it. You may have to tweak these values to get the best results.