海陵人脸识别模块串口通信+ROS

#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""" 
人脸识别窗口程序:
作者:FFD
版本:1.0
"""
import serial
# import crcmod
import threading
import rospy
from std_msgs.msg import Int32
import binascii
import time

# pub = rospy.Publisher('/Face_Detection_Topic', Int32, queue_size=10) 
port=rospy.get_param('port',"/dev/ttyUSB0")
bps=rospy.get_param('bps',"115200")
# port="/dev/ttyUSB0"
# bps=115200
pub_data=rospy.Publisher("/Face_Detection_Topic",Int32,queue_size=10)
ser = serial.Serial(port, bps, timeout=0.5)
sigin=False

def read_data():
    while not rospy.is_shutdown():
        # data = ser.read(1024)
        list_data = []
        data =str(binascii.b2a_hex(ser.read(1024)))
        # print(len(data))
        # 字符转列表
        if len(data)>10:

            for i in range(1,len(data)) :
                if (i%2==0):
                    # print(data[i:i+2])
                    list_data.append(data[i:i+2])
            # print(list_data)
            # 判断是否为有效数据
            if list_data[0]=='ef'and list_data[1]=='aa' :
                # print('有效数据')

                # 识别指令返回
                if list_data[7]=='12':
                    # print("获取到识别指令")
                    id_pub=Int32()
                    if list_data[8]=='00':
                        id=int(list_data[11])-16
                        print("人脸识别成功,ID:",id)
                        global sigin
                        sigin=True
                        id_pub.data=int(id)
                        pub_data.publish(id)

                    elif list_data[8]=='01':
                        id_pub.data=99
                        # pub_data.publish(id_pub)
                        # print("检测无人脸")
                    elif list_data[8]=='03':
                        id_pub.data=99
                        pub_data.publish(id_pub)
                        print("未找到该用户信息")
                    elif list_data[8]=='06':
                        id_pub.data=99
                        pub_data.publish(id_pub)
                        print("

你可能感兴趣的:(串口通信,人脸识别模块,HLK-TX510,海陵)