0

I have already installed ros noetic distribution and the sudo apt-get install ros-noetic-cv-bridge and sudo apt-get install ros-noetic-cv-bridge successfully. However, when I am trying to run the following code in pycharm, I am getting the following error:

import os
import argparse
import pdb
import cv2
import rosbag
from sensor_msgs.msg import Image
from cv_bridge import CvBridge

bag_file = './bag_files/20230707_152832.bag'
output_dir= './frames/rgb_bag_output'


image_topic = '/device_0/sensor_1/Color_0/image/data'
# image_topic ='sensor_msgs/Image'

bag = rosbag.Bag(bag_file, "r")
bridge = CvBridge()

#gg =bag.read_messages(topics = '/device_0/sensor_1/Color_0/image/data')
# bag.get_message_count()

count = 0
for topic, msg, t in bag.read_messages(topics=image_topic):
    cv_img = bridge.imgmsg_to_cv2(msg, desired_encoding= "rgb8")#"passthrough")
    cv2.imwrite(os.path.join(output_dir, "frame%06i.png" % count), cv_img)
    print("Wrote image %i" % count)
    count += 1

bag.close() 

the error:

Traceback (most recent call last):
  File "/home/es/PycharmProjects/2-Process-RGBD/extract_bag_frame.py", line 32, in <module>
    cv_img = bridge.imgmsg_to_cv2(msg, desired_encoding= "rgb8")#"passthrough")
  File "/home/es/anaconda3/envs/hsi-env/lib/python3.8/site-packages/cv_bridge/core.py", line 163, in imgmsg_to_cv2
    dtype, n_channels = self.encoding_to_dtype_with_channels(img_msg.encoding)
  File "/home/es/anaconda3/envs/hsi-env/lib/python3.8/site-packages/cv_bridge/core.py", line 99, in encoding_to_dtype_with_channels
    return self.cvtype2_to_dtype_with_channels(self.encoding_to_cvtype2(encoding))
  File "/home/es/anaconda3/envs/hsi-env/lib/python3.8/site-packages/cv_bridge/core.py", line 91, in encoding_to_cvtype2
    from cv_bridge.boost.cv_bridge_boost import getCvType
ModuleNotFoundError: No module named 'cv_bridge.boost.cv_bridge_boost'

How can I resolve this issue?

S.EB
  • 1,966
  • 4
  • 29
  • 54

0 Answers0