Comments (14)
The issue is with converting a grayscale image into rgb8 without specifying how you want to convert it, but it looks like you try and convert your grayscale image unnecessarily to a color format.
Rather than converting your binary image into rgb8, then immediately converting it back to gray as shown here:
imageLeft = br.imgmsg_to_cv2(imageL, "rgb8")
imageRight = br.imgmsg_to_cv2(imageR, "rgb8")
imageL_new=cv.cvtColor(imageLeft, cv.COLOR_BGR2GRAY)
imageR_new=cv.cvtColor(imageRight, cv.COLOR_BGR2GRAY)
try reading it in as a mono8 or another grayscale format instead, like following:
imageL_new = br.imgmsg_to_cv2(imageL, desired_encoding='mono16')
imageR_new = br.imgmsg_to_cv2(imageR, desired_encoding='mono16')
from vision_opencv.
@ijnek Thank you for your response. however after trying your solution im now getting this error :
disparity = stereo.compute(imageR_new,imageL_new)
error: /build/opencv-L2vuMj/opencv-3.2.0+dfsg/modules/calib3d/src/stereobm.cpp:1072: error: (-210) Both input images must have CV_8UC1 in function compute
from vision_opencv.
Hi, try replacing 'mono16' with 'mono8' in the commands I sent previously and see if it works.
from vision_opencv.
Hi, try replacing 'mono16' with 'mono8' in the commands I sent previously and see if it works.
@ijnek i made the changes but i still cant see the disparity image in the desired topic with rqt_image_view and i get this this in the terminal :
ImageView.callback_image() could not convert image from '16SC1' to 'rgb8' ([16SC1] is not a color format. but [rgb8] is. The conversion does not make sense)
FYI :
im basically trying to estimate a disparity map from the subscribed image topics and then publish it. i set in both cameras launch file the color mode to : rgb8
Update :
I changed the camera parameter in the launch file to mono8 but that didnt change anything, but it was worth the try but i still am confused on how to solve the issue
from vision_opencv.
I believe the problem lies in the input image format being the wrong format.
You seem to be expecting both input images to be color images. In that case, the code you have in the original post seems correct. The error messages indicate however, that the input images you're receiving are 16SC1 which are grayscale (or depth) images, not colored images.
Did you try using rqt_image_view to view the input images to see if they're gray or rgb?
from vision_opencv.
in ImageView i dont see anything when i select either the /left_camera
or /right_camera
topics and thats when i get that error in the terminal. however my /image_raw
topic is rgb
from vision_opencv.
I believe your input images aren't rgb. What does /camera_left/image_raw
and /camera_right/image_raw
look like in rqt_image_view?
from vision_opencv.
@ijnek here are 2 screenshots of both /camera_left/image
_raw and /camera_right/image_raw
and a screenshot of the color mode im running the cameras with : rgb8
from vision_opencv.
Those images look like color images, and so they're definitely not gray.
Could you try something along the lines of
print(imageL.encoding)
print(imageR.encoding)
to make sure that's rgb8
?
from vision_opencv.
[INFO] [1668765614.833292]: receiving Image
[INFO] [1668765614.879525]: showing depth image
rgb8
yeah its rgb8 encoding :/
from vision_opencv.
Then I don't know why you're getting the error message could not convert image from '16SC1' to 'rgb8' ([16SC1] is not a color format. but [rgb8] is. The conversion does not make sense)
.... you'll have to narrow down which line is the problem.
But I did realise you have cv.COLOR_BGR2GRAY
, but it should be cv.COLOR_RGB2GRAY
..
from vision_opencv.
@ijnek thank you for your help. i noticed that as well and i changed it to cv.COLOR_RGB2GRAY
but that didn't solve the Problem. what i get out of the disparity = stereo.compute(imageR_new,imageL_new)
function has a dtype of np.int16. but does that have a role in the issue ?
from vision_opencv.
@ijnek i made the following changes to my code :
#! /usr/bin/env python2
import rospy
import cv2 as cv
import numpy as np
from cv_bridge import CvBridge, CvBridgeError
from sensor_msgs.msg import Image
import message_filters
def read_cameras():
imageL = message_filters.Subscriber("/ids_left/image_rect", Image)
imageR = message_filters.Subscriber("/ids_middle/image_rect", Image)
# Synchronize images
ts = message_filters.ApproximateTimeSynchronizer([imageL, imageR], queue_size=10, slop=0.5)
ts.registerCallback(image_callback)
rospy.spin()
def image_callback(imageL, imageR):
br = CvBridge()
rospy.loginfo("receiving Image")
imageLeft = br.imgmsg_to_cv2(imageL, desired_encoding='bgr8')
imageRight = br.imgmsg_to_cv2(imageR, desired_encoding='bgr8')
imageLeft_new=cv.cvtColor(imageLeft, cv.COLOR_BGR2GRAY)
imageRight_new=cv.cvtColor(imageRight, cv.COLOR_BGR2GRAY)
stereo = cv.StereoBM_create(numDisparities=16, blockSize=15)
disparity = stereo.compute(imageRight_new,imageLeft_new)
arr8 = (disparity/256).astype(np.uint8) # np.uint16 to np.uint8
color_disparity = cv.applyColorMap(arr8, cv.COLORMAP_JET)
rospy.loginfo("showing depth image")
# Process images...
pub = rospy.Publisher('/left_camera', Image, queue_size=1)
msg = br.cv2_to_imgmsg(color_disparity, encoding='rgb8')
pub2 = rospy.Publisher('/Right_camera', Image, queue_size=1)
msg2 = br.cv2_to_imgmsg(color_disparity, encoding='rgb8')
pub.publish(msg)
pub2.publish(msg2)
if __name__ == '__main__':
rospy.init_node('my_node')
try:
read_cameras()
except rospy.ROSInterruptException:
pass
However now i can see my /left_camera and /right_camera topics in rqt_image_view and they look like this :
this doesnt look like a disparity image to me..
from vision_opencv.
im closing the issue but i havent found a solution yet. if anyone has an idea let me know please
from vision_opencv.
Related Issues (20)
- ImportError: libopencv_core.so.4.2: cannot open shared object file no such file or directory HOT 2
- how to convert a 32FC1 image message to color formats? HOT 1
- Error: ‘EQUIDISTANT’ is not a member of ‘sensor_msgs::distortion_models’. HOT 3
- CMake Error cv_bridgeConfig.cmake:113 HOT 1
- ROSCvMatContainer assumes encoding string for cv::Mat type CV_8UC3
- Potential code duplication in ROSCvMatContainer
- Check for OpenCV 4 in ROS Melodic
- ImportError: /lib/x86_64-linux-gnu/libp11-kit.so.0: undefined symbol: ffi_type_pointer, version LIBFFI_BASE_7.0 HOT 4
- CMake Error at /opt/ros/noetic/share/cv_bridge/cmake/cv_bridgeConfig.cmake:113 HOT 1
- ModuleNotFoundError: No module named 'catkin_pkg'
- cannot install vision_opencv from binaries with libopencv-contrib-dev installed.
- error in anaconda virtual environment HOT 1
- image_geometry/cameramodels.py uses deprecated numpy.matrix subclass HOT 3
- fix rosdep install for cv_bridge and opencv
- image_geometry documentation not generating
- Rolling Ubuntu Jammy image_geometry build disabled since 3-7-2024 HOT 3
- Magic number in `getConversionCodes()`
- Suspicious code in `getConversionCode()` HOT 1
- Numpy 2.0 support HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from vision_opencv.