1.라즈베리파이 카메라
라즈베리파이 전용 카메라는 2013년도에 500만 pixel용 V1이 출시된 이후 2016년도에는 800만 pixel용 V2이 출시되었고 2020년도에는 1200만 pixel용 High Quality Camera가 출시되었다. V1과 V2는 동일한 사이즈의 소형 카메라 모듈 형태이지만 High Quality Cameras는 비교적 큰사이즈로 렌즈교환이 가능한 형태이다.
2.라즈베리파이 카메라 사양
Model Raspberry pi camera V1 Raspberry pi camera V2 Raspberry pi camera HQ Photo Net price $25 $25 $50 Size Around 25 × 24 × 9 mm Around 25 × 24 × 9 mm 38 x 38 x 18.4mm (excluding lens) Weight 3g 3g Still resolution 5 Megapixels 8 Megapixels 12.3 Megapixels Video modes 1080p30, 720p60 and 640 × 480p60/90 1080p30, 720p60 and 640 × 480p60/90 1080p30, 720p60 and 640 × 480p60/90 Linux integration V4L2 driver available V4L2 driver available V4L2 driver available C programming API OpenMAX IL and others available OpenMAX IL and others available Sensor OmniVision OV5647 Sony IMX219 Sony IMX 477 Sensor resolution 2592 × 1944 pixels 3280 × 2464 pixels 4056 x 3040 pixels Sensor image area 3.76 × 2.74 mm 3.68 x 2.76 mm (4.6 mm diagonal) 6.287mm x 4.712 mm (7.9mm diagonal) Pixel size 1.4 µm × 1.4 µm 1.12 µm x 1.12 µm 1.55 µm x 1.55 µm Optical size 1/4″ 1/4″ Full-frame SLR lens equivalent 35 mm S/N ratio 36 dB Dynamic range 67 dB @ 8x gain Sensitivity 680 mV/lux-sec Dark current 16 mV/sec @ 60 C Well capacity 4.3 Ke- Fixed focus 1 m to infinity N/A Focal length 3.60 mm +/- 0.01 3.04 mm Depends on lens Horizontal field of view 53.50 +/- 0.13 degrees 62.2 degrees Depends on lens Vertical field of view 41.41 +/- 0.11 degrees 48.8 degrees Depends on lens Focal ratio (F-Stop) 2.9 2.0 Depends on lens
위 표에서는 버전 별로 25달러에서 50달러로 큰 가격차이가 없는 것처럼 보이지만, V1은 중국산 복제품이 많아 훨씬 싼 가격 (5달러 미만)에 구매할 수 있고, High Quality Camera는 렌즈를 별도로 구매해야 하므로 2배이상 비용이 소요된다.
그리고 구매시 주의해야 할 사항은 야간 촬영용으로 IR필터를 제거한 NOIR 버전도 함께 판매되므로 용도에 맞추어 선택해야 한다. 아래 사진의 왼쪽 녹색은 IR필터가 포함된 일반적인 촬영용이고 오른쪽 검정색은 야간에 적외선 불빛을 주어 야간촬영이 가능하도록 IR 필터를 제거한 NOIR 버전이다.
야간 촬영용으로 아래와 같이 NOIR 버전 카메라에 전용 적외선 조명장치까지 부착하여 판매되는 경우도 있다.
3.라즈베리파이 카메라 사용방법
1) 카메라 모듈 연결
위그림과 같이 보드의 카메라 아답터 검정색부분을 살짝 밀어 올려 틈을 벌린 후 케이블을 삽입한 후 다시 눌러 고정시켜 주면 된다.
2) 라즈베리파이 설정
라즈베리파이 데스크탑 메뉴에서 Preferences -> Raspberry Configuration을 선택하면 아래와 같이 환경설정화면이 표시되는데 2번째 탭에 있는 Camera를 Enable로 선택하고 Rebooting하면 된다.
만약 SSH등으로 원격접속하여 라즈베리파이 데스크탑 화면을 띄울 수 없는 경우라면 다음 명령어를 입력하여 텍스트버전 환경설정화면을 호출하여 작업할 수도 있다.
sudo raspi-config
3번째의 Interface Option을 선택한 후 표시되는 아래 화면에서 P1 Camera 메뉴를 선택한다
아래 화면이 표시될 때 yes를 선택하여 Enable시키면 된다.
3) 촬영방법 : 터미널창을 호출하여 다음 명령어를 입력해 주면 된다
– 정지화면(Stillcut) 촬영 : raspistill option
option에는 여러가지가 있으나 대표적인 것은 다음과 같다 .
-o file명 : 저장할 파일 명
예를 들어 raspistill -o test.png 라는 명령은 스틸컷 사진을 찍어 test.png라는 파일로 저장하라는 명령이다
-t 지연시간 : 지연시간 (밀리세컨드 단위) 이후에 촬영하라는 명령이다. ( 생략치는 2000미리세컨드 = 2초)
예) raspistill -t 5000 -o test.png라는 명령은 5초후에 촬영하여 test.png라는 파일로 저장하라는 명령
-w 가로크기 -h 세로크기 : 지정하는 가로 세로크기 사이즈로 촬영하라는 명령이다
예) raspistill -o aa.png -w 640 -h 400 : 가로 640px 세로 480px 사이즈로 촬영하여 aa.jpg 로 저장
– 동영상촬영 : raspivid option
option은 raspistill 과 비슷하나 Default size는 1920×1080 px 이다.
-t 시간 : 지정 시간 (밀리세컨드 단위)동안 촬영하라는 명령이다.
-f framerate : 지정하는 framerate 속도로 촬영
예 ) raspivid -t 10000 -o video.h264 -f 30 : 30 frame/sec 품질로 10초간 촬영하여 video.h264라는 file로 저장하라는 명령이다.
4. 문제해결 :
1) V1카메라는 작동되는데 V2 카메라가 안되는 경우 : 라즈베리파이 펌웨어가 V2 카메라 기능 이전일 경우가
있으므로 라즈베리파이 터미널창에서 다음 명령을 입력하여 라즈베리파이 펌웨어를 최신판으로 Update해 준다.
sudo apt-get-update
sudo apt-get-upgrade
2) 초점이 맞지 않는 경우 : 촬영대상이 너무 멀거나 너무 가까워서 흐릿하게 활영되거나, 구매 초기시에 부터 초점조절이 되어있지 않아 흐릿하게 나오는 경우가 있는데 카메라 렌즈를 돌려 초점을 미세조절할 수 있다.
카메라 구매시 박스안에는 위 사진과 같은 둥근 프라스틱이 있는데 이것이 초점 미세조정용 기구이다. 위 사진에서와 같이 이기구를 카메라렌즈 위에 끼워서 좌우로 조그씩 돌려가며 초점을 미세조절할 수 있다. 만약 이 기구가 없으면 아래와 같이 핀셋으로 잡고 돌려서 조정할 수도 있는데 핀셋끝으로 렌즈 표면을 긁지 않도록 조심해야 한다.
구매좌표 :
-해외직구
-국내 https://link.coupang.com/a/j8g8B
쿠팡 파트너스 활동의 일환으로, 이에 따른 일정액의 수수료를 제공받을 수 있습니다.
Sets burst capture mode. This prevents the camera from returning to preview mode in between captures, meaning that captures can be taken closer together.
The camera is run for the requested time ( -t ), and a capture can be initiated throughout that time by sending a USR1 signal to the camera process. This can be done using the kill command. You can find the camera process ID using the pgrep raspistill command.
The camera is run for the requested time ( -t ), and a capture can be initiated throughout that time by pressing the Enter key. Pressing X then Enter will exit the application before the timeout is reached. If the timeout is set to 0, the camera will run indefinitely until the user presses X then Enter. Using the verbose option ( -v ) will display a prompt asking for user input, otherwise no prompt is displayed.
This runs the preview window using the full resolution capture mode. Maximum frames per second in this mode is 15fps, and the preview will have the same field of view as the capture. Captures should happen more quickly, as no mode change should be required. This feature is currently under development.
Applies real-time EXIF information from any attached GPS dongle (using GSPD) to the image; requires libgps.so to be installed.
Setting –exif none will prevent any EXIF information being stored in the file. This reduces the file size slightly.
Note that a small subset of these tags will be set automatically by the camera system, but will be overridden by any EXIF options on the command line.
would set the longitude to 5 degs, 10 minutes, 15 seconds. See EXIF documentation for more details on the range of tags available; the supported tags are as follows:
Allows the insertion of specific EXIF tags into the JPEG image. You can have up to 32 EXIF tag entries. This is useful for tasks like adding GPS metadata. For example, to set the longitude:
Sets the JPEG restart marker interval to a specific value. Can be useful for lossy transport streams because it allows a broken JPEG file to still be partially displayed.
Valid options are jpg , bmp , gif , and png . Note that unaccelerated image types (GIF, PNG, BMP) will take much longer to save than jpg, which is hardware accelerated. Also note that the filename suffix is completely ignored when deciding the encoding of a file.
This options cycles through the range of camera options. No capture is taken, and the demo will end at the end of the timeout period, irrespective of whether all the options have been cycled. The time between cycles should be specified as a millisecond value.
if –thumb none is specified, no thumbnail information will be placed in the file. This reduces the file size slightly.
Allows specification of the thumbnail image inserted into the JPEG file. If not specified, defaults are a size of 64×48 at quality 35.
Instead of a simple frame number, the timelapse file names will use a single number which is the Unix timestamp, i.e. the seconds since 1970.
Instead of a simple frame number, the timelapse file names will use a date/time value of the format aabbccddee , where aa is the month, bb is the day of the month, cc is the hour, dd is the minute, and ee is the second.
Specifies the first frame number in the timelapse. Useful if you have already saved a number of frames, and want to start again at the next frame.
If a time-lapse value of 0 is entered, the application will take pictures as fast as possible. Note that there’s an minimum enforced pause of 30ms between captures to ensure that exposure calculations can be made.
Note that the %04d indicates a 4-digit number, with leading zeroes added to make the required number of digits. So, for example, %08d would result in an 8-digit number.
The specific value is the time between shots in milliseconds. Note that you should specify %04d at the point in the filename where you want a frame count number to appear. So, for example, the code below will produce a capture every 2 seconds, over a total period of 30s, named image0001.jpg , image0002.jpg and so on, through to image0015.jpg .
If set to 0, the preview will run indefinitely, until stopped with CTRL-C. In this case no capture is made.
The program will run for the specified length of time, entered in milliseconds. It then takes the capture and saves it if an output is specified. If a timeout value is not specified, then it is set to 5 seconds (-t 5000). Note that low values (less than 500ms, although it can depend on other settings) may not give enough time for the camera to start up and provide enough frames for the automatic algorithms like AWB and AGC to provide accurate results.
Makes a file system link under this name to the latest frame.
Specifies the output filename. If not specified, no file is saved. If the filename is ‘-‘, then all output is sent to stdout.
This option inserts the raw Bayer data from the camera into the JPEG metadata.
raspivid
Copy to Clipboard –width, -w Set image width
Width of resulting video. This should be between 64 and 1920.
Copy to Clipboard –height, -h Set image height
Height of resulting video. This should be between 64 and 1080.
Copy to Clipboard –bitrate, -b Set bitrate
Use bits per second, so 10Mbps would be -b 10000000 . For H264, 1080p30 a high quality bitrate would be 15Mbps or more. Maximum bitrate is 25Mbps ( -b 25000000 ), but much over 17Mbps won’t show noticeable improvement at 1080p30.
Copy to Clipboard –output, -o Output filename
Specify the output filename. If not specified, no file is saved. If the filename is ‘-‘, then all output is sent to stdout.
To connect to a remote IPv4 host, use tcp or udp followed by the required IP Address. e.g. tcp://192.168.1.2:1234 or udp://192.168.1.2:1234 .
To listen on a TCP port (IPv4) and wait for an incoming connection use –listen (-l) option, e.g. raspivid -l -o tcp://0.0.0.0:3333 will bind to all network interfaces, raspivid -l -o tcp://192.168.1.1:3333 will bind to a local IPv4.
Copy to Clipboard –listen, -l
When using a network connection as the data sink, this option will make the system wait for a connection from the remote system before sending data.
Copy to Clipboard –verbose, -v Output verbose information during run
Outputs debugging/information messages during the program run.
Copy to Clipboard –timeout, -t Time before the camera takes picture and shuts down
The total length of time that the program will run for. If not specified, the default is 5000ms (5 seconds). If set to 0, the application will run indefinitely until stopped with Ctrl-C.
Copy to Clipboard –demo, -d Run a demo mode
This options cycles through the range of camera options. No recording is done, and the demo will end at the end of the timeout period, irrespective of whether all the options have been cycled. The time between cycles should be specified as a millisecond value.
Copy to Clipboard –framerate, -fps Specify the frames per second to record
At present, the minimum frame rate allowed is 2fps, and the maximum is 30fps. This is likely to change in the future.
Copy to Clipboard –penc, -e Display preview image after encoding
Switch on an option to display the preview after compression. This will show any compression artefacts in the preview window. In normal operation, the preview will show the camera output prior to being compressed. This option is not guaranteed to work in future releases.
Copy to Clipboard –intra, -g Specify the intra refresh period (key frame rate/GoP)
Sets the intra refresh period (GoP) rate for the recorded video. H264 video uses a complete frame (I-frame) every intra refresh period, from which subsequent frames are based. This option specifies the number of frames between each I-frame. Larger numbers here will reduce the size of the resulting video, and smaller numbers make the stream less error-prone.
Copy to Clipboard –qp, -qp Set quantisation parameter
Sets the initial quantisation parameter for the stream. Varies from approximately 10 to 40, and will greatly affect the quality of the recording. Higher values reduce quality and decrease file size. Combine this setting with a bitrate of 0 to set a completely variable bitrate.
Copy to Clipboard –profile, -pf Specify H264 profile to use for encoding
Sets the H264 profile to be used for the encoding. Options are:
baseline
main
high
Copy to Clipboard –level, -lev
Specifies the H264 encoder level to use for encoding. Options are 4 , 4.1 , and 4.2 .
Copy to Clipboard –irefresh, -if
Sets the H264 intra-refresh type. Possible options are cyclic , adaptive , both , and cyclicrows .
Copy to Clipboard –inline, -ih Insert PPS, SPS headers
Forces the stream to include PPS and SPS headers on every I-frame. Needed for certain streaming cases e.g. Apple HLS. These headers are small, so don’t greatly increase the file size.
Copy to Clipboard –spstimings, -stm
Insert timing information into the SPS block.
Copy to Clipboard –timed, -td Do timed switches between capture and pause
This options allows the video capture to be paused and restarted at particular time intervals. Two values are required: the on time and the off time. On time is the amount of time the video is captured, and off time is the amount it is paused. The total time of the recording is defined by the timeout option. Note that the recording may take slightly over the timeout setting depending on the on and off times.
For example:
Copy to Clipboard raspivid -o test.h264 -t 25000 -timed 2500,5000
will record for a period of 25 seconds. The recording will be over a timeframe consisting of 2500ms (2.5s) segments with 5000ms (5s) gaps, repeating over the 20s. So the entire recording will actually be only 10s long, since 4 segments of 2.5s = 10s separated by 5s gaps. So:
2.5 record — 5 pause – 2.5 record — 5 pause – 2.5 record — 5 pause — 2.5 record
gives a total recording period of 25s, but only 10s of actual recorded footage.
Copy to Clipboard –keypress, -k Toggle between record and pause on Enter keypress
On each press of the Enter key, the recording will be paused or restarted. Pressing X then Enter will stop recording and close the application. Note that the timeout value will be used to signal the end of recording, but is only checked after each Enter keypress; so if the system is waiting for a keypress, even if the timeout has expired, it will still wait for the keypress before exiting.
Copy to Clipboard –signal, -s Toggle between record and pause according to SIGUSR1
Sending a USR1 signal to the raspivid process will toggle between recording and paused. This can be done using the kill command, as below. You can find the raspivid process ID using pgrep raspivid .
kill -USR1
Note that the timeout value will be used to indicate the end of recording, but is only checked after each receipt of the SIGUSR1 signal; so if the system is waiting for a signal, even if the timeout has expired, it will still wait for the signal before exiting.
Copy to Clipboard –split, -sp
When in a signal or keypress mode, each time recording is restarted, a new file is created.
Copy to Clipboard –circular, -c
Select circular buffer mode. All encoded data is stored in a circular buffer until a trigger is activated, then the buffer is saved.
Copy to Clipboard –vectors, -x
Turns on output of motion vectors from the H264 encoder to the specified file name.
Copy to Clipboard –flush, -fl
Forces a flush of output data buffers as soon as video data is written. This bypasses any OS caching of written data, and can decrease latency.
Copy to Clipboard –save-pts, -pts
Saves timestamp information to the specified file. Useful as an input file to mkvmerge .
Copy to Clipboard –codec, -cd
Specifies the encoder codec to use. Options are H264 and MJPEG . H264 can encode up to 1080p, whereas MJPEG can encode up to the sensor size, but at decreased framerates due to the higher processing and storage requirements.
Copy to Clipboard –initial, -i Define initial state on startup
Define whether the camera will start paused or will immediately start recording. Options are record or pause . Note that if you are using a simple timeout, and initial is set to pause , no output will be recorded.
Copy to Clipboard –segment, -sg Segment the stream into multiple files
Rather than creating a single file, the file is split into segments of approximately the number of milliseconds specified. In order to provide different filenames, you should add %04d or similar at the point in the filename where you want a segment count number to appear e.g:
Copy to Clipboard –segment 3000 -o video%04d.h264
will produce video clips of approximately 3000ms (3s) long, named video0001.h264 , video0002.h264 etc. The clips should be seamless (no frame drops between clips), but the accuracy of each clip length will depend on the intraframe period, as the segments will always start on an I-frame. They will therefore always be equal or longer to the specified period.
The most recent version of Raspivid will also allow the file name to be time-based, rather than using a segment number. For example:
Copy to Clipboard –segment 3000 -o video_%c.h264
will produce file names formatted like so: video_Fri Jul 20 16:23:48 2018.h264
There are many different formatting options available. Note than the %d and %u options are not available, as they are used for the segment number formatting, and that some combinations may produce invalid file names.
Copy to Clipboard –wrap, -wr Set the maximum value for segment number
When outputting segments, this is the maximum the segment number can reach before it’s reset to 1, giving the ability to keep recording segments, but overwriting the oldest one. So if set to 4, in the segment example above, the files produced will be video0001.h264 , video0002.h264 , video0003.h264 , and video0004.h264 . Once video0004.h264 is recorded, the count will reset to 1, and video0001.h264 will be overwritten.
Copy to Clipboard –start, -sn Set the initial segment number
When outputting segments, this is the initial segment number, giving the ability to resume a previous recording from a given segment. The default value is 1.
Copy to Clipboard –raw, -r
Specify the output file name for any raw data files requested.
Copy to Clipboard –raw-format, -rf