У меня есть просчитанная нейросеть. Я хочу с помощью opencv брать кадры из видео, прогонять их через нейросеть и выводить результат.
cap = cv2.VideoCapture("C:\snow.mp4")
while(True):
ret, frame = cap.read()
cv2.imshow('Video', frame)
# Загружаем изображение
img_path = frame
img = image.load_img(img_path, target_size=(200, 200))
# Преобразуем изображением в массив numpy
x = image.img_to_array(img)
# Инвертируем и нормализуем изображение
x /= 255
x = np2.expand_dims(x, axis=0)
prediction = mod.predict(x)
prediction = np.argmax(prediction[0])
print(classes[prediction])
print(frame)
#print(gray)
if cv2.waitKey(1) & 0xFF == ord('q'):
break
в итоге выходит ошибка
AttributeError Traceback (most recent call last)
~\Anaconda3\envs\q\lib\site-packages\PIL\Image.py in open(fp, mode)
2655 try:
-> 2656 fp.seek(0)
2657 except (AttributeError, io.UnsupportedOperation):
AttributeError: 'numpy.ndarray' object has no attribute 'seek'
During handling of the above exception, another exception occurred:
AttributeError Traceback (most recent call last)
<ipython-input-15-b6889e26cf03> in <module>
5 # Загружаем изображение
6 img_path = frame
----> 7 img = image.load_img(img_path, target_size=(200, 200))
8
9 # Преобразуем изображением в массив numpy
~\Anaconda3\envs\q\lib\site-packages\keras_preprocessing\image\utils.py in load_img(path, grayscale, color_mode, target_size, interpolation)
108 raise ImportError('Could not import PIL.Image. '
109 'The use of `load_img` requires PIL.')
--> 110 img = pil_image.open(path)
111 if color_mode == 'grayscale':
112 if img.mode != 'L':
~\Anaconda3\envs\q\lib\site-packages\PIL\Image.py in open(fp, mode)
2656 fp.seek(0)
2657 except (AttributeError, io.UnsupportedOperation):
-> 2658 fp = io.BytesIO(fp.read())
2659 exclusive_fp = True
2660
AttributeError: 'numpy.ndarray' object has no attribute 'read'
как корректно взять кадр из видео?