Based on OpenCV Face Recognition, Use VisionFive 2 to control 3D-Printed Anti-Social Flowers

This article is reproduced from the Verimake blog: Verimake.

Demo video: Video.

The operation of this tutorial is mainly based on StarFive’s VisionFive 2 development board. For specific information about the board or other products, refer to the official website. For the open-source technical documentation and installation tutorials for VisionFive 2, refer to the official documentation.

1. Installing Debian OS on VisionFive 2

1.1 Burn Debian OS onto Micro-SD

This section refers to section 3.3 in the official documentation on how to burn the OS to a Micro-SD card.

[Preparation] Prepare a 32GB Micro-SD card. Connect the Micro-SD card to your computer using an external or built-in card reader. Format the Micro-SD card.

For macOS users, the Micro-SD card may not appear when inserted. You can use the command diskutil list in the terminal to confirm if the target Micro-SD card is recognized. Then, format the Micro-SD card using the command sudo diskutil eraseDisk FAT32 SDCARD MBRFormat </dev/...>, where </dev/...> is the specific name of the target Micro-SD card.

[Download the system] Download the latest version of the Debian image from the link provided by StarFive Technology (link). Extract the file with the .bz2 extension from the sd folder.

[Burning process] The document recommends using BalenaEtcher. Click the download link to install and run BalenaEtcher. Click “Flash from File” and select the previously extracted .img file. Click “Select target” and choose the connected Micro-SD card. Finally, click “Flash!” to start the burning process.

1.1 Login to Debian

In the “Login to Debian” section of the official documentation, three login methods are provided:

This tutorial mainly uses the USB to serial connection with a macOS computer for login. If you want to try other methods, refer to the official documentation.

Hardware connection

Refer to the following diagram to connect the serial port and connect the USB to serial converter to your personal computer.


Install Minicom

To install Minicom on macOS, you need to use Homebrew. First, install Homebrew by entering the following command in the terminal:

/bin/bash -c "$(curl -fsSL"

Then, enter the command to install minicom:

brew install minicom

Connect the serial port

First, you need to know the device name for the USB serial connection. Use the command ls /dev/tty.* to view all the connected serial devices on your computer and find the ID of the target device (e.g., /dev/tty.usbmodem102, where usbmodem102 is the device ID, and /dev/tty. remains the same). After obtaining the device ID, enter the following command to connect to the serial device:

minicom -D /dev/tty.<deviceID> -b 115200

Start the device

Enter the username and password to log in. You can log in using either the “root” or “user” username, with the password being “starfive”.

2. Python 3 Environment Setup

The official documentation provides a shell command to install dependencies, including Firefox browser and python-opencv, using a one-click installation package. First, download the corresponding file. This step requires VisionFive 2 to be connected to the internet, which can be achieved by connecting an Ethernet cable to the Ethernet interface.


This step can be completed on the terminal of VisionFive 2 or downloaded on your personal computer and transferred to VisionFive 2 (you can also create a file with the same name on VisionFive 2 and copy all the content). Run the shell script for installing the package and dependencies.

chmod +x

sudo ./

This installation process may take a while, possibly 2-3 hours.

3. Face Recognition using OpenCV

[Hardware Configuration] This article uses a USB camera. The current version of VisionFive 2 does not support pyqt, which means that the program cannot display the content captured by the camera. To verify the availability of your own camera, enter the following Python command in the terminal:


If Python 3 is successfully configured, the Python programming interface will be displayed. Enter the following code in this interface:

import cv2

print(cv2.VideoCapture(index=4, apiPreference=cv2.CAP_V4L2)) # USB camera

Here, the default index for an external USB camera is 4. It is recommended to use the command sudo v4l2-ctl --list-devices in the terminal to check the number after /dev/video under the “USB Camera” section to confirm the index.

If the camera information is printed without any errors, it indicates that the camera is working correctly.

[Face Recognition] Once the camera is successfully read, you can start writing programs related to face recognition. Since Qt cannot be used, it is best to enter the command export QT_QPA_PLATFORM=offscreen in the terminal to use the offscreen mode.

4. Example Demo

Here is a simple example. The camera will read the information and print True/False in the output to indicate whether a face is detected. Create a new Python document and enter nano in the terminal to enter the nano editor. Enter the following code:

import cv2
import time

# Load the cascade classifier model
face_cascade = cv2.CascadeClassifier("/usr/share/opencv4/haarcascades/haarcascade_frontalface_default.xml")

# Open the camera
cap = cv2.VideoCapture(4, cv2.CAP_V4L2)

# Create a timer
start_time = time.time()

while True:
    # Read the camera image
    ret, frame =

    # Convert the image to grayscale
    gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)

    # Detect faces
    faces = face_cascade.detectMultiScale(gray, scaleFactor=1.1, minNeighbors=5, minSize=(30, 30))

    # Check if faces are detected
    if len(faces) > 0:
        has_face = True
        has_face = False

    # Print the result

    # Check if 30 seconds have elapsed
    elapsed_time = time.time() - start_time
    if elapsed_time >= 30:

    # Wait for a while to ensure the program finishes

# End the program

The default frontal face model haarcascade_frontalface_default.xml is used here. In the /usr/share/opencv4/haarcascades directory, there are other models available for different types of face recognition, such as eye detection, etc.

Example Demonstration

As demonstrated in this tutorial, we have created a video in collaboration with StarFive, showcasing the remote control of paper flowers using face recognition. You can watch the video here.


The modeling file of the 3d-Printed flowers:


I am out of the loop. Just what is an “Anti-Social Flower”?

Machine translation mistake likely. Anti-Social-Anxiety Robotic Flower - robotiic flowers that help relax and reduce social anxiety.


@rvalles @chbinnc Sorry for the confusion. “Anti-social” means avoiding meeting people here since when the camera recognizes a face, the flowers close up and open again when no face is detected. Is “Anti-Social” a good word to describe this kind of personality? Any advice is welcome. :grinning: