Quantcast
Channel: Raspberry Pi Forums
Viewing all articles
Browse latest Browse all 4919

Camera board • Re: libcam - fov vs performance

$
0
0
This captures approx 1000 frames in 10 secs at 1920x1080 ( full fov) using rpicam-vid... to RAM on a Pi5..

Code:

#!/usr/bin/env python3import timeimport os, subprocessimport signalimport globimport sysimport cv2import numpy as np# setupframerate  = 100    # fpscap_length = 10000  # in mSram_limit  = 150    # in MB, stops if RAM below thiswidth      = 1920   # frame width height     = 1080   # frame height# clear ramprint("Clearing RAM...")frames = glob.glob('/run/shm/*.jpg')for tt in range(0,len(frames)):    os.remove(frames[tt])   # start camera with subprocessprint("Starting Camera...")command = "rpicam-vid --camera 0 -n -t 0  --width 1920 --height 1080 --codec mjpeg --segment 1 --framerate " + str(framerate) + " -o /run/shm/temp_%06d.jpg"s = subprocess.Popen(command, shell=True, preexec_fn=os.setsid)poll = s.poll()while poll != None:    print("waiting...")    poll = s.poll()# check ramst = os.statvfs("/run/shm/")freeram = (st.f_bavail * st.f_frsize)/1100000# main loopwhile freeram > ram_limit:       # check ram and stop if full    st = os.statvfs("/run/shm/")    freeram = (st.f_bavail * st.f_frsize)/1100000                 # capture for cap_length    print("Capturing Frames...")    start = time.monotonic()    st = os.statvfs("/run/shm/")    freeram = (st.f_bavail * st.f_frsize)/1100000    while time.monotonic() - start < cap_length/1000 and freeram > ram_limit:        st = os.statvfs("/run/shm/")        freeram = (st.f_bavail * st.f_frsize)/1100000            # stop camera subprocess    os.killpg(s.pid, signal.SIGTERM)           # show trigger frame    frames = glob.glob('/run/shm/temp*.jpg')    im = cv2.imread(frames[0])    image = cv2.resize(im, (960, 540))    cv2.imshow(frames[0],image)           # wait for a key press    print( "Press ESC to exit, Any other key to restart")    k = cv2.waitKey(0)    if k == 27:    # Esc key to stop        print("Exit")        os.killpg(s.pid, signal.SIGTERM)        cv2.destroyAllWindows()        sys.exit()    # clear ram    print("Clearing RAM...")    frames = glob.glob('/run/shm/*.jpg')    for tt in range(0,len(frames)):        os.remove(frames[tt])            # restart camera with subprocess    print("Starting Camera...")    command = "rpicam-vid --camera 0 -n -t 0  --width 1920 --height 1080 --codec mjpeg --segment 1 --framerate " + str(framerate) + " -o /run/shm/temp_%06d.jpg"    s = subprocess.Popen(command, shell=True, preexec_fn=os.setsid)    poll = s.poll()    while poll != None:        print("waiting...")        poll = s.poll()            # stop camera subprocess if runningpoll = s.poll()if poll == None:    os.killpg(s.pid, signal.SIGTERM)

Statistics: Posted by gordon77 — Sat Apr 06, 2024 2:04 pm



Viewing all articles
Browse latest Browse all 4919

Trending Articles