I'm attempting to write a program that captures a raw stream from the video port and passes it to OpenCV, but the program fails when trying to capture the stream. I know it's possible, because before I switched to using Python, I was using a C++ class that could do this. At least, I think that's what it does.
It's definitely not an OpenCV error, as the program dies before any OpenCV functions are called.
Traceback (most recent call last):
File "main.py", line 122, in <module>
main()
File "main.py", line 117, in main
frame = cam.read()
File "/home/pi/2014-Vision/src/picam.py", line 16, in read
self.cam.capture(stream, 'rgba', True, (320, 240))
File "/usr/lib/python2.7/dist-packages/picamera/camera.py", line 859, in capture
if not encoder.wait(30):
File "/usr/lib/python2.7/dist-packages/picamera/encoders.py", line 326, in wait
raise self.exception
AssertionError
from __future__ import division
import picamera
import cv2
import numpy as np
import io
import time
class PiCam:
def __init__(self):
self.cam = picamera.PiCamera()
def read(self):
stream = open('image.data', 'wb')
self.cam.capture(stream, 'bgra', True, (320, 240))
image = np.fromfile(stream, dtype = np.uint8)
return image
cam = PiCam()
cv2.namedWindow("Camera Image", cv2.WINDOW_AUTOSIZE)
while True:
cv2.imshow("Camera Image", cam.read())
cv2.waitKey(1)
return