【问题标题】:unable to capture images using python (image gets corrupted)无法使用 python 捕获图像(图像已损坏)
【发布时间】:2021-04-28 05:57:23
【问题描述】:

所以我为 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.

【问题讨论】:

  • 请正确格式化您的代码。不要使用 sn-ps 标记 python 代码。使用 ctrl + k 或将代码括在三个反引号(```)中。

标签: python raspberry-pi raspberry-pi4 picamera


【解决方案1】:

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

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()

【讨论】:

    猜你喜欢
    • 2017-06-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-12-27
    • 2014-10-19
    • 1970-01-01
    • 2018-05-05
    相关资源
    最近更新 更多