Nagarjun Vinukonda
Nagarjun Vinukonda

Reputation: 183

Building python3 with ROS using vison_opencv: Raise CvBridgeError, "encoding specified as %s but image has incompatible type %s" % (encoding,cv_type)

I am trying to run python3 with ROS. By default ROS melodic is installed with python2.7. Hence I have installed the python3 using following instructions:

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

where I have cloned the cv_bridge src from the following git: which is called vision_opencv https://github.com/mikejmills/vision_opencv

I also put in my scripts as

#!/usr/bin/env python3

So that it complies in python3 when I did catkin_make

The following error is the trouble with this package:

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

Not sure what to do.

If I compile only with python2.7 instead of python3 I get error as:

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

Can someone tell me how to tackle this problem?

Upvotes: 0

Views: 311

Answers (1)

BTables
BTables

Reputation: 4823

You’re trying to use Python2.x code with Python3, which doesn’t work. If you want to use Python3 with ROS you shouldn’t be using Melodic, since it targets 2.x. You can get it to sort of work with Python3, but it’s still not a great idea.

If you want Python3 you should be using the Noetic distro.

Upvotes: 1

Related Questions