Welcome to NUWA-HP60C Depth Camera repository
1.ROS+Opencv Basics
1. ROS+OpenCV Basics
Function package location: ~/ascam_ws/src/ascam_visual
1.1 Overview
ROS has integrated Opencv3.0 or higher versions during the installation process, so there is almost no need to consider the installation configuration. ROS transmits images in its own sensor_msgs/Image message format and cannot directly process images, but the provided [CvBridge] can perfectly convert and be converted image data formats. [CvBridge] is a ROS library, which is equivalent to a bridge between ROS and Opencv.
Opencv and ROS image data conversion is shown in the figure below:

Although the installation configuration does not require too much consideration, the use environment still needs to be configured, mainly the two files [package.xml] and [CMakeLists.txt]. This function package not only uses [CvBridge], but also requires [Opencv] and [PCL], so they are configured together.
- package.xml
[cv_bridge]: image conversion dependency package.
xxxxxxxxxx<build_depend>sensor_msgs</build_depend><build_export_depend>sensor_msgs</build_export_depend><exec_depend>sensor_msgs</exec_depend><build_depend>std_msgs</build_depend><build_export_depend>std_msgs</build_export_depend><exec_depend>std_msgs</exec_depend><build_depend>cv_bridge</build_depend><build_export_depend>cv_bridge</build_export_depend><exec_depend>cv_bridge</exec_depend><exec_depend>image_transport</exec_depend>- CMakeLists.txt
This file has a lot of configuration content. For specific content, please check the source file. The file location is: ~/ascam_ws/src/ascam_visual/CMakeLists.txt
1.2. Start the camera
1.2.1. Start the camera
Terminal input,
xxxxxxxxxxroslaunch ascamera hp60c.launch
View the topic,
xxxxxxxxxxrostopic list
The following are commonly used,
/ascamera_hp60c/rgb0/image: RGB color image topic
/ascamera_hp60c/depth0/image_raw: Depth depth image topic
/ascamera_hp60c/depth0/points: Depth point cloud data topic
View the encoding format of the topic: rostopic echo + [topic] + encoding, for example,
xxxxxxxxxxrostopic echo /ascamera_hp60c/rgb0/image/encodingrostopic echo /ascamera_hp60c/depth0/image_raw/encoding

1.2.2, Start the color image subscription node
xxxxxxxxxxrosrun ascam_visual ascam_rgb_image.py # pyrosrun ascam_visual ascam_rgb_image # C++
View the node graph,
xxxxxxxxxxrqt_graph

- py code analysis
Create a subscriber: the subscribed topic is ["/ascamera_hp60c/rgb0/image"], data type [Image], callback function
[topic()]
xxxxxxxxxxsub = rospy.Subscriber("/ascamera_hp60c/rgb0/image", Image, topic)Use [CvBridge] to convert data. Here you need to pay attention to the encoding format. If the encoding format is incorrect, the converted image will have problems.
xxxxxxxxxxbridge = CvBridge()frame = bridge.imgmsg_to_cv2(msg, "bgr8")- c++ code analysis
Similar to py code
xxxxxxxxxx//Create a receiverros::Subscriber subscriber = n.subscribe<sensor_msgs::Image("/ascamera_hp60c/rgb0/image", 10, RGB_Callback);//Create cv_bridge examplecv_bridge::CvImagePtr cv_ptr;//Data conversioncv_ptr = cv_bridge::toCvCopy(msg, sensor_msgs::image_encodings::BGR8);1.2.3, Start the depth map subscription node
xxxxxxxxxx#Start by selecting 1 from the following commandsrosrun ascam_visual ascam_depth_image.py # pyrosrun ascam_visual ascam_depth_image # C++
View the node graph,
xxxxxxxxxxrqt_graph

- py code analysis
Create a subscriber: the subscribed topic is ["/ascamera_hp60c/depth0/image_raw"], data type [Image], callback function [topic()]
xxxxxxxxxxsub = rospy.Subscriber("/ascamera_hp60c/depth0/image_raw", Image, topic)
Use [CvBridge] to convert data. Here you need to pay attention to the encoding format. If the encoding format is incorrect, the converted image will have problems.
xxxxxxxxxx# Encoding formatencoding = ['16UC1', '32FC1']# You can switch different encoding formats to test the effectframe = bridge.imgmsg_to_cv2(msg, encoding[1])- c++ code analysis
Similar to py code,
xxxxxxxxxx//Create a receiver.ros::Subscriber subscriber = n.subscribe<sensor_msgs::Image>("/ascamera_hp60c/depth0/image_raw", 10, depth_Callback);// Create cv_bridge examplecv_bridge::CvImagePtr cv_ptr;// Data conversioncv_ptr = cv_bridge::toCvCopy(msg, sensor_msgs::image_encodings::TYPE_16UC1)1.2.4, start color image inversion
xxxxxxxxxxrosrun ascam_visual ascam_image_flip.py # pyImage view (open two), select different topics to display
xxxxxxxxxxrqt_image_view

- Code analysis
1), create subscribers
The subscribed topic is ["/ascamera_hp60c/rgb0/image"], data type [Image], callback function [topic()].
2), create publishers
The published topic is ["/ascamera_hp60c/rgb0/image_flip"], data type [Image], queue size [10].
3) Callback function
# Normal image transmission processingdef topic(msg):if not isinstance(msg, Image):returnbridge = CvBridge()frame = bridge.imgmsg_to_cv2(msg, "bgr8")# Opencv image processingframe = cv.resize(frame, (640, 480))frame = cv.flip(frame, 1)# opencv mat -> ros msgmsg = bridge.cv2_to_imgmsg(frame, "bgr8")# Image processing is complete, publish directlypub_img.publish(msg)