ROS消息格式-vision_msgs/Detection2DArray (后续创作中...)
生活随笔
收集整理的這篇文章主要介紹了
ROS消息格式-vision_msgs/Detection2DArray (后续创作中...)
小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
1. 終端中查看消息格式
? ~ rosmsg show vision_msgs/Detection2DArray std_msgs/Header header uint32 seqtime stampstring frame_id vision_msgs/Detection2D[] detectionsstd_msgs/Header headeruint32 seqtime stampstring frame_idvision_msgs/ObjectHypothesisWithPose[] resultsint64 idfloat64 scoregeometry_msgs/PoseWithCovariance posegeometry_msgs/Pose posegeometry_msgs/Point positionfloat64 xfloat64 yfloat64 zgeometry_msgs/Quaternion orientationfloat64 xfloat64 yfloat64 zfloat64 wfloat64[36] covariancevision_msgs/BoundingBox2D bboxgeometry_msgs/Pose2D centerfloat64 xfloat64 yfloat64 thetafloat64 size_xfloat64 size_ysensor_msgs/Image source_imgstd_msgs/Header headeruint32 seqtime stampstring frame_iduint32 heightuint32 widthstring encodinguint8 is_bigendianuint32 stepuint8[] data2. 變量含義解讀:
Detection2DArray
# A list of 2D detections, for a multi-object 2D detector.Header header# A list of the detected proposals. A multi-proposal detector might generate # this list with many candidate detections generated from a single input. Detection2D[] detectionsDetection2D[] detections
#Defines a 2D detection result. # #This is similar to a 2D classification, but includes position information, #allowing a classification result for a specific crop or image point to #to be located in the larger image.Header header#Class probabilities ObjectHypothesisWithPose[] results#2D bounding box surrounding the object. BoundingBox2D bbox#The 2D data that generated these results (i.e. region proposal cropped out of #the image). Not required for all use cases, so it may be empty. sensor_msgs/Image source_img參考文檔:http://docs.ros.org/api/vision_msgs/html/msg/Detection2DArray.html/
3. 代碼實(shí)戰(zhàn):(基于Python,實(shí)現(xiàn)一個(gè)簡(jiǎn)單的人臉檢測(cè)):
3.1:訂閱話題
def main():rospy.init_node('track_node')rospy.Subscriber("/objects",Detection2DArray, trcakcallback)rospy.spin()這里訂閱了"/object話題",從tensorflow相關(guān)節(jié)點(diǎn)中,獲得圖片信息,作為ROS的消息進(jìn)行傳送PS:
2. 這里使用ROS信息傳輸,非常占用本地帶寬.雖然沒有上傳到云端.
3. 這里沒有使用基于MIT-Racecar的模擬環(huán)境,但是可以想象,一秒三四十兆的上傳和下載速率.同時(shí)開啟gazebo模擬激光雷達(dá)和相機(jī)節(jié)點(diǎn),還有模擬小車模型及運(yùn)動(dòng),以及目標(biāo)檢測(cè)相關(guān)節(jié)點(diǎn),就已經(jīng)讓我的電腦變得十分卡慢了
3.2: 回調(diào)函數(shù)
#控制臺(tái)輸出速度和轉(zhuǎn)向參數(shù) def vels(speed,turn):return "currently:\tspeed[ %s ]\tturn[ %s ]" % (speed,turn)def Add_vels(speed_add_once,turn_add_once):return "AddOnce:\tSpeed[ %s ]\tTurn[ %s ]" % (speed_add_once,turn_add_once)def trcakcallback(_msg_): rospy.loginfo("=========Msgs=========") rospy.loginfo(_msg_.header.seq) rospy.loginfo(_msg_.detections[-1].header.frame_id) rospy.loginfo(_msg_.detections[-1].results[-1].id) re_id = _msg_.detections[-1].results[-1].id;rospy.loginfo(_msg_.detections[-1].bbox) rospy.loginfo("=========Control=========") if(re_id == "1"):control_speed=(_msg_.detections[-1].bbox.size_x-550)/300control_turn=(_msg_.detections[-1].bbox.center.x-250)/90else:print("NO--------------------1")control_speed=0control_turn=0rospy.loginfo(control_speed) rospy.loginfo(control_turn) pub = rospy.Publisher('/cmd_vel', Twist, queue_size=5)# 創(chuàng)建并發(fā)布twist消息twist = Twist()twist.linear.x = control_speed; twist.linear.y = 0; twist.linear.z = 0twist.angular.x = 0; twist.angular.y = 0; twist.angular.z = control_turnpub.publish(twist)注意: 這里獲得的數(shù)據(jù)格式是"字符串"型的,而不是簡(jiǎn)單的整數(shù)型.
函數(shù)說(shuō)明: 簡(jiǎn)單的獲得目標(biāo)檢測(cè)結(jié)果,根據(jù)目標(biāo)的位置以及框的大小控制小車運(yùn)動(dòng)
總結(jié)
以上是生活随笔為你收集整理的ROS消息格式-vision_msgs/Detection2DArray (后续创作中...)的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: ROS初学笔记 - C++11与PCL库
- 下一篇: [转]C++中sleep()函数的使用