Welcome to K230 Vision Module repository
8.k230 face recognition
k230 face recognition
k230 face recognitionk230 and RDK X5 communication1. Experimental Prerequisites2. Experimental wiring3. Main code explanation4. Experimental Phenomenon
k230 and RDK X5 communication
1. Experimental Prerequisites
This tutorial uses the RDK X5 development board, and the corresponding routine path is [14.export\RDK-K230\08_k230_face_recognition.py].
K230 needs to run the [14.export\CanmvIDE-K230\08.face_recognition.py] program to start the experiment. It is recommended to download it as an offline program. Since the face recognition function requires the face information to be registered in advance, please refer to the [7. Face Recognition\7. Registering Face Recognition] course first, and then perform this experiment after registering the face.
Things you need:
Windows computer RDK X5 development board USB to TTL module K230 visual module (including TF card with image burned in) Type-C data cable Connection cable
2. Experimental wiring
| k230 vision module | USB to TTL module |
|---|---|
| 5V | VCC |
| GND | GND |
| TXD(IO9) | RxD |
| RXD(IO10) | TXD |

3. Main code explanation
ximport serialimport timecom="/dev/ttyUSB0"ser = serial.Serial(com, 115200)FUNC_ID = 8def parse_data(data): if data[0] == ord('$') and data[len(data)-1] == ord('#'): data_list = data[1:len(data)-1].decode('utf-8').split(',') data_len = int(data_list[0]) data_id = int(data_list[1]) if data_len == len(data) and data_id == FUNC_ID: # print(data_list) x = int(data_list[2]) y = int(data_list[3]) w = int(data_list[4]) h = int(data_list[5]) msg = data_list[6] score = int(data_list[7]) return x, y, w, h, msg, score elif (data_len != len(data)): print("data len error:", data_len, len(data)) elif(data_id != FUNC_ID): print("func id error:", data_id, FUNC_ID) return -1, -1, -1, -1, "", -1while True: if ser.in_waiting: data = ser.readline() # print("rx:", data) x, y, w, h, msg, score = parse_data(data.rstrip(b'\n')) print("face recogition:x:%d, y:%d, w:%d, h:%d, msg:%s, score:%d" % (x, y, w, h, msg, score)) The above program is for parsing K230 data. Only when it complies with specific protocols can the corresponding data be parsed.
in
- x: is the horizontal coordinate of the upper left corner of the recognized box
- y: is the vertical coordinate of the upper left corner of the recognized box
- w: is the width of the recognized frame
- h: is the length of the recognized frame
- name: is the name of the person who is identified, if it is not registered then it is 'unknown'
- score: is the score for identifying people
4. Experimental Phenomenon
- After connecting the cables, the k230 visual module runs offline. After K230 is connected to Canmv IDE, open the corresponding program, click [Save open script to CanMV board (as main.py)] on the toolbar, and then restart K230.

- Transfer the program file to the system, open the terminal and enter the corresponding directory, then run the following command to start the program.
xxxxxxxxxxpython3 08_k230_face_recognition.py
- When the K230 camera image recognizes a face, the terminal will parse and print out the information transmitted by the K230.
in
x: is the horizontal coordinate of the upper left corner of the recognized box
y: is the vertical coordinate of the upper left corner of the recognized box
w: is the width of the recognized frame
h: is the length of the recognized frame
name: is the name of the person who is identified, if it is not registered then it is 'unknown'
score: is the score for identifying people
As shown in the figure below
