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

Revision history [back]

click to hide/show revision 1
initial version

Hi,

you can use numpy instaed of cv_bridge. Get the data from callback, reshape and normalize it. That's how you can use python3 with melodic. Below is the example:

#!/usr/bin/env python3
import rospy
from sensor_msgs.msg import Image
import cv2 as cv
import numpy as np
from geometry_msgs.msg import Twist
import sys

def callback(data):
    image_a = np.frombuffer(data, dtype=np.int16).reshape(data.height,data.width)
    image = cv.normalize(image_a, None, 0, 255, cv2.NORM_MINMAX, cv2.CV_8U)
    cv.imshow("opencv ros image", image)

if __name__ =="__main__":
    cv_image = rospy.Subscriber("/robot/front_rgbd_camera/rgb/image_raw", Image, callback )

Play with the dtype according to your image type. Hope it works!

Hi,

you can use numpy instaed of cv_bridge. Get the data from callback, reshape and normalize it. That's how you can use python3 with melodic. Below is the example:

#!/usr/bin/env python3
import rospy
from sensor_msgs.msg import Image
import cv2 as cv
import numpy as np
from geometry_msgs.msg import Twist
import sys

def callback(data):
    image_a = np.frombuffer(data, np.frombuffer(data.data, dtype=np.int16).reshape(data.height,data.width)
    image = cv.normalize(image_a, None, 0, 255, cv2.NORM_MINMAX, cv2.CV_8U)
    cv.imshow("opencv ros image", image)

if __name__ =="__main__":
    cv_image = rospy.Subscriber("/robot/front_rgbd_camera/rgb/image_raw", Image, callback )

Play with the dtype according to your image type. Hope it works!

Hi,

you can use numpy instaed of cv_bridge. Get the data from callback, reshape and normalize it. That's how you can use python3 with melodic. Below is the example:

#!/usr/bin/env python3
import rospy
from sensor_msgs.msg import Image
import cv2 as cv
import numpy as np
from geometry_msgs.msg import Twist
import sys

def callback(data):
    image_a = np.frombuffer(data.data, dtype=np.int16).reshape(data.height,data.width)
dtype=np.uint16).reshape(data.height,data.width,-1)
    image = cv.normalize(image_a, None, 0, 255, cv2.NORM_MINMAX, cv2.CV_8U)
    cv.imshow("opencv ros image", image)

if __name__ =="__main__":
    cv_image = rospy.Subscriber("/robot/front_rgbd_camera/rgb/image_raw", Image, callback )

Play with the dtype according to your image type. Hope it works!