|
| 1 | +import time |
| 2 | +from picamera import PiCamera |
| 3 | +import numpy as np |
| 4 | +import matplotlib.pyplot as plt |
| 5 | + |
| 6 | +t1 = time.time() |
| 7 | +h = 640 # change this to anything < 2592 (anything over 2000 will likely get a memory error when plotting |
| 8 | +cam_res = (int(h),int(0.75*h)) # keeping the natural 3/4 resolution of the camera |
| 9 | +cam_res = (int(16*np.floor(cam_res[1]/16)),int(32*np.floor(cam_res[0]/32))) |
| 10 | +cam = PiCamera() |
| 11 | +cam.resolution = (cam_res[1],cam_res[0]) |
| 12 | +data = np.empty((cam_res[0],cam_res[1],3),dtype=np.uint8) |
| 13 | +x,y = np.meshgrid(np.arange(np.shape(data)[1]),np.arange(0,np.shape(data)[0])) |
| 14 | +cam.capture(data,'rgb') |
| 15 | +fig,axn = plt.subplots(2,2,sharex=True,sharey=True) |
| 16 | +fig.set_size_inches(9,7) |
| 17 | +axn[0,0].pcolormesh(x,y,data[:,:,0],cmap='gray') |
| 18 | +axn[0,1].pcolormesh(x,y,data[:,:,1],cmap='gray') |
| 19 | +axn[1,0].pcolormesh(x,y,data[:,:,2],cmap='gray') |
| 20 | +axn[1,1].imshow(data,label='Full Color') |
| 21 | +axn[0,0].title.set_text('Red') |
| 22 | +axn[0,1].title.set_text('Green') |
| 23 | +axn[1,0].title.set_text('Blue') |
| 24 | +axn[1,1].title.set_text('All') |
| 25 | +print('Time to plot all images: {0:2.1f}'.format(time.time()-t1)) |
| 26 | +data = np.empty((cam_res[0],cam_res[1],3),dtype=np.uint8) |
| 27 | +plt.savefig('component_plot.png',dpi=150) |
| 28 | +plt.cla() |
| 29 | +plt.close() |
0 commit comments