How to use a service to make a snapshot?
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 client.py, 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 _,frame=cam.read(). 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?
UBUNTU 16.04 KINETIC
Asked by fnando1995 on 2019-06-12 10:19:22 UTC
Answers
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 = camera.read()
ret,actual_frame = camera.read()
~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.
Asked by fnando1995 on 2019-06-21 09:32:38 UTC
Comments
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
Asked by jayess on 2019-06-20 17:21:57 UTC