Ask Your Question

How to use a service to make a snapshot?

asked 2019-06-12 10:19:22 -0600

fnando1995 gravatar image

Hello, i already make the python file for the server and client.

I am starting the camera in the server file at the begining, so it just starts one time only and keep up while the service is up too.

the client is a simple python file too which ask the server, it does not send any value to the service.

the server, in its callback handle function, take the picture with the camera and save it.

the problem is that everytime i make the rosrun pkg, the server save only the FIRST image.

lets say i start the roscore, then the server, it starts saying the camera is up. then i run the client and the service does what is supposed to do with the commad _, then at the secon rosrun of the cliente, the "frame" is the same as the before rosrun, and for that time and on the frame keeps been the first....

Why does this occurs? does services are not the proper why to solve this activity?


edit retag flag offensive close merge delete


Can you update your question with your actual code? It's hard to tell what's going on when we only have a description of what's happening

jayess gravatar image jayess  ( 2019-06-20 17:21:57 -0600 )edit

1 Answer

Sort by ยป oldest newest most voted

answered 2019-06-21 09:32:38 -0600

fnando1995 gravatar image

Hello @jayess!

I make some research and this actually could not be implemented. The service will not be able to keep the cameras turned on without the buffer problem. (the first image was shown by the .read() method and after a second or third use of it, it will present the "same" frame because the buffer keeps some frame and the .read method call whatever is in the buffer of the camera). What i finally did was to use a node as a topic publisher to keep the frames in realtime being publish (this is posible is you are working wil low-mid resolution pictures, something like 4k will give you an exponential latency depending on your memory, if so, pease try not to use realtime, but clean your buffer before using using the image, this means use some .read() as a photo rampage and select the last one to continue the flow, as shown next).

~The "10" number depends on the camera, some will have a lower buffer as i have tested. not actual documentation, just testing.

 for i in range(10):  
      ret,frame =
 ret,actual_frame =

~keeps working with "actual_frame"

As you can see, the for is used just to clean the buffer, this is what i have done so far, because i havent figured if python opencv have a function to clean buffer of the camera var created with cv2.VideoCapture().

hope this could help someone.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower


Asked: 2019-06-12 10:19:22 -0600

Seen: 150 times

Last updated: Jun 21 '19