我使用watchdog库来检测在特定文件夹中创建新图像的时间。当watchdog检测到新创建的图像时,我使用SimpleCV/OpenCV启动一些图像处理功能。在
然而,这些照片是从一个树莓派相机拍摄的,从下面的错误我不相信整个图像是保存时,它第一次出现在目录中。(实际上,文件是以“碎片”或多种形式保存的)。在
请注意当我将图像复制并粘贴到相应的文件夹中时,脚本将成功运行。在
询问:是否有任何方法可以仅在保存完整个文件后才启动图像处理?在import time
from SimpleCV import Image
from watchdog.observers import Observer
from watchdog.events import FileSystemEventHandler
class ExampleHandler(FileSystemEventHandler):
def on_created(self, event):
image = Image(event.src_path)
do image processing stuff
print "Got event for file %s" % event.src_path
observer = Observer()
event_handler = ExampleHandler() # create event handler
observer.schedule(event_handler, path='/path/to/images') # set observer to use created handler in directory
observer.start()
# sleep until keyboard interrupt, then stop + rejoin the observer
try:
while True:
time.sleep(1)
except KeyboardInterrupt:
observer.stop()
observer.join()
错误转储:
^{pr2}$
编辑在识别一个新文件后将处理程序更新到休眠状态几秒钟后,我收到一个不同的错误。在class ExampleHandler(FileSystemEventHandler):
def on_created(self, event):
time.sleep(3)
cans = Image(event.src_path)
错误IOError: [Errno 2] No such file or directory: '/path/to/images/test.jpg~'
请注意,我使用以下Pi命令捕获图像:raspistill -o 'test.jpg'