I have a projector that I use to project several images onto a scene. I project several photos onto the scene sequentially and try to take 1 picture of every different image projected onto the scene. I am trying to capture photos of the scene using capture_sequence function and I enable video_port parameter to take photos faster.
I have a generator function to yield a new stream object to the function for every photo I take. This generator function takes almost 1 second to yield a new stream since I project a different image onto the scene in between frames and it takes 1 second to project a new photo onto the scene and save the capture onto the disk.
The weird thing is that the first 3 images show the same image projected onto the scene. I change the image between every frame using the generator function (and I do this synchronously). I even put sleeps of several seconds to make sure the new image is shown before yield statement returns but it doesn't matter, the first 3 photo is still the same.
If I disable video_port parameter, everything works fine. Every photo taken shows a different image projected onto the scene.
What might be the problem? Is there some buffering going on in video port when I initialize the capture_sequence function? What can I do to overcome this problem?
You can find the relevant parts of the code:
Code: Select all
def capture(self): self.__pi_camera.capture_sequence(self._feed_capture(), format='yuv', use_video_port=True) def _feed_capture(self): frame = 0 while frame < 10: self.__projector.show_image(get_next_image_to_project()) # Wait until image is shown while self.__projector.image_shown() is False: time.sleep(0.05) stream = io.BytesIO() yield stream stream.seek(0) captured_grayscale_array = numpy.fromstring(stream.getvalue(), dtype=numpy.uint8, count=yuv_width * yuv_height).reshape( (yuv_height, yuv_width)) self.save_array_as_image(captured_grayscale_array, str(frame) + ".jpg") frame += 1