Robotics StackExchange | Archived questions

Beginner question: OpenCV Error: Assertion failed, Ros

Ubuntu 18.04 Ros Melodic

in the shell:

python serit.py

the output:

OpenCV Error: Assertion failed (cn <= 4) in scalarToRawData, file /build/opencv-L2vuMj/opencv-3.2.0+dfsg/modules/core/src/matrix.cpp, line 1104
[ERROR] [1651748901.105022]: bad callback: <function func at 0x7fedfaa5f1d0>
Traceback (most recent call last):
  File "/opt/ros/melodic/lib/python2.7/dist-packages/rospy/topics.py", line 750, in _invoke_callback
    cb(msg)
  File "serit.py", line 338, in func
    srchap,left_curverad,right_curverad=search_around_poly(blur)
  File "serit.py", line 255, in search_around_poly
    leftx, lefty, rightx, righty, out_img = find_lane_pixels(image)
  File "serit.py", line 195, in find_lane_pixels
    cv2.rectangle(out_img, (win_xleft_low, win_y_low), (win_xleft_high, win_y_high), (0, 255, 0), 4)
error: /build/opencv-L2vuMj/opencv-3.2.0+dfsg/modules/core/src/matrix.cpp:1104: error: (-215) cn <= 4 in function scalarToRawData

run without ROS in the VsCode: use /usr/bin/python3

I understand that there is a problem with the python version. If so how can I fix this? ı am new here and Ros.

Thanks in advance

Asked by hnb on 2022-05-05 07:00:35 UTC

Comments

In that function, "cn" is the number of channels per pixel. For example, an RGB image has 3 channels per pixel. So assuming you are using python2, it would appear you are not passing in an acceptable image format.

Asked by Mike Scheutzow on 2022-05-08 12:29:09 UTC

Answers

There are several possibilities, /usr/bin/python or /usr/bin/python2 or even /usr/bin/env python. Ros melodic works with python2.7 so you should be using python2 not python3.

To confirm you are using right path for python, you can run /usr/bin/python or /usr/bin/python2 in your terminal, use the one which starts the python in the terminal.

Asked by aarsh_t on 2022-05-06 02:35:45 UTC

Comments