0

所以我为 hq 相机制作了一个相机应用程序,但我无法在我的树莓派 4 上拍摄任何类型的照片!

from guizero import App, PushButton
from picamera import PiCamera

camera = PiCamera()

app = App()
def preview():
    camera.start_preview(fullscreen=False, window = (50,150,2048,1152))
    
button = PushButton(app, command=preview, text="preview")
def stop_preview():
    camera.stop_preview()
    
button = PushButton(app, command=stop_preview, text="stop preview")
def shutter():
    camera.capture('/home/pi/Desktop/image.jpg')
    
button = PushButton(app, command=shutter, text="shutter")
app.display()

但由于某种原因,我得到了这个错误!

mmal: mmal_vc_port_enable: failed to enable port vc.ril.image_encode:out:0(JPEG): ENOMEM
mmal: mmal_port_enable: failed to enable port vc.ril.image_encode:out:0(JPEG)(0x1e258a0) (ENOMEM)
Exception in Tkinter callback
Traceback (most recent call last):
  File "/usr/lib/python3.7/tkinter/__init__.py", line 1705, in __call__
    return self.func(*args)
  File "/home/pi/.local/lib/python3.7/site-packages/guizero/PushButton.py", line 206, in _command_callback
    self._command()
  File "/home/pi/Desktop/James Strand Camera", line 16, in shutter
    camera.capture('/home/pi/Desktop/image.jpg')
  File "/usr/lib/python3/dist-packages/picamera/camera.py", line 1418, in capture
    encoder.start(output)
  File "/usr/lib/python3/dist-packages/picamera/encoders.py", line 1126, in start
    super(PiCookedOneImageEncoder, self).start(output)
  File "/usr/lib/python3/dist-packages/picamera/encoders.py", line 377, in start
    self.output_port.enable(self._callback)
  File "/usr/lib/python3/dist-packages/picamera/mmalobj.py", line 1249, in enable
    prefix="Unable to enable port %s" % self.name)
  File "/usr/lib/python3/dist-packages/picamera/exc.py", line 184, in mmal_check
    raise PiCameraMMALError(status, prefix)
picamera.exc.PiCameraMMALError: Unable to enable port vc.ril.image_encode:out:0: Out of memory

我也尝试让代码单独捕获!

from picamera import PiCamera
from time import sleep

camera = PiCamera()

camera.start_preview()
sleep(5)
camera.capture('/home/pi/Desktop/image.jpg')
camera.stop_preview()

注意!:尝试获取错误代码,但执行后我卡在预览中!但否则没有预览我明白了!

mmal: mmal_vc_port_enable: failed to enable port vc.ril.image_encode:out:0(JPEG): ENOMEM
mmal: mmal_port_enable: failed to enable port vc.ril.image_encode:out:0(JPEG)(0x9a5a60) (ENOMEM)

Backend terminated or disconnected. Use 'Stop/Restart' to restart.
4

1 回答 1

0

没关系,我让它工作了!这是我的代码!

from picamera import PiCamera

camera = PiCamera()
camera.resolution = (1920, 1080)

app = App()
def preview():
    camera.start_preview(fullscreen=False, window = (50,150,2048,1152))
    
button = PushButton(app, command=preview, text="preview")
def stop_preview():
    camera.stop_preview()
    
button = PushButton(app, command=stop_preview, text="stop preview")
def shutter():
    camera.capture('/home/pi/Desktop/image.jpg')
    
button = PushButton(app, command=shutter, text="shutter")
app.display()
于 2021-01-24T07:57:32.943 回答