Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Python how to use raspberry pie opencv face recognition to automatically control computer display desktop

2025-03-29 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

This article mainly introduces how Python uses raspberry pie opencv face recognition to automatically control the computer display desktop, the article is very detailed, has a certain reference value, interested friends must read it!

Preface since Amoy a raspberry pie 3b on salted fish, tried to do some intranet penetration, set up a website and ate ash, and then bought a camera and extension cord on a whim.

The next step is to knock the code.

Environment

Raspberry pie 3 + python3.7

Win7 python3.6

Process

First of all, the raspberry pie and the computer should be under an intranet, under a router. There are a lot of dependent libraries that need to be installed manually to turn on the camera in the raspberry pie setting and then install cv2,cv2. To introduce the principle, face recognition mainly relies on opencv open source face detection and recognition classifier, which only needs to be imported. Download address of classifier github:

Https://github.com/opencv/opencv/tree/master/data/haarcascades

Download the whole project, extract it, and find

Haarcascade_frontalface_default.xml file, just put this file together with the script file. Do not want to download all the articles at the bottom of the project address can be downloaded separately. Use http to access the intranet URL to inform the working computer to press win+d, which requires the computer to install a web server. I will use the simplest web.py and specify the version when installing web.py.

Import cv2import timeimport requestscapture = cv2.VideoCapture (0) # get camera object casc_path = "haarcascade_frontalface_default.xml" faceCascade = cv2.CascadeClassifier (casc_path) color = (0,255,0) font = cv2.FONT_HERSHEY_SIMPLEX end_time=0countdown=0while (True): # read an image ret,frame=capture.read () # the first return value is Bool to determine whether there is an image The second is the image if ret: # converted to a grayscale image grey = cv2.cvtColor (frame, cv2.COLOR_BGR2GRAY) faceRects = faceCascade.detectMultiScale (grey, scaleFactor = 1.2, minNeighbors = 3, minSize = (32,32)) # this is an array that can be output to take a look If the parameter count = str (len (faceRects)) if int (count) > 0: # > 0: # detects the face start_time = time.time () # to determine the interval between sending requests, the interval between two requests should not be less than 30 seconds. Otherwise, the experience is very bad if end_time30: requests.get ("http://192.168.1.165:8080/") # change the intranet ip end_time = time.time () for faceRect in faceRects: # draw the box every time you restart the computer Frame each face x, y, w, h = faceRect cv2.rectangle (frame, (x-10, y-10), (x + w + 10, y + h + 10), color, 2) cv2.putText (frame, "count:" + count, (10,40), font, 0.8,0255,255) 2) # add a text display of the number of faces # display the image cv2.imshow ("test", frame) c = cv2.waitKey (10) # wait for the exit key if c & 0xFF = ord ('q'): break then let the computer accept the http request For the computer to press win+d, you need the library pyautogui. At first, I also thought that I needed shell script to search for a long time, and this web.py library was also searched by Baidu. Collect all kinds of libraries, which fully reflects the simplicity and ease of use of python. Haha.

#-*-coding: UTF-8-*-import webimport pyautoguiimport timeurls = ('/ (. *)', 'hello') app = web.application (urls, globals ()) class hello: def GET (self Name): pyautogui.keyDown ('win') pyautogui.keyDown (' d') pyautogui.keyUp ('d') pyautogui.keyUp ('win') print ("execute") return "go" if _ _ name__ = = "_ main__": app.run () below is the effect:

The above is all the contents of the article "how Python uses raspberry pie opencv face recognition to automatically control computer display desktop". Thank you for reading! Hope to share the content to help you, more related knowledge, welcome to follow the industry information channel!

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.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report