Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Raw resize bug again #83

fishrockz opened this issue Apr 13, 2014 · 3 comments

Raw resize bug again #83

fishrockz opened this issue Apr 13, 2014 · 3 comments


Copy link

high spent a while trying to get this to work at all and manage to find the resolution that dosen't course an error

from __future__ import division
import io
import time
import picamera
import numpy as np
import matplotlib.pyplot as plt
width = 1024
height = 768 # this works
width = 100
height = 100 # this dont!

stream = io.BytesIO()#open('', 'wb')
# Capture the image in RGB format
with picamera.PiCamera() as camera:
    #camera.resolution = (1024, 768)
    camera.resolution = (width, height)
    camera.capture(stream, 'rgba')
    print time.time() -st
# Rewind the stream for reading
# Calculate the actual image size in the stream (accounting for rounding
# of the resolution)
fwidth = (width + 31) // 32 * 32
fheight = (height + 15) // 16 * 16
# Load the data in a three-dimensional array and crop it to the requested
# resolution
image = np.fromstring(stream.getvalue(), dtype=np.uint8)
image= image.reshape((fheight, fwidth, 4))[:height, :width, :]
# If you wish, the following code will convert the image's bytes into
# floating point values in the range 0 to 1 (a typical format for some
# sorts of analysis)
#image = image.astype(np.float)
#image = image / 255.0
print image,image.shape
print time.time() -st


I currently do this via a funny bit of C but it would be supper if i could do it via python

Apart form that its a brill little library you have written WELL DONE!!

It would be good to see how fast it would work if it it would accept 100 x 100

Your tip about adding the alpha chan really speeds it up!

Copy link

I think this is something to do with the firmware as 100x100 raw captures used to work but stopped somewhere around firmware 600 (which is why the 100x100 tests is currently xfailed in picamera's test suite). Oddly, they work in YUV mode, but nothing else. However, I'm going to try and re-work the raw capture stuff this weekend anyway due to #73 so I'll have a go with 100x100 in RGB while I'm at it.

In the meantime, you might want to try a small res with a "normal" aspect ratio, like 160x120 - I seem to recall that works but I haven't tested it in a while.

@waveform80 waveform80 added the bug label Apr 15, 2014
@waveform80 waveform80 added this to the 1.4 milestone Apr 15, 2014
@waveform80 waveform80 self-assigned this Apr 15, 2014
Copy link

yep 160x120 works, thanks for the workaround.

Copy link

Looks like the resizer now demands that sizes are aligned when it gets configured (both requested size and crop size). I spent a bit of the weekend re-working raw capture anyway while tinkering with #73 so this shouldn't be too difficult to tack on there as well.

Incidentally, in the new version RGB captures which don't involve the video-port or a resizer (as in your example code above) should be as fast as (or faster than) RGBA because picamera will now dispense with the use of a resizer and switch the still port to the required encoding when it's able to do so (this is all in the interests of getting picamera as close to raspiyuv in behaviour as possible to try and avoid bumping into quite so many bugs in raw capture!)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet

No branches or pull requests

2 participants