所以我有两个版本的Picamera拍照。 当我跑步时,这一功能有效。
import cameraTrigger as ct
from picamera import PiCamera
import time
n=1
TOTAL_PICS=30
while n <= TOTAL_PICS:
img = ct.takePic()
n+=1
cameraTrigger.py
import time
import socket
import pickle as p
import numpy as np
import cv2
from picamera import PiCamera
from common import constantSource as cs
camera = PiCamera()
size = cs.getImageSize()
camera.resolution = size
def takePic(path=None):
if path is not None:
start = time.time()
camera.capture(path)
end = time.time()
print("Trigger time: " + str(end-start))
data = None
elif path is None:
start = time.time()
data = np.empty((size[1], size[0], 3), dtype=np.uint8)
camera.capture(data, "bgr")
end = time.time()
print("Trigger time: " + str(end-start))
return data
但是,这个(集成脚本)不起作用。它停在第3行(相机= PiCamera())。
from picamera import PiCamera
import time
camera = PiCamera()
camera.resolution = (720,560)
time.sleep(2.0)
n=1
TOTAL_PICS=30
while n <= TOTAL_PICS:
img = np.empty((560,720,3),dtype=np.uint8)
camera.capture(img,"bgr")
n+=1
出现此错误
mmal: mmal_vc_port_enable: failed to enable port vc.null_sink:in:0(OPQV): ENOSPC
mmal: mmal_port_enable: failed to enable connected port (vc.null_sink:in:0(OPQV))0x10ad0a0 (ENOSPC)
mmal: mmal_connection_enable: output port couldn't be enabled
Traceback (most recent call last):
File "stereoCalibration_pi.py", line 17, in <module>
left = PiCamera()
File "/home/pi/.virtualenvs/cv/local/lib/python3.5/site-packages/picamera/camera.py", line 433, in __init__
self._init_preview()
File "/home/pi/.virtualenvs/cv/local/lib/python3.5/site-packages/picamera/camera.py", line 513, in _init_preview
self, self._camera.outputs[self.CAMERA_PREVIEW_PORT])
File "/home/pi/.virtualenvs/cv/local/lib/python3.5/site-packages/picamera/renderers.py", line 558, in __init__
self.renderer.inputs[0].connect(source).enable()
File "/home/pi/.virtualenvs/cv/local/lib/python3.5/site-packages/picamera/mmalobj.py", line 2212, in enable
prefix="Failed to enable connection")
File "/home/pi/.virtualenvs/cv/local/lib/python3.5/site-packages/picamera/exc.py", line 184, in mmal_check
raise PiCameraMMALError(status, prefix)
picamera.exc.PiCameraMMALError: Failed to enable connection: Out of resources
我遇到错误的原因是什么?谢谢您的提前帮助!