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

Camera board • Re: Newbie alert! Help with Rpi5 and camera distance recording

$
0
0
My code that I mixed and matched from examples..

Code:

import timeimport cv2from picamera2 import Picamera2from picamera2.encoders import H264Encoder, Qualityfrom picamera2.outputs import FileOutputfrom picamera2 import MappedArraypicam2 = Picamera2()picam2.configure(picam2.create_video_configuration())colour = (0, 0, 255)origin = (0, 30)font = cv2.FONT_HERSHEY_SIMPLEXscale = 1thickness = 2def apply_timestamp(request):    timestamp = time.strftime("%Y-%m-%d %X")    with MappedArray(request, "main") as m:        cv2.putText(m.array, timestamp, origin, font, scale, colour, thickness)def do_encode(encoder, quality, filename):    start_time = time.strftime("%Y-%m-%d %X")    print("Recording started at:",start_time)    picam2.start_encoder(encoder, output = FileOutput(f"{int(time.time())}.h264"), name='main', quality=quality)    time.sleep(time_seconds)    picam2.stop_encoder(encoder)    picam2.stop()    stop_time = time.strftime("%Y-%m-%d %X")    print("Recording stopped at:",stop_time)hours = 1while hours <= 1:    print("Elapsed hours so far: ",hours)    config = picam2.create_video_configuration({'format': 'BGR888', 'size': (800, 600)})    picam2.configure(config)    picam2.pre_callback = apply_timestamp    picam2.start()    time_seconds = 3600    do_encode(H264Encoder(), Quality.VERY_LOW, "h264_low.h264")    hours += 1print("Completed  12 hour run")

The first hour test completed, the file size is 624MB so for 12 hours I'm looking at about approx 7.488GB. That's tiny!!! Woo! Ok so if we wanted to bump up the quality a tad since 7GB is nothing should I change from VERY_LOW to ...um whatever medium is I forgot lol?

Overall rip into the code with suggestions to refine it and make it more reliable/function/professional/stable whatever you wanna call it! I'm just glad that in its current form it uses such little space I expected more than that!! I ran the code setting hours = 0 and recording 10 second clips and it iterated just fine and finished upon the conditions in the code so I know that works. Think I'm close! Again look for ways to improve it, better performance ect...you can total hate on my code I dont care! :) Like I said its mashed code from different examples!

Statistics: Posted by anglerfish27 — Sat Dec 28, 2024 8:35 pm



Viewing all articles
Browse latest Browse all 5103

Trending Articles