我正在尝试创建一个UI界面,以同时播放ROS bag文件中的所有视频。为此,我使用了线程概念,就像每个视频的每个线程一样。
我可以播放所有视频,但是在播放时会出现以下错误,导致播放停止。
class Main(QMainWindow):
...
...
class videoThread(QtCore.QThread):
def __init__(self,topic,bag,label):
super().__init__()
self.bag = bag
self.topic = topic
self.label = label
def run(self):
bridge = CvBridge()
for topic,msg,t in self.bag.read_messages(topics=[self.topic]):
img_dcam = bridge.compressed_imgmsg_to_cv2(msg,desired_encoding="passthrough")
rgbImage = cv2.cvtColor(img_dcam,cv2.COLOR_BGR2RGB)
convertToQtFormat = QImage(rgbImage.data,rgbImage.shape[1],rgbImage.shape[0],QImage.Format_RGB888)
convertToQtFormat = QPixmap.fromImage(convertToQtFormat)
pixmap = QPixmap(convertToQtFormat)
resizeImage = pixmap.scaled(300,300,Qt.KeepAspectRatio)
self.label.setPixmap(resizeImage)
time.sleep(0.033)
def playVideo(self,topic):
self.x = self.videoThread(topic,self.bag,self.label)
self.x.start()
Traceback (most recent call last):
File "rosmanager_main.py",line 1276,in run
for topic,t in self.bag.read_messages(topics=[self.topic]):
File "/opt/ros/melodic/lib/python2.7/dist-packages/rosbag/bag.py",line 2679,in read_messages
yield self.seek_and_read_message_data_record((entry.chunk_pos,entry.offset),raw,return_connection_header)
File "/opt/ros/melodic/lib/python2.7/dist-packages/rosbag/bag.py",line 2826,in seek_and_read_message_data_record
header = _read_header(f)
File "/opt/ros/melodic/lib/python2.7/dist-packages/rosbag/bag.py",line 1999,in _read_header
raise ROSBagFormatException('Error reading header: %s' % str(ex))
rosbag.bag.ROSBagFormatException: Error reading header: expecting 606348583 bytes,read 871518