第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問題,去搜搜看,總會(huì)有你想問的

如何保存通過camera.capture_continuous讀取的圖像并將其保存到文件中

如何保存通過camera.capture_continuous讀取的圖像并將其保存到文件中

不負(fù)相思意 2022-05-11 16:26:33
我通過 camera.capture_continuous(stream,format='rgb', use_video_port=True, resize=(width, height) 讀取 raspi 相機(jī),將其饋送到珊瑚邊緣 USB 加速器。這非常有效。但現(xiàn)在我想保存某些圖像(取決于分析)到硬盤。我是 python 初學(xué)者... file.write 沒有用。我假設(shè)是因?yàn)槲业玫搅四撤N原始 rgb 圖像數(shù)據(jù)而不是 jpg。我希望能夠?qū)D像存儲(chǔ)為 jpg。誰能建議使用什么功能?更新我嘗試了以下import argparseimport osimport ioimport timefrom collections import dequeimport numpy as npimport picamerafrom PIL import Imageimport edgetpu.classification.enginedef main():  stream = io.BytesIO()  engine = edgetpu.classification.engine.ClassificationEngine(args.model)  for foo in camera.capture_continuous(stream,                                       format='rgb',                                       use_video_port=True,                                       resize=(width, height)):      stream.truncate()      stream.seek(0)      input = np.frombuffer(stream.getvalue(), dtype=np.uint8)      results = engine.ClassifyWithInputTensor(input, top_k=3)      ...      image = Image.fromarray(input.astype('uint8'), 'RGB')      image.save("imgs/image_" + str(i) + ".jpg")但只得到一個(gè)錯(cuò)誤:Traceback (most recent call last):  File "mio.py", line 85, in <module>    main()  File "mio.py", line 75, in main    image = Image.fromarray(input.astype('uint8'), 'RGB')  File "/usr/lib/python3/dist-packages/PIL/Image.py", line 2529, in fromarray    size = shape[1], shape[0]IndexError: tuple index out of range我究竟做錯(cuò)了什么?
查看完整描述

2 回答

?
偶然的你

TA貢獻(xiàn)1841條經(jīng)驗(yàn) 獲得超3個(gè)贊

您可以使用Pillow庫將圖像保存到磁盤。就像是:


pip install Pillow numpy


import numpy as np

from PIL import Image

pixels = np.array([[[255, 0, 0], [0, 255, 0]], [[0, 0, 255], [255, 255, 0]]])

image = Image.fromarray(pixels.astype('uint8'), 'RGB')

image.save('out.jpg')


查看完整回答
反對(duì) 回復(fù) 2022-05-11
?
搖曳的薔薇

TA貢獻(xiàn)1793條經(jīng)驗(yàn) 獲得超6個(gè)贊

用以下行解決了它

image = Image.frombuffer('RGB', (width,height), streamValue)


查看完整回答
反對(duì) 回復(fù) 2022-05-11
  • 2 回答
  • 0 關(guān)注
  • 275 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)