[英]Capturing image from Webcam Using Python on Windows
我現在使用的代碼是:-
from VideoCapture import Device
cam = Device()
cam.saveSnapshot('image.jpg')
使用py 2.7和導入的pygame和所有視頻捕獲,我在pycharm中收到此錯誤:-
C:\Python27\python.exe F:/Xtraz/Orion/Key-Logger.py
Traceback (most recent call last):
File "F:/Xtraz/Orion/Key-Logger.py", line 3, in <module>
cam.saveSnapshot('image.jpg')
File "C:\Python27\lib\VideoCapture.py", line 200, in saveSnapshot
self.getImage(timestamp, boldfont, textpos).save(filename, **keywords)
File "C:\Python27\lib\VideoCapture.py", line 138, in getImage
im = Image.fromstring('RGB', (width, height), buffer, 'raw', 'BGR', 0, -1)
File "C:\Users\admin\AppData\Roaming\Python\Python27\site-packages\PIL\Image.py", line 2080, in fromstring
"Please call frombytes() instead.")
NotImplementedError: fromstring() has been removed. Please call frombytes() instead.
Process finished with exit code 1
網絡攝像頭LED指示燈點亮,然后立即關閉。 或僅在Windows上與py 2.7和pycharm一起使用的其他代碼和庫幫助我! 我只想保存圖像,而不顯示它!
您可能想降級您的PIL版本,似乎VideoCapture已有一段時間沒有更新,並且仍然依賴於過時的PIL版本。
PIL 2.x似乎有一個正常的fromstring
方法: https : //github.com/python-pillow/Pillow/blob/2.9.0/PIL/Image.py#L750
否則,您可以嘗試將VideoCapture.py
的行138從im = Image.fromstring(...)
更改為im = Image.frombytes(...)
; 希望這是阻止它運行的唯一方法。
如果您使用的是pip
,則可以使用pip uninstall Pillow
卸載當前版本,然后使用pip install Pillow==2.9.0
安裝較舊的版本( Pillow
是PIL的一個分支,PIL基本已死)。
打開文件C:\\Python27\\lib\\VideoCapture.py
並轉到第138行。您應該具有以下內容:
im = Image.fromstring('RGB', (width, height), buffer, 'raw', 'BGR', 0, -1)
將此行替換為:
im = Image.frombytes('RGB', (width, height), buffer, 'raw', 'BGR', 0, -1)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.