0

I need access to full camera video resolution (1080p) and after searching found that recording (start_recording()) methods of PICamera is much better than capturing methods(capture_continues()) regarding speed (I've done some benchmark).

In the section 5.9. Custom outputs of Advanced Recipes of PICamera documentation the start_recording() seems redirecting camera frames (or what ever) to a custom class.

But the problem is that I don't know how to access/modify frames inside the class. I've used some other methods that people using it when accessing frames through capture_continues() but these codes didn't work. Seems the format of data here (inside class) is differ.

This is the sample code you can use as a custom output solution (that can be found in the PICamera documentation) :

from __future__ import print_function

import picamera

class MyOutput(object):
    def __init__(self):
        self.size = 0

    def write(self, s):
        self.size += len(s)

    def flush(self):
        print('%d bytes would have been written' % self.size)

with picamera.PiCamera() as camera:
    camera.resolution = (640, 480)
    camera.framerate = 60
    camera.start_recording(MyOutput(), format='h264')
    camera.wait_recording(10)
    camera.stop_recording()

This is sample code that I've used inside write method of MyOutput:

data = np.fromstring(s, dtype=np.uint8)
image = cv2.imdecode(data, 1)
cv2.imshow('frame2', image)

And this is returned error:

Xlib:  extension "RANDR" missing on display ":1.0".
OpenCV Error: Bad flag (parameter or structure field) (Unrecognized or unsupported array type) in cvGetMat, file /usr/src/packages/BUILD/opencv-2.4.1+dfsg/modules/core/src/array.cpp, line 2482
Traceback (most recent call last):
  File "home/pi/share/python/cus_out.py", line 32, in <module>
    camera.stop_recording()
  File "/usr/lib/python2.7/dist-packages/picamera/camera.py", line 976, in __exit__
    self.close()
  File "/usr/lib/python2.7/dist-packages/picamera/camera.py", line 955, in close
    self.stop_recording(splitter_port=port)
  File "/usr/lib/python2.7/dist-packages/picamera/camera.py", line 1362, in stop_recording
    self.wait_recording(0, splitter_port)
  File "/usr/lib/python2.7/dist-packages/picamera/camera.py", line 1333, in wait_recording
    encoder.wait(timeout)
  File "/usr/lib/python2.7/dist-packages/picamera/encoders.py", line 853, in wait
    raise self.exception
cv2.error: /usr/src/packages/BUILD/opencv-2.4.1+dfsg/modules/core/src/array.cpp:2482: error: (-206) Unrecognized or unsupported array type in function cvGetMat
2
  • 1
    "I need fast access to full camera video resolution" -> Just in case this is an XY problem, writing your own python program is unlikely to be the most direct route to that goal. If you mean, "...in a python program" then ignore this ;)
    – goldilocks
    Jun 28, 2016 at 11:09
  • 1
    Neat tip about XY problem :D.
    – SAMPro
    Jun 28, 2016 at 12:57

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.