raspberrypi / picamera2

New libcamera based python library
BSD 2-Clause "Simplified" License
891 stars 188 forks source link

[HOW-TO] Recreate capture_continuous function with PiCamera2 #900

Closed Ara-O closed 11 months ago

Ara-O commented 11 months ago

I am trying to migrate from picamera to picamera2 and I have been struggling to translate this code to picamera2

with picamera.PiCamera(resolution=(640,480), framerate=30) as camera:
     camera.start_preview(fullscreen=False, window=(100, 20, 640, 480))
     try:
        stream = io.BytesIO()

        # I'm having problems specifically with the line below
        for _ in camera.capture_continuous(stream, format='jpeg', use_video_port=True):
            stream.seek(0)
            image = Image.open(stream).convert('RGB')

-- using picamera

I want to update that to use picamera2.

puterboy commented 9 months ago

I have the same question - did you figure this out? The report was closed but no solution was posted...

The code I am trying to translate is:

bio = io.BytesIO()
for foo in self.pi_camera.capture_continuous(bio, format='jpeg', use_video_port=True):
                bio.seek(0)
                chunk = bio.read()
                bio.seek(0)
                bio.truncate()

I'm surprised that such a basic feature is not replicated in picamera2 and barring that at least a workaround should be documented. How else are people supposed to update picamera code?

i1Cps commented 7 months ago

Any luck guys?

LedRami commented 7 months ago

Up