Callback function for sensor_image sensor
Hello ROS community,
I'm working with a subscriber in python to recover images from camera and I'm trying to save all the images that I received by using the code below. I understand my problem: it is that it save me the same image a lot of time because of the while loop. But when I delete the the while loop it saves me only the last image captured by the camera.
So I don't knew how my callback function exactly. I want to save every received image.
Thank you for your advises at advance
def image_callback(msg):
i = 0
print("Received an image!")
try:
# Convert your ROS Image message to OpenCV2
cv2_img = bridge.imgmsg_to_cv2(msg, "bgr8")
except CvBridgeError, e:
print(e)
else:
while(True):
# Save your OpenCV2 image as a jpeg
cv2.imwrite('camera_image'+str(i)+'.png', cv2_img)
print("image enregistrer num ", str(i))
i+=1`
Asked by massyp on 2019-05-29 06:07:54 UTC
Comments
here is the best way :
Asked by massyp on 2019-05-29 08:07:44 UTC
If you have a working solutions, please mark it as the accepted answer.
Asked by dasanche on 2019-06-08 04:45:37 UTC
Sorry, But I can't mark, that says me that it is my own solution.
So I think that you can vote. It's a good solution
Thank you.
Asked by massyp on 2019-06-08 05:27:45 UTC