OpenCV is the most popular library for computer vision. Originally written in C/C++, it now provides bindings for Python. OpenCV uses machine learning algorithms to search for faces within a picture. For something as complicated as a face, there isn’t one simple test that will tell you if it found a face or not. Instead, there are thousands of small patterns/features that must be matched. The algorithms break the task of identifying the face into thousands of smaller, bite-sized tasks, each of which is easy to solveHere is what you can do with OpenCV
Well before we start mentioning the provided examples on web site, it is good to have the API search tool - i.e. reading and writing images API
Here as part of the gui features we will read an image from disk. Likewise, we can write a copy of the image to the disk.
Here are some of the methods we will use:
imread
- file name
- flag on way image should be read
- named window name
- image
- file name on disk
- image
#------------------------------------------------------------
import cv2
import numpy as np
#practice numpy
#https://www.w3resource.com/python-exercises/numpy/index.php#EDITOR
# IMREAD_GRAYSCALE = 0
# IMREAD_COLOR = 1
# IMREAD_UNCHANGED = -1
img = cv2.imread('img.JPG',cv2.IMREAD_GRAYSCALE)
# ----------showing with opencv.........
cv2.imshow('my image',img)
k = cv2.waitKey(0) & 0xFF
if k == 27: # wait for ESC key to exit
cv2.destroyAllWindows()
elif k == ord('s'): # wait for 's' key to save and exit
cv2.imwrite('img2.JPG',img) # writing the image
cv2.destroyAllWindows()
#------------------------------------------------------------