Performance: Object detection pipeline in ROS
This affects the real-time responsiveness and smoothness of robotic perception by impacting sensor data processing and visualization speed.
ros::Subscriber sub = nh.subscribe("/camera/image_raw", 10, &callback); void callback(const sensor_msgs::ImageConstPtr& msg) { // Quickly convert and push to a thread-safe queue cv_bridge::CvImagePtr cv_ptr = cv_bridge::toCvCopy(msg, sensor_msgs::image_encodings::BGR8); image_queue.push(cv_ptr->image); } // Separate worker thread processes images asynchronously void worker() { while (ros::ok()) { if (!image_queue.empty()) { cv::Mat img = image_queue.pop(); detectObjects(img); } } }
ros::Subscriber sub = nh.subscribe("/camera/image_raw", 10, &callback); void callback(const sensor_msgs::ImageConstPtr& msg) { cv_bridge::CvImagePtr cv_ptr; try { cv_ptr = cv_bridge::toCvCopy(msg, sensor_msgs::image_encodings::BGR8); } catch (cv_bridge::Exception& e) { ROS_ERROR("cv_bridge exception: %s", e.what()); return; } // Heavy processing inside callback detectObjects(cv_ptr->image); }
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Heavy processing in subscriber callback | N/A | Blocks message queue causing delays | High CPU usage during callback | [X] Bad |
| Asynchronous processing with thread-safe queue | N/A | Non-blocking message handling | Balanced CPU usage | [OK] Good |
| Publishing individual markers per object | N/A | Multiple visualization updates | High GPU load | [X] Bad |
| Batch publishing markers with MarkerArray | N/A | Single visualization update | Lower GPU load | [OK] Good |
import rospy
from sensor_msgs.msg import Image
def callback(data):
rospy.loginfo('Image received')
rospy.init_node('detector')
rospy.Subscriber('/camera/image_raw', Image, callback)
rospy.spin()
What will be printed when an image message arrives on /camera/image_raw?<launch> <node pkg="object_detection" type="detector.py" name="detector" /> </launch>But when you run
roslaunch, you get an error saying the node type is not found. What is the likely problem?Pass the test and this pattern moves unknown