使用 ROS 使用 vison_opencv 构建 python3:引发 CvBridgeError,“编码指定为 %s 但图像具有不兼容的类型 %s” % (encoding,cv_type)

问题描述 投票:0回答:1

我正在尝试使用 ROS 运行 python3。默认情况下,ROS melodic 随 python2.7 一起安装。 因此,我使用以下说明安装了 python3:

https://dkqhzm2.tistory.com/entry/ImportError-dynamic-module-does-not-define-module-export-function-PyInitcvbridgeboost-in-Xavier-AGX

我从以下 git 克隆了 cv_bridge src:它被称为vision_opencv https://github.com/mikejmills/vision_opencv

我也将我的脚本放入

#!/usr/bin/env python3

这样当我做catkin_make时它符合python3

以下错误是此包的问题:

rrcam@rrcam20220901-001:~/catkin_ws$ rosrun camera_calibration cameracalibrator.py --size 12x8 --square 0.05 image:=/cam1
Traceback (most recent call last):
  File "/home/rrcam/catkin_ws/src/camera_calibration/nodes/cameracalibrator.py", line 39, in <module>
    from camera_calibration.camera_calibrator import OpenCVCalibrationNode
  File "/home/rrcam/catkin_ws/src/camera_calibration/src/camera_calibration/camera_calibrator.py", line 44, in <module>
    from camera_calibration.calibrator import MonoCalibrator, StereoCalibrator, Patterns
  File "/home/rrcam/catkin_ws/src/camera_calibration/src/camera_calibration/calibrator.py", line 38, in <module>
    import cv_bridge
  File "/home/rrcam/catkin_ws/devel/lib/python2.7/dist-packages/cv_bridge/__init__.py", line 34, in <module>
    exec(__fh.read())
  File "<string>", line 1, in <module>
  File "/home/rrcam/catkin_ws/src/vision_opencv/cv_bridge/python/cv_bridge/core.py", line 164
    raise CvBridgeError, "encoding specified as %s, but image has incompatible type %s" % (encoding, cv_type)
                          ^
SyntaxError: invalid syntax

不知道该怎么办。

如果我仅使用 python2.7 而不是 python3 进行编译,则会出现错误:

rrcam@rrcam20220901-001:~/catkin_ws$ rosrun camera_calibration cameracalibrator.py --size 12x8 --square 0.05 image:=/cam1
Exception in thread Thread-6:
Traceback (most recent call last):
  File "/usr/lib/python2.7/threading.py", line 801, in __bootstrap_inner
    self.run()
  File "/home/rrcam/catkin_ws/src/camera_calibration/src/camera_calibration/camera_calibrator.py", line 118, in run
    self.function(m)
  File "/home/rrcam/catkin_ws/src/camera_calibration/src/camera_calibration/camera_calibrator.py", line 242, in handle_monocular
    max_chessboard_speed = self._max_chessboard_speed)
  File "/home/rrcam/catkin_ws/src/camera_calibration/src/camera_calibration/calibrator.py", line 954, in __init__
    super(MonoCalibrator, self).__init__(*args, **kwargs)
TypeError: super() argument 1 must be type, not classobj

有人可以告诉我如何解决这个问题吗?

python-3.x ros python-2.x
1个回答
1
投票

您尝试将 Python2.x 代码与 Python3 一起使用,但这不起作用。如果你想在 ROS 中使用 Python3,你不应该使用 Melodic,因为它的目标是 2.x。你可以让它有点与Python3一起工作,但这仍然不是一个好主意。

如果您想要 Python3,您应该使用 Noetic 发行版。

© www.soinside.com 2019 - 2024. All rights reserved.