cv_bridge missing channel data?
Hi,
I am working on a task where I need to get the Image data from a bag file and process it for further use. Below is the approach and issue I am facing. Kindly help me.
- Written a python script which subscribes to the
Image
topic. - Converted the
ros_msg
tocv2
format by usingbridge.imgmsg_to_cv2(data, desired_encoding="bgr8")
. - The converted image needs to be directly fed into a model which does the AI related tasks.
- I am not able to see the channel when I try to feed the image data directly to the model. But the trained model needs channel as well.
- When I save the image to local disk and try to load, it works perfectly fine and I am able to see the channel as well.
Could you please let me know if I am missing anything here? Below is the code snippet.
Converting to CV2 and feeding into the model
def callback(data):
bridge = CvBridge()
test_image = bridge.imgmsg_to_cv2(data, desired_encoding="bgr8")
print("Shape Before : {}".format(test_image.shape)) ---- (300, 300)
test_image = np.expand_dims(test_image, axis = 0)
print("Shape After : {}".format(test_image.shape)) ---- (1, 300, 300)
Saving to local disk and feeding to the model
def callback(data):
bridge = CvBridge()
test_image = bridge.imgmsg_to_cv2(data, desired_encoding="bgr8")
cv2.imwrite("File.jpg", test_image)
test_image = image.load_img(path = "/home/File.jpg", target_size = (300, 300))
test_image = image.img_to_array(test_image)
print("Shape Before : {}".format(test_image.shape)) ---- (300, 300, 3)
test_image = np.expand_dims(test_image, axis = 0)
print("Shape After : {}".format(test_image.shape)) ---- (1, 300, 300, 3)
Any help/updates on this?
Thank you, KK
Asked by kk2105 on 2019-04-05 05:58:25 UTC
Comments