一、3588板卡、麒麟系统
表 板卡信息
序号 | 项目 | 备注 |
操作系统 | 银河麒麟 V10 | 内核为linux 5.10.160 |
芯片 | ARM64 | RK3588 |
接口 | u口、网口 | |
电压 | 9~24V |
二、摄像头类型
海康摄像头(200万像素,4mm定焦镜头,具有补光能力):
图 1 相机尺寸
表 1 技术参数
三、第一种读取方法
直接使用opencv进行读取
代码为:
import cv2
cap = cv2.VideoCapture("rtsp://用户名(例:amdin):密码(例:A12345)@ 摄像头IP与端口号(例:192.168.254.12:554)/Streaming/Channels/101")
cap.set(cv2.CAP_PROP_FOURCC,cv2.VideoWriter_fourcc('M','J','P','G'))
while True:
ret,frame = cap.read()
if not ret:
cap = cv2.cap("rtsp://用户名(例:amdin):密码(例:A12345)@ 摄像头IP与端口号(例:192.168.254.12:554)/Streaming/Channels/101")
continue #(这里需要注意,否则读取数据会频繁中断)
cv2.imshow("camera", frame)
if cv2.waitKey(1) & 0xFF == ord('q'):
break
cap.release()
cv2.destroyAllWindows()
优点,使用方法简单;缺点,延时大,后续接图像处理时,容易出现断连情况。
四、第二种读取方法
安装ros系统,下载rocon_devices-develop
网址: GitHub - robotics-in-concert/rocon_devices: A collection of device drivers involved in rocon
具体步骤:
mkdir -p ~/catkin_ws/src
cd ~/catkin_ws/src
catkin_init_workspace
将rocon_devices-develop添加到src文件夹下:
在src/rocon_devices-develop/rocon_rtsp_camera_relay/launch/rtsp_camera_relay.launch中,修改 第二行 default="rtsp://用户名(例:amdin):密码(例:A12345)@ 摄像头IP与端口号(例:192.168.254.12:554)/Streaming/Channels/101"
输入catkin_make
启动命令 roslaunch rocon_rtsp_camera_relay rtsp_camera_relay.launch
采集数据使用如下代码进行接收(python):
#!/usr/bin/env python3
import sys
sys.path.append('/opt/ros/kinetic/lib/python2.7/dist-packages')
sys.path.append('/usr/lib/python2.7/dist-packages')
import rospy
import time
from sensor_msgs.msg import Image
from cv_bridge import CvBridge,CvBridgeError
import numpy as np
import sys
python3 = True if sys.hexversion > 0x03000000 else False
if python3:
# remove ros python2 library
ros_cv_path = '/opt/ros/kinetic/lib/python2.7/dist-packages'
if ros_cv_path in sys.path:
sys.path.remove(ros_cv_path)
import cv2 as cv
#----------------------------------------------------
cv_type = dict()
cv_type['mono8'] = (np.uint8 , 1)
cv_type['8UC2'] = (np.uint8 , 2)
cv_type['bgr8'] = (np.uint8 , 3)
cv_type['8UC4'] = (np.uint8 , 4)
cv_type['8SC1'] = (np.int8 , 1)
cv_type['8SC2'] = (np.int8 , 2)
cv_type['8SC3'] = (np.int8 , 3)
cv_type['8SC4'] = (np.int8 , 4)
cv_type['16UC1'] = (np.uint16 , 1)
cv_type['16UC2'] = (np.uint16 , 2)
cv_type['16UC3'] = (np.uint16 , 3)
cv_type['16UC4'] = (np.uint16 , 4)
cv_type['16SC1'] = (np.int16 , 1)
cv_type['16SC2'] = (np.int16 , 2)
cv_type['16SC3'] = (np.int16 , 3)
cv_type['16SC4'] = (np.int16 , 4)
cv_type['32SC1'] = (np.uint32 , 1)
cv_type['32SC2'] = (np.uint32 , 2)
cv_type['32SC3'] = (np.uint32 , 3)
cv_type['32SC4'] = (np.uint32 , 4)
cv_type['32FC1'] = (np.int32 , 1)
cv_type['32FC2'] = (np.int32 , 2)
cv_type['32FC3'] = (np.int32 , 3)
cv_type['32FC4'] = (np.int32 , 4)
cv_type['64FC1'] = (np.float64, 1)
cv_type['64FC2'] = (np.float64, 2)
cv_type['64FC3'] = (np.float64, 3)
cv_type['64FC4'] = (np.float64, 4)
ros_type = dict()
ros_type[('uint8' , 1)] = ('mono8', 1)
ros_type[('uint8' , 2)] = ('8UC2' , 2)
ros_type[('uint8' , 3)] = ('bgr8' , 3)
ros_type[('uint8' , 4)] = ('8UC4' , 4)
ros_type[('int8' , 1)] = ('8SC1' , 1)
ros_type[('int8' , 2)] = ('8SC2' , 2)
ros_type[('int8' , 3)] = ('8SC3' , 3)
ros_type[('int8' , 4)] = ('8SC4' , 4)
ros_type[('uint16' , 1)] = ('16UC1', 1)
ros_type[('uint16' , 2)] = ('16UC2', 2)
ros_type[('uint16' , 3)] = ('16UC3', 3)
ros_type[('uint16' , 4)] = ('16UC4', 4)
ros_type[('int16' , 1)] = ('16SC1', 1)
ros_type[('int16' , 2)] = ('16SC2', 2)
ros_type[('int16' , 3)] = ('16SC3', 3)
ros_type[('int16' , 4)] = ('16SC4', 4)
ros_type[('uint32' , 1)] = ('32SC1', 1)
ros_type[('uint32' , 2)] = ('32SC2', 2)
ros_type[('uint32' , 3)] = ('32SC3', 3)
ros_type[('uint32' , 4)] = ('32SC4', 4)
ros_type[('int32' , 1)] = ('32FC1', 1)
ros_type[('int32' , 2)] = ('32FC2', 2)
ros_type[('int32' , 3)] = ('32FC3', 3)
ros_type[('int32' , 4)] = ('32FC4', 4)
ros_type[('float64', 1)] = ('64FC1', 1)
ros_type[('float64', 2)] = ('64FC2', 2)
ros_type[('float64', 3)] = ('64FC3', 3)
ros_type[('float64', 4)] = ('64FC4', 4)
def ToRosMsg(img):
msg = Image()
msg.header.stamp = rospy.Time.now()
msg.width = img.shape[1]
msg.height = img.shape[0]
channel = 1
if len(img.shape) is 3:
channel = img.shape[2]
msg.encoding = ros_type[(str(img.dtype), channel)][0]
msg.is_bigendian = 0
msg.step = msg.width * channel
msg.data = img.tobytes()
return msg
def ToCvImg(msg):
img = np.fromstring(
msg.data, dtype=cv_type[msg.encoding][0]).reshape(
msg.height, msg.width, cv_type[msg.encoding][1])
return img
def callback(imgmsg):
img = ToCvImg(imgmsg)
cv_img = cv.resize(img,(640,416),interpolation=cv.INTER_NEAREST)
cv.imshow("listener", cv_img)
cv.waitKey(1)
def listener():
rospy.init_node('listener', anonymous=True)
rospy.Subscriber("/rtsp_camera_relay/image", Image, callback)
rospy.spin()
if __name__ == '__main__':
listener()
优点,数据采集延时小;缺点,安装ros,需要折腾。