我写了这个短代码用相机拍摄照片。它工作正常 - 我有问题显示(以及后来关闭)我刚刚做的图像。我正在使用newest = max(glob.iglob('*.jpg'), key=os.path.getctime)
找到我刚才所做的图片 - 现在我要打开并显示无效的图片im = Image.open(newest)
im.show()
- 有什么建议吗?
import Image
import picamera
import time
import sys
import datetime
import RPi.GPIO as GPIO
import glob
import os
GPIO.setmode(GPIO.BCM)
GPIO.setup(16, GPIO.IN, pull_up_down=GPIO.PUD_UP)
GPIO.setup(18, GPIO.IN, pull_up_down=GPIO.PUD_UP)
now = datetime.datetime.now()
camera = picamera.PiCamera()
camera.resolution = (1920, 1080)
camera.framerate = 24
camera.start_preview()
while True:
input_state=GPIO.input(16)
input_state2=GPIO.input(18)
if input_state == False:
zahlen = [4,3,2,1,0]
for i in zahlen:
camera.annotate_text = '' + str(i+1)
n = i+1
print n
time.sleep(1)
camera.annotate_text = ''
camera.capture('Hausmesse_' + str(now.hour) + ':' + str(now.minute) + ':' + str(now.second) + '.jpg')
newest = max(glob.iglob('*.jpg'), key=os.path.getctime)
im = Image.open(newest)
im.show()
time.sleep(5)
if input_state2 == False:
#time.sleep(5)
sys.exit()
编辑:
我尝试使用matplotlib
- 它为我提供了图片image=mplImage.imread(newest)
的数据,但没有使用plt.imshow(image)
[[[125 106 128]
[123 106 125]
[117 103 120]
...,
[157 133 147]
[155 131 145]
[154 130 144]]
[[129 110 132]
[126 109 128]
[116 103 120]
...,
[154 130 144]
[154 130 144]
[159 135 149]]
[[127 109 131]
[124 109 130]
[118 105 123]
...,
[157 133 146]
[155 129 145]
[155 131 145]]
...,
[[130 129 134]
[127 126 131]
[124 122 125]
...,
[211 206 203]
[210 205 202]
[209 204 201]]
[[128 126 131]
[126 124 129]
[133 128 134]
...,
[209 203 203]
[209 203 203]
[212 206 206]]
[[135 133 138]
[130 128 133]
[129 124 130]
...,
[210 204 204]
[210 204 204]
[212 206 206]]]
答案 0 :(得分:0)
我没有太多使用Image的经验,但我会指向MatPlotLib。 (见http://matplotlib.org/users/image_tutorial.html)。
一个简单的示例是您可以将图像作为数组(甚至是存储的文件):
import matplotlib.pyplot as plt
import matplotlib.image as mplImage
# If image is not already an array then:
image=mplImage.imread('testimage.png')
plt.imshow(image)