from VideoCapture import Device import time, string interval = 2 cam = Device(devnum=0, showVideoWindow=0) # cam.setResolution(648, 480) cam.saveSnapshot('image.jpg', timestamp=3, boldfont=1, quality=75) i = 0 quant = interval * .1 starttime = time.time() while 1: lasttime = now = int((time.time() - starttime) / interval) print(i) cam.saveSnapshot('image.jpg', timestamp=3, boldfont=1) i += 1 while now == lasttime: now = int((time.time() - starttime) / interval) time.sleeqp(quant)运行后出现如下错误:
D:\Python\python3.exe "D:/PyCharm files/face/other_try/text.py"
Traceback (most recent call last):File "D:/PyCharm files/face/other_try/text.py", line 9, in <module>
cam.saveSnapshot('image.jpg', timestamp=3, boldfont=1, quality=75)
File "D:\Python\lib\site-packages\VideoCapture\__init__.py", line 234, in saveSnapshot
self.getImage(timestamp, boldfont, textpos).save(filename, **keywords)
File "D:\Python\lib\site-packages\VideoCapture\__init__.py", line 154, in getImage
'RGB', (width, height), buffer, 'raw', 'BGR', 0, -1)
File "D:\Python\lib\site-packages\PIL\Image.py", line 2342, in fromstring
"Please call frombytes() instead.")
NotImplementedError: fromstring() has been removed. Please call frombytes() instead.
解决:
首先找到"D:\Python\lib\site-packages\PIL\Image.py"文件的2341行,会发现代码如下,用raise报出NotImplementedError错误,而NotImplementedError表示没有实现的错误。可能由于版本更新的问题,fromstring()这个函数已经不存在了,需要把遇到的fromstring修改成frombytes。
然后按照错误继续往上找,找到"D:\Python\lib\site-packages\VideoCapture\__init__.py"文件,把153行的fromstring修改成frombytes即可。
这里附上另外一篇博客https://blog.csdn.net/grey_csdn/article/details/77074707,对于NotImplementedError的使用和理解有很大的帮助。