R329 Development Board Application - Operation Image (2)
[Copy link]
R329 development board application - operation image ( 2 )
In the previous post ( https://bbs.eeworld.com.cn/thread-1181408-1-1.html ), we have successfully sent the image to the small screen on the board. This post will implement Baidu AI processing.
This R329 development board supports the network, so we can consider implementing AI functions from both local and network aspects . Considering the popularity, Baidu AI is selected as the network implementation. Baidu AI can recognize faces based on pictures and infer age, appearance, face shape, etc. Here we only quote the coordinates of the face.
First, use your Baidu account to apply for the AI application interface. After a successful application, you can obtain the AppID, API Key, and Secret Key . Then calculate the application token based on the API key and Secret Key , and then apply this token to the web request. The response contains information such as the number of faces recognized and the location of the face.
Compared with the previous code, only a small section of code for base64 conversion of the image and network access is inserted, and it is not expanded. One thing that is a bit tricky is that I don’t know how to directly generate base64 code from the image in cv2 , but save it as a temporary file and then read the file in the local path, which feels a bit awkward.
As mentioned in the previous article, if the camera is above the screen, the image read will be inverted, and Baidu AI will automatically rotate the image 180 degrees before recognition, so the returned value of x and y will be at the bottom right of the image we need to recognize, while w and h will extend to the upper left. When writing the code frame, you should use xw and yh .
When cv2 is drawing, the coordinates must be identified as integers ( int ), otherwise an error will be prompted. Therefore, when using the cv2.rectangle command to draw, you need to use int(x) , int(y) , int(xw) , int(yh) for forced conversion.
Due to Baidu's restrictions, fast real-time recognition is not possible, so a restriction condition is added. When the number of recognized faces in the same frame reaches 3 (or more), the current image is saved and the program is interrupted.
As described in "Operating Images ( 1 )" ( https://bbs.eeworld.com.cn/thread-1181408-1-1.html ), enter echo -e "\033[?25l" > /dev/tty0 in the terminal command line to cancel the prompt cursor. Point the camera at a random photo of a person on the Internet, and the camera content can be displayed on the screen. At the same time, the face of the person in the picture can be identified
Attached is a large screen image:
Here, we take out the temporary file, which is an inverted picture.
At the same time, we can see that it takes about 0.5 seconds to process each frame of the image . On the one hand, this is due to network reasons. On the other hand, the efficiency of cv2 drawing is also one of the limitations.
In addition to real people, we also tried cartoon characters, which is also acceptable.
|