I have encoundtered an interesting problem with some of my python code to capture still images. The two programs below are running at different times on the same Raspberry Pi 3B+ with the camera board v2.1. The first program takes a single .PNG image and saves it, with a file size of 5 MB. The second program is configured to capture a series of images, depending on the input number of frames. It saved .PNG images that were 12 MB. I was running these same bits of code previously capturing .JPG and it produced roughly equivalent file sizes. When I switched to save as .PNG for the first program, it had no issues. The second program gave me an "out of resources" error, and so I increased the GPU memory from 128 to 256. This increase allowed the second program to capture multiple images run and save .PNG. The only other difference for the second program is that it is triggered by a GPIO input, and while capturing photos it keeps checking for a GPIO input to terminate the program early before reaching the frames specified at the start of the program.
My question is, why are the .PNG images so much larger in file size compared to the first program. I can't see that there is any difference in the code that would produce that difference. What am I missing?
First program for single capture:
Code: Select all
import time from time import sleep from picamera import PiCamera frames = 1 camera = PiCamera(resolution=(3280, 2464), framerate=30) camera.start_preview(resolution=(2600, 2000),vflip=True,hflip=True) camera.iso = 100 time.sleep(10) camera.rotation=180 camera.shutter_speed = camera.exposure_speed #camera.shutter_speed = 8500 camera.exposure_mode = 'off' g = camera.awb_gains camera.awb_mode = 'off' camera.awb_gains = g start = time.time() camera.capture_sequence(['/home/pi/Desktop/ge267/WORKING/test_image%02d.png' % i for i in range(frames)],quality=100) finish = time.time() camera.stop_preview() camera.close() print('Captured %d frames at %.2ffps' % ( frames, frames / (finish - start)))
Code: Select all
import time import RPi.GPIO as GPIO from time import sleep from picamera import PiCamera def run(): GPIO.setmode(GPIO.BOARD) GPIO.setup(19,GPIO.IN) capture_on = True frames = 1 image_name = 'gimli' filepath = '/home/pi/Desktop/ge267/WORKING/'+ image_name #For capture with use_video_port, use resolution 1024x768 camera = PiCamera(resolution=(3280, 2464), framerate=30) camera.iso = 100 time.sleep(2) camera.rotation=180 camera.shutter_speed = camera.exposure_speed #camera.shutter_speed = 8500 camera.exposure_mode = 'off' g = camera.awb_gains camera.awb_mode = 'off' camera.awb_gains = g start = time.time() i = 1 while capture_on == True: camera.capture(filepath + '_image%04d' % i,format ='png', quality=100, use_video_port=False) print('Photo number: image%04d.jpg' %i) if GPIO.input(19)==1: capture_on = False elif i >= frames: capture_on = False i += 1 finish = time.time() camera.close() print('Captured %d frames at %.2ffps' % ( (i-1), i / (finish - start))) del i