basler / pypylon

The official python wrapper for the pylon Camera Software Suite
http://www.baslerweb.com
BSD 3-Clause "New" or "Revised" License
562 stars 207 forks source link

Basler High FPS recording difficulties #103

Closed jturi closed 3 years ago

jturi commented 5 years ago

Hi,

I hope somebody can help us with this issue.

We have two Basler acA1300-200uc cameras with 25mm lenses. We are trying to save videos with 200 FPS (608x608) in mkv format but no luck so far. We tried to save 608x608 jpg images (95 Kb) as well but the pypylon API does not support JPG or JPEG on Linux. We only had success with the pypylon/samples/save_image.py script :

Somehow it is very slow. With a USB3.0 cable and 40 MB/s write speed 200 jpg images (95 Kb each) (19 Mb total) should take 0.5 seconds. Can somebody help how to set the framerate, resolution and image/video file format and save a 1-sec long video? Or save 200 images in 1 second to a SSD drive? Also is there an option to set the capturing resolution, framerate and format?

I found a solution here: https://stackoverflow.com/questions/49782358/save-video-instead-of-saving-images-while-using-basler-camera-and-python

But the pypylon-1.4.0 library does not have a grab_images() function anymore.

import os
import pypylon
from imageio import get_writer

while True:
    try:
        fsamp = float(input('Sampling rate (Hz): '))
        break
    except ValueError:
        print('Invalid input.')

time_exposure = 1000000 / fsamp

available_cameras = pypylon.factory.find_devices()
cam = pypylon.factory.create_device(available_cameras[0])
cam.open()

cam.properties['ExposureTime'] = time_exposure

buffer = tuple(cam.grab_images(2000))
with get_writer(
       'output-filename.mkv',  # mkv players often support H.264
        fps=fsamp,  # FPS is in units Hz; should be real-time.
        codec='libx264',  # When used properly, this is basically
                          # "PNG for video" (i.e. lossless)
        quality=None,  # disables variable compression
        pixelformat='rgb24',  # keep it as RGB colours
        ffmpeg_params=[  # compatibility with older library versions
            '-preset',  # set to faster, veryfast, superfast, ultrafast
            'fast',     # for higher speed but worse compression
            '-crf',  # quality; set to 0 for lossless, but keep in mind
            '11'     # that the camera probably adds static anyway
        ]
) as writer:
    for image in buffer:
        writer.append_data(image)
del buffer
thiesmoeller commented 5 years ago

Just realized that you are using the inofficial pypylon. This repo is the official Basler Python Binding. Our API is very close to the Basler pylon C++ ask and has thus a complete different way of handling your high performance use case

Take a look in the samples for looped acquisition