樹莓派相機︰ PiCamera 《三》

『問題』有時比『答案』有趣乎?祇因『懸疑』未決耶!

所謂『玩科技』自得其樂者也☆

pi@raspberrypi:~/test ipython3  Python 3.4.2 (default, Oct 19 2014, 13:31:11)  Type "copyright", "credits" or "license" for more information.  IPython 2.3.0 -- An enhanced Interactive Python. ?         -> Introduction and overview of IPython's features. %quickref -> Quick reference. help      -> Python's own help system. object?   -> Details about 'object', use 'object??' for extra details.  In [1]: from io import BytesIO  In [2]: from picamera import PiCamera  In [3]: from PIL import Image  In [4]: 串流 = BytesIO()  In [5]: 相機 = PiCamera()  In [6]: 相機.resolution = (1024, 768)  In [7]: 相機.capture(串流, format='jpeg')  In [8]: 串流.seek(0) Out[8]: 0  In [9]: 擷取影像 = Image.open(串流)  In [10]: 擷取影像.show()  In [11]:  </pre> <img class="alignnone size-full wp-image-62130" src="http://www.freesandal.org/wp-content/uploads/PIL1024x768.png" alt="pil1024x768" width="1026" height="797" />    <pre class="lang:python decode:true">pi@raspberrypi:~/test ipython3 
Python 3.4.2 (default, Oct 19 2014, 13:31:11) 
Type "copyright", "credits" or "license" for more information.

IPython 2.3.0 -- An enhanced Interactive Python.
?         -> Introduction and overview of IPython's features.
%quickref -> Quick reference.
help      -> Python's own help system.
object?   -> Details about 'object', use 'object??' for extra details.

In [1]: import picamera

In [2]: import numpy as np

In [3]: import matplotlib.pyplot as plt

In [4]: 相機 = picamera.PiCamera()

In [5]: 相機.resolution = (320, 240)

In [6]: RGB空矩陣 = np.empty((240, 320, 3), dtype=np.uint8)

In [7]: 相機.capture(RGB空矩陣, 'rgb')

In [8]: type(RGB空矩陣)
Out[8]: numpy.ndarray

In [9]: RGB空矩陣.shape
Out[9]: (240, 320, 3)

In [10]: plt.imshow(RGB空矩陣)
Out[10]: <matplotlib.image.AxesImage at 0x6e023a50>

In [11]: plt.show()

In [12]: 

plt320x240