ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question
0

Beginner question: OpenCV Error: Assertion failed, Ros

asked 2022-05-05 11:39:26 -0500

hnb gravatar image

updated 2022-05-08 11:43:32 -0500

gvdhoorn gravatar image

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

edit retag flag offensive close merge delete

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.

Mike Scheutzow gravatar image Mike Scheutzow  ( 2022-05-08 12:29:09 -0500 )edit

1 Answer

Sort by » oldest newest most voted
1

answered 2022-05-06 02:35:45 -0500

aarsh_t gravatar image

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.

edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2022-05-05 07:00:35 -0500

Seen: 856 times

Last updated: May 08 '22