6by9 wrote: ↑Thu Aug 23, 2018 2:27 pm
Two differences:
1) There is no hardware acceleration for PNG, whilst there is for JPEG.
2) PNG encodes an RGB image. JPEG encodes a YUV image. The camera always produces YUV, so therefore is a conversion from YUV to RGB required, and again this is done in software.
Basically there is no easy way to accelerate this. Increasing the vpu clock should give you a linear increase in performance should you wish to go that route.
(There would be a way to offload the conversion to RGB to hardware if you really felt like messing with MMAL pipelines. It won't be easy through picamera)
I'm a little surprised there's that big a difference between JPEG with quality 100 and PNG. JPEG quality 100 will be throwing away very little of the high frequency data, therefore it should be pretty close. Can you quantify what you perceive as the difference in image quality?
Thanks for all the replies so far. An update on where I am now:
-I've tried to capture in using rgb directly into a numpy array, after which I save the array as an .npy file to the SD card (for post-processing into a bmp later). The size of the .npy file is 23 MB, and I have managed to capture this and write to the SD card in less than one second. I've posted a copy of the script at the end of this post.
-I can't immediately quantify the quality difference between the JPEG and PNG, but my application examines patterns of pixels to identify parts of an image. Any modification to the pixels is a degradation of the precision of repeat measurements made with photos of the same scene. Does that make any sense?
-In order to make this capture work at all I had to set GPU memory to 256 MB.
-I am now trying to determine why the code doesn't always complete properly (it takes the first few photos in the loop and then gets stuck with no error output--it just freezes). It is not consistently not working though--the capture program works perfectly sometimes, and other times gets hung up and I have to reboot. I can't determine what is the limiting process that could be hanging this up. I've tried to force_turbo=1, and given some over_voltage=2 to try and stabilise the program.
-a colleague has suggested that I may be putting the cpu and program into 'race conditions'.
Can anyone comment if my program is crashing because of a hardware limitation or interference of the software running and being interrupted by other system processes.
Code: Select all
#RGB capture to a numpy array, triggering from GPIO input
#Last updated August 24,2018
import time
import RPi.GPIO as GPIO
from time import sleep
import picamera
import numpy as np
def run():
GPIO.setmode(GPIO.BOARD)
GPIO.setup(19,GPIO.IN)
capture_on = True
frames = 4
image_name = 'gandalf'
filepath = '/home/pi/Desktop/ge267/WORKING/'+ image_name
#For capture with use_video_port, use resolution 1024x768
with picamera.PiCamera() as camera:
width = 3264 #requested output resolution
height = 2464
fwidth = (width + 31) // 32 * 32 #add buffer of array space required by capture to numpy
fheight = (height + 15) // 16 * 16
camera.resolution = (fwidth, fheight)
camera.framerate = 30
camera.iso = 100
camera.rotation=180
time.sleep(2)
i = 1
output = np.empty((fheight, fwidth, 3), dtype=np.uint8) #create an empty numpy array
while capture_on == True:
start = time.time()
camera.capture(output,format='rgb')
np.save(filepath + '_frame%04d.npy' % i,output,allow_pickle='FALSE') #save the array as a binary file for post-processing
finish = time.time()
print('Frame number: frame%04d.npy' %i)
print('Captured one frame in %.2f seconds' % (finish - start))
if GPIO.input(19)==1: #escape options
capture_on = False
elif i >= frames:
capture_on = False
i += 1
camera.close()