In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Network Security >
Share
Shulou(Shulou.com)05/31 Report--
This article mainly explains "how to realize Python face recognition". The content in the article is simple and clear, and it is easy to learn and understand. now please follow the editor's train of thought to study and learn "how to achieve Python face recognition".
Expansion and corrosion of 0x 00 Python pictures
The expansion and erosion of the image is mainly to find the maximum and small areas in the image. The structural element in the code refers to: there are two images BMagX. If X is the object being processed and B is used to deal with X, then B is called structure element, which is also vividly called brush. Structural elements are usually smaller images.
"" Image expansion and corrosion ""
Import cv2
# read pictures: cv2.imread (path, num)
Img = cv2.imread ("1.jpg", 0)
# construct a structural element of 3x3
Elment = cv2.getStructuringElement (cv2.MORPH_RECT, (3mai 3))
# inflated image cv2.dilate (image, element structure)
Dilate = cv2.dilate (img,elment)
# etching image cv2.erode (image, element structure)
Erode = cv2.erode (img,elment)
# subtract two images to get edges, the first parameter is the expanded image, and the second parameter is the corroded image
Result = cv2.absdiff (dilate,erode)
# threshold type: 'TERM_CRITERIA_COUNT',' TERM_CRITERIA_EPS', 'TERM_CRITERIA_MAX_ITER'
# 'THRESH_BINARY',' THRESH_BINARY_INV', 'THRESH_MASK',' THRESH_OTSU'
# 'THRESH_TOZERO_INV',' THRESH_TRIANGLE', 'THRESH_TRUNC'
Retval,result = cv2.threshold (result,50,255,cv2.THRESH_BINARY)
# invert color, that is, invert each pixel of a binary image
Result = cv2.bitwise_not (result)
# display image
Cv2.imshow ('origin',img)
# original image
Cv2.imshow ('result',result)
# Edge detection map
Cv2.waitKey (0)
Cv2.destroyAllWindows ()
Face recognition in 0x01 images
Image face recognition is divided into the following steps:
Picture grayscale, geometric transformation, image enhancement, normalization
Feature point location, face alignment, capturing facial features
"" face detection ""
Import cv2
# call the face detection feature library
Face = cv2.CascadeClassifier ('haarcascade_frontalface_alt2.xml')
# read image file
Sample_imag = cv2.imread ('1.jpg')
# face detection
Faces = face.detectMultiScale (sample_imag,scaleFactor=1.1,minNeig hbors=5,minSize= (1010))
# frame processing
For (xmemy wjinh) in faces:
Cv2.rectangle (sample_imag, (xQuery), (xrew), (0pr 255), 2)
# the result is written to the image
Cv2.imwrite ('face.jpg',sample_imag)
Print ("detect success")
# create a new window to display image
Cv2.namedWindow ("Image")
Cv2.imshow ("Image", sample_imag)
Cv2.waitKey (0)
Cv2.destroyAllWindows ()
Show me James: handsome
And when it comes to identifying warriors: (no way, I didn't recognize it. I went to the training library.)
0x02 dynamic face recognition
Dynamic face recognition does not need to stop and wait, as long as you appear in a certain recognition range, whether you are walking or standing, the system will recognize automatically, that is to say, people walk past in a natural form. The camera will capture and collect information, issue corresponding instructions, and carry out dynamic face recognition.
The first thing is to obtain the feature data which is helpful to face classification according to the shape description of facial organs and the characteristics of the interval between them. The feature weight generally includes the Euclidean interval, curvature and viewpoint between feature points.
Import cv2
# 1. Classifier using OpenCV
# 2. Read photos from the camera or locally
# 3. Change the box on the picture
# 4. Show the picture on the new window
# 1. Classifier / feature library using OpenCV
Detector = cv2.CascadeClassifier ('haarcascade_frontalface_alt2.xml')
# 2. Read photos from the camera or locally
Cap = cv2.VideoCapture (0)
While True:
Ret,img = cap.read ()
Faces = detector.detectMultiScale (img,1.3,5)
# 3. Change the box on the picture
For (xmemy wjinh) in faces:
Cv2.rectangle (img, (x, y), (x + w, y + h), (0,255,0), 2)
Cv2.imshow ('frame',img)
If cv2.waitKey (1) & 0xFF = = ord ('q'):
Break
# 4. Show the picture on the new window
Cap.release ()
Cv2.destroyAllWindows ()
Thank you for your reading, the above is the content of "how to achieve Python face recognition", after the study of this article, I believe you have a deeper understanding of how to achieve Python face recognition, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.