개발자/라즈베리파이4

라즈베리파이3 B+ libcamera 설치

지구빵집 2023. 1. 11. 10:10
반응형

 

 

이전 라즈베리파이3 B+ libcamera 설치 문제 해결 포스팅에서 라즈베리파이4 전용 OS인 Bullseye 에서는 이미 libcamera 라이브러리가 들어 있다고 해서 설명 내용은 라즈베리파이4 이하 보드에 라즈베리파이 전용 카메라를 사용하고자 할 때 적용한다는 사실을 말씀드렸다. 

 

카메라 사양 참고자료

 

RPI 8MP CAMERA V2 datashhet.pdf
0.20MB

 

 

 

카메라 사양 참고자료

 

 

 

libcamera 설치 

 

다음 명령으로 libcamera 라이브러리를 설치할 수 있습니다.

 

1. libcamera-install 파일 다운로드 및 설치

 

$git clone https://github.com/waveshare/libcamera-install.git

 

2. 다운로드한 폴더로 이동합니다. 아래 명령어를 차례대로 실행합니다.

 

$cd libcamera-install

 

$sudo chmod +x install_libcamera_all.sh

 

$sudo ./install_libcamera_all.sh

 

설치한 후 "echo "install Succeed" 라인이 출력되면 성공한 것이고, "echo "install Fail" 라인이 출력되면 실패한 것입니다.라고 하지만 사실 이렇게 나오지 않아도 성굥했다. 신경 쓰지 마시길. 저는 아래처럼 메시지가 나왔다.

 

.
.
.
[ 95%] Built target libcamera-jpeg
Scanning dependencies of target libcamera-raw
[ 97%] Building CXX object apps/CMakeFiles/libcamera-raw.dir/libcamera_raw.cpp.o
[100%] Linking CXX executable ../libcamera-raw
[100%] Built target libcamera-raw
 make succeed
-----------------------libcamera End-----------------------

install Succeed 1

 

설치 후 /home/pi/libcamera-install 폴더 아래에 libcamera, libcamera-apps, libepoxy 폴더 세 개가 생성한 것을 확인할 수 있습니다. libcamera를 다시 설치하려면 먼저 이러한 폴더를 검색해야 합니다. 아래 폴더 구조 참고하세요.

 

pi@raspberrypi:~/libcamera-install $ ls
README.md  install_libcamera_all.sh  libcamera  libcamera-apps  libepoxy
pi@raspberrypi:~/libcamera-install $

 

3. 소프트웨어를 다시 시작하십시오.

 

$sudo reboot

 

이렇게 진행해도 잘 돌아가지 않는다. 아래와 같은 에러메시지가 뜨기도 하고

 

pi@raspberrypi:~/libcamera-install/libcamera-apps/build $ ./libcamera-hello
Preview window unavailable
[1:21:23.951805794] [3504]  INFO Camera camera_manager.cpp:299 libcamera v0.0.3+17-c15ff6b5
[1:21:24.453803390] [3505]  WARN RPI raspberrypi.cpp:1270 Mismatch between Unicam and CamHelper for emb
[1:21:24.464102097] [3505] ERROR RPI raspberrypi.cpp:1298 Unicam driver does not use the MediaControlle
[1:21:24.472086647] [3505] ERROR RPI raspberrypi.cpp:1190 Failed to register camera imx219 10-0010: -22
ERROR: *** no cameras available ***
pi@raspberrypi:~/libcamera-install/libcamera-apps/build $

 

카메라가 없다고 나오기도 하는 데 원인은 라즈베리파이 팜 웨어를 업데이트하지 않아서다. 다음 두 명령어를 사용해 libcamera 라이브러리가 실행되도록 한다.

 

1. 먼저 $sudo rpi-update 명령을 실행하여 라즈베리파이 펌웨어를 업데이트한다.

 

참고로 업데이트하면 화면 내용을 아래에 표시한다. 뭔 내용인지 잘 모른다.

 


pi@raspberrypi:~/libcamera-install/libcamera-apps/build $ sudo rpi-update
 *** Raspberry Pi firmware updater by Hexxeh, enhanced by AndrewS and Dom
 *** Performing self-update
 *** Relaunching after update
 *** Raspberry Pi firmware updater by Hexxeh, enhanced by AndrewS and Dom
 *** We're running for the first time
 *** Backing up files (this will take a few minutes)
 *** Backing up firmware
 *** Backing up modules 5.10.103-v7+
#############################################################
WARNING: This update bumps to rpi-5.15.y linux tree
See: https://forums.raspberrypi.com/viewtopic.php?t=322879

'rpi-update' should only be used if there is a specific
reason to do so - for example, a request by a Raspberry Pi
engineer or if you want to help the testing effort
and are comfortable with restoring if there are regressions.

DO NOT use 'rpi-update' as part of a regular update process.
##############################################################
Would you like to proceed? (y/N)
 *** Downloading specific firmware revision (this will take a few minutes)
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0
100  113M  100  113M    0     0  4111k      0  0:00:28  0:00:28 --:--:-- 4254k
 *** Updating firmware
 *** Updating kernel modules
 *** depmod 5.15.84-v7l+
 *** depmod 5.15.84-v8+
 *** depmod 5.15.84+
 *** depmod 5.15.84-v7+
 *** Updating VideoCore libraries
 *** Using HardFP libraries
 *** Updating SDK
 *** Running ldconfig
 *** Storing current firmware revision
 *** Deleting downloaded files
 *** Syncing changes to disk
 *** If no errors appeared, your firmware was successfully updated to dce121783a0dd144306c4672c1fa59dc5
 *** A reboot is needed to activate the new firmware
pi@raspberrypi:~/libcamera-install/libcamera-apps/build $

 

 

2. 리부팅 명령어는 $sudo reboot

3. $sudo raspi-config 라즈베리파이 설정 화면으로 들어가서 "Advanced Options"로 이동하여 "Glamor" 그래픽 가속을 활성화한다. 아래 이미지를 참고한다. 

 

Glamor 그래픽 가속을 활성화
Glamor 그래픽 가속을 활성화
Glamor 그래픽 가속을 활성화

 

이제 libcamera를 이용해서 라즈베리파이 카메라가 정상적으로 동작한다. 나이스!

 

일단 카메라 정보를 출력해 본다. 실행위치를 확인한다. 명령어도 확인한다.

 

pi@raspberrypi:~/libcamera-install/libcamera-apps/build $ ./libcamera-hello --list-cameras
Available cameras
-----------------
0 : imx219 [3280x2464] (/base/soc/i2c0mux/i2c@1/imx219@10)
    Modes: 'SRGGB10_CSI2P' : 640x480 [206.65 fps - (1000, 752)/1280x960 crop]
                             1640x1232 [41.85 fps - (0, 0)/3280x2464 crop]
                             1920x1080 [47.57 fps - (680, 692)/1920x1080 crop]
                             3280x2464 [21.19 fps - (0, 0)/3280x2464 crop]
           'SRGGB8' : 640x480 [206.65 fps - (1000, 752)/1280x960 crop]
                      1640x1232 [41.85 fps - (0, 0)/3280x2464 crop]
                      1920x1080 [47.57 fps - (680, 692)/1920x1080 crop]
                      3280x2464 [21.19 fps - (0, 0)/3280x2464 crop]
pi@raspberrypi:~/libcamera-install/libcamera-apps/build $

 

 

카메라를 테스트하여 5초 동안 미리 보기를 하면 카메라의 아름다운 영상을 볼 수 있다. 명령은 아래와 같다. 멈추는 것은 Ctrl-c를 입력한다. 

 

$cd /home/pi/libcamera-apps/build

 

$./libcamera-hello 

 

다음 명령으로 테스트한다. 멈추기 위해서는 ctrl-c를 입력한다. 동영상 화면을 출력한다.

 

$./libcamera-hello -t 0

 

스틸 이미지 - 픽셀을 지정하여 정지영상을 촬영하는 경우 터미널에서 다음 명령으로 할 수 있습니다. 고급 기능을 사용하려면 libcamera-still 이라는 명령도 있습니다. 

 

$./libcamera-vid -t 5000 -o test.h264 

 

파이썬 프로그램에서 촬영 - 아래의 간단한 Python 프로그램으로 정지 영상을 촬영할 수 있습니다. 

 

from picamera import PiCamera         

camera = PiCamera()                   
camera.capture('/home/pi/photo.jpg')

 

 

참고 내용

 

찾아보니, 라즈베리파이에서 카메라를 사용하려면 Preferences/Raspberry Pi Configuration/Interface에서 Camera를 Enable 하는 등 세팅이 더 필요하다고 언급한다.

공식적으로 Bullseye 버전부터는 카메라를 알아서 detect 해주어 따로 설정이 필요 없다고 하더라.(아래 공식 문서 참고) 이것은 더 이상의 PiCamera Python 라이브러리를 지원하지 않음을 의미한다. 또한, raspicam 역시 지원하지 않게 된다.

하지만 새로운 Bullseye OS는 libcamera 앱이 사전 설치가 되어 enable the camera 같은 작업을 할 필요 없이 바로 카메라 모듈을 연결하여 사진을 찍으면 된다고 한다.

 

 

참고

libcamera 설치 Github

공식문서 bullseye-camera-system

Introducing the Raspberry Pi Cameras - 여기 내용 좋음

라즈베리파이 4 설치 및 카메라 연동 

라즈베리파이 전용 카메라 사용법- 다른 자료 참고하세요.

 

 

More Information

 

 

라즈베리파이3 B+ libcamera 설치

 

 

 

반응형