라즈베리파이 Global Shutter Camera 적용기

2023. 5. 11. 23:07개발

이번에 출시된 라즈베리파이 글로벌 셔터 카메라(이하 'GS카메라')를 테스트하게 되었다. 참고로 Raspberry Pi 4 Model B에서 진행했다.

기존에 HQ카메라를 사용하던 코드가 돌아갈 거라 기대한 내가 바보다 ㅠㅠ

 

libcamera-hello --list-camera
>> no camera enabled

vcgencmd get_camera
>> supported=1 detected=0

카메라가 인식되지 않는다..;; 

 

Then, please follow the relevant setup instructions for the libcamera software stack, and the Picamera2 Python library.
- https://www.raspberrypi.com/documentation/accessories/camera.html

Picamera2 is the libcamera-based replacement for Picamera which was a Python interface to the Raspberry Pi's legacy camera stack. Picamera2 also presents an easy to use Python API.
- https://github.com/raspberrypi/picamera2

picamera2 라이브러리를 준비해야 한다고 documentation에 새로 명시되어 있었다. GS카메라가 신규 모델이다보니 Legacy가 되어버린 내 picamera 코드에서는 동작하지 않은 모양이다.

 

이제 해결해보자.

sudo apt updapte # 업데이트 정보를 불러온다.
sudo apt upgrade # 불러온 업데이트로 업그레이드한다.

sudo apt install -y python3-picamera2

sudo apt install -y python3-opencv
sudo apt install -y opencv-data

먼저, 상기 커맨드로 라즈베리파이를 최신 상태로 준비한다.

 

Picamera2 is not supported on:
- Images based on Buster or earlier releases.
- Raspberry Pi OS Legacy images.
- Bullseye (or later) images where the legacy camera stack has been re-enabled.

Picamera2는

  • OS Bullseye 이미지에서
  • legacy camera stack 인터페이스가 disable일 때만 지원된다.

실제로 나의 경우에는 legacy camera stack이 enable였기 때문에 카메라가 인식되지 않았던 것 같다.

disable한 후에는 `libcamera-hello --list-camera' 커맨드로 카메라를 확인할 수 있었다.

 

그런데...

libcamera-hello -t 10000 # 10000ms(10초)간 카메라 프리뷰를 켠다.
>> 에러

카메라를 인식했는 데 왜 보질 못하니 ㅠㅠ 이래저래 삽질하다가 해결한 커맨드는 아래와 같다.

libcamera-hello -t 10000 --qt-preview
>> 정상 실행 (프리뷰를 10초간 볼 수 있었다.)

 

The QtGL preview window is not recommended when the image needs to be shown on a remote display (not connected to the Pi).
The main use case for the Qt preview is displaying the preview window on another networked computer using X forwarding, or using the VNC remote desktop software. Under these conditions the 3D-hardware-accelerated implementation either does not work at all, or does not work very well.
- https://datasheets.raspberrypi.com/camera/picamera2-manual.pdf

3.4. Remote preview windows
The preview window can be displayed on a remote display, for example when you have logged in to your Pi over ssh or through VNC. When using ssh:
•You should use the -X parameter (or equivalent) to set up X-forwarding.
•The QtGL (hardware accelerated) preview will not work and will result in an error message. The Qt preview must be used instead, though being software rendered (and presumably travelling over a network), framerates can be expected to be significantly poorer.
When using VNC:
•The QtGL (hardware accelerated) window works adequately if you also have a display connected directly to your Raspberry Pi
•If you do not have a display connected directly to the Pi, the QtGL preview will work very poorly, and the Qt preview window should be used instead
If you are not running, or have suspended, X-Windows on the Pi but still have a display attached, you can log into the Pi without X-forwarding and use the DRM/KMS preview implementation. This will appear on the display that is attached directly to the Pi.
- https://datasheets.raspberrypi.com/camera/picamera2-manual.pdf

문제는 내가 모니터없이 VNC viewer를 통해서 화면을 본다는 점이었다.

VNC viewer와 같은 리모트 디스플레이에서는 기본값(Default)인 QTGL(3D H/W accelerate관련)이 정상적으로 돌아가지 않는다.

 

from picamera2 import Picamera2, Preview

picam2 = Picamera2()

picam2.start_preview(Preview.QTGL) # VNC viewer 하에서는 동작하지 않는다.

# 만약 VNC viewer를 쓴다면,
picam2.start_preview(Preview.QT) # 로 정상 동작할 수 있다.
728x90
반응형