0

I wish to deploy this RPi along with the attached camera module to a factory floor and then analyze the video stream. Hence, I have a headless RPi which I plan to use for this purpose.

Code:

import time
from picamera2 import Picamera2, Preview

picam = Picamera2()

config = picam.create_preview_configuration()
picam.configure(config)

picam.start_preview(Preview.QTGL)

picam.start()
time.sleep(2)
picam.capture_file("test-python.jpg")

picam.close()

Error:

[2:49:33.584694604] [60122]  INFO Camera camera_manager.cpp:297 libcamera v0.0.5+83-bde9b04f
[2:49:33.701068350] [60124]  INFO RPI vc4.cpp:437 Registered camera /base/soc/i2c0mux/i2c@1/imx708@1a to Unicam device /dev/media2 and ISP device /dev/media1
[2:49:33.701156145] [60124]  INFO RPI pipeline_base.cpp:1101 Using configuration file '/usr/share/libcamera/pipeline/rpi/vc4/rpi_apps.yaml'
[2:49:33.708057499] [60122]  INFO Camera camera.cpp:1033 configuring streams: (0) 640x480-XBGR8888 (1) 1536x864-SBGGR10_CSI2P
[2:49:33.708623451] [60124]  INFO RPI vc4.cpp:565 Sensor: /base/soc/i2c0mux/i2c@1/imx708@1a - Selected sensor format: 1536x864-SBGGR10_1X10 - Selected unicam format: 1536x864-pBAA
qt.qpa.xcb: could not connect to display :1.0
qt.qpa.plugin: Could not load the Qt platform plugin "xcb" in "" even though it was found.
This application failed to start because no Qt platform plugin could be initialized. Reinstalling the application may fix this problem.

Available platform plugins are: eglfs, linuxfb, minimal, minimalegl, offscreen, vnc, xcb.

Aborted
3
  • Possible duplicate
    – rkochar
    Sep 14 at 2:33
  • 1
    You appear to be starting preview which requires a desktop. Try setting the headless resolution in config.
    – CoderMike
    Sep 14 at 7:37
  • Thank you @CoderMike, that solved my issue.
    – Skywalker
    Sep 14 at 17:48

1 Answer 1

1

As @CoderMike rightly pointed out, I simply had to write a headless version of the script above.

Even though it was not a big deal, here is the headless version of the script above:

import time
from picamera2 import Picamera2

with Picamera2() as picam:
    picam.start()
    time.sleep(2)
    picam.capture_file("test-python.jpg")

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.