IoT 기반의 스마트 CCTV 만들기
손충범
1
01장. 실습 환경 구축 http://cafe.naver.com/thisisWindows
학습 목차
라즈베리파이 소개 및 운영체제 설치
라즈베리파이 카메라 설치 및 설정
CCTV 만들기
Pi 원격관리하기
유무선공유기 설정
MicroSD 메모리 백업
클라우드 저장소 구축하기
2
01장. 실습 환경 구축 http://cafe.naver.com/thisisWindows
라즈베리파이 소개
영국의 라즈베리파이 재단에서 교육 목적으로 만든 SBC(싱글보드컴퓨터).
마이크로프로세서, 메모리, 각종 I/O 장치(오디오, 비디오, 카메라, HDMI)등이 자체
내장.
라즈베리파이 3부터는 와이파이, 블루투스가 기본 내장되어 있음.
라즈베리파이 4는 micro HDMI가 2개로 듀얼 모니터 연결이 가능하며 전원부는
USB-C타입 지원
3
01장. 실습 환경 구축 http://cafe.naver.com/thisisWindows
라즈베리파이 소개
하드웨어 구성
• 64비트 쿼드 코어 프로세서
• 마이크로 HDMI 포트 2개
• 최대 4K 해상도의 듀얼 디스플레이 지원
• 최대 4Kp60의 하드웨어 비디오 디코딩
• 최대 4GB의 RAM
• 듀얼 대역 2.4 / 5.0Ghz 무선 LAN
• Bluetooth 5.0
• 기가비트 이더넷
• USB 3.0 및 PoE 기능 지원
4
01장. 실습 환경 구축 http://cafe.naver.com/thisisWindows
라즈베리파이 운영체제 설치
공식 홈페이지
• https://www.raspberrypi.org/
Raspberry Pi Imager for Windows 운영체제 설치
네트워크 설정
• 유선 또는 무선 네트워크 사용
운영체제 업데이트 및 업그레이드
5
01장. 실습 환경 구축 http://cafe.naver.com/thisisWindows
라즈베리파이 운영체제 설치
라즈비안 운영체제 업데이트 및 업그레이드
• sudo apt-get update
• sudo apt-get upgrade
한글 설정하기 1
• Raspberry Pi Configuration -> Localisation -> Set Timezone -> Asia(Seoul)
• Raspberry Pi Configuration -> Localisation -> Set Keyboard -> korean
6
01장. 실습 환경 구축 http://cafe.naver.com/thisisWindows
라즈베리파이 운영체제 설치
한글 설정하기 2
• sudo apt-get install ibus
• sudo apt-get install ibus-hangul
• sudo apt-get install fonts-unfonts-core
• sudo reboot
7
01장. 실습 환경 구축 http://cafe.naver.com/thisisWindows
라즈베리파이 운영체제 설치
한글 설정하기 3
• sudo apt-get install nabi
• Preferences -> Input Method ->
• Raspberry Pi Configuration -> Localisation -> Set Locale -> ko(UTF-8)
8
01장. 실습 환경 구축 http://cafe.naver.com/thisisWindows
라즈베리파이 운영체제 설치
기타 설정하기
• Raspberry Pi Configuration
• Interface 탭
• Camera, SSH, VNC항목 Enable 선택
• Performance 탭
• GPU Memory 256MB로 입력
9
01장. 실습 환경 구축 http://cafe.naver.com/thisisWindows
라즈베리파이 운영체제 설치
라즈베리 파이 커널 업데이트
• sudo rpi-update
• sudo reboot
10
01장. 실습 환경 구축 http://cafe.naver.com/thisisWindows
라즈베리파이 카메라 설치 및 설정
라즈베리 파이 카메라(Rpi 카메라)
11
01장. 실습 환경 구축 http://cafe.naver.com/thisisWindows
라즈베리파이 카메라 설치 및 설정
라즈베리 파이 카메라(Rpi 카메라) v1.3 스펙
• 5MP 카메라 모듈
• 스틸 사진 해상도 : 2592 x 1944
• 비디오 : 1920x1080p @ 30fps, 1280x720p @ 60fps,
640x480p 60/90fps 레코딩 지원
• 15 핀 MIPI 카메라 직렬 인터페이스(DSI)-Raspberry Pi 보드에 직접 연결
• 크기 : 20 x 25 x 9mm
• 무게 3g
12
01장. 실습 환경 구축 http://cafe.naver.com/thisisWindows
CCTV 법령
13
[공공장소] [사적장소]
• CCTV를공개되지않는사적장소에설치하는경우, 개인정보를수집함에있어서정보주체의동의가필요하고동의를얻음에있어서 CCTV 촬영목적과촬영되는부분촬영된영상의보관기간을미리설명해야하고정보주체에게촬영을거부할권리가있다는것과동의거부에따른불이익이있을경우그불이익의내용을미리알려야함
• CCTV에촬영되는사람들의사전동의를받았다고해도음성은녹음할수없음
01장. 실습 환경 구축 http://cafe.naver.com/thisisWindows
CCTV 만들기
Motion 감지 프로그램 설정하기
• 모션 설치하기 : sudo apt-get install motion
• 모션 설정하기
• sudo nano /etc/motion/motion.conf
• 팁 : nano 편집기 -> 저장(Ctrl+O), 종료(Ctrl+X)
• 모션 실행
• sudo motion -b
14
01장. 실습 환경 구축 http://cafe.naver.com/thisisWindows
CCTV 만들기
Motion 감지 프로그램 설정하기
• 모션 종료
• sudo systemctl stop motion
• CCTV 확인
• 웹브라우저 주소창
• localhost:8081
• IP주소:8081
15
01장. 실습 환경 구축 http://cafe.naver.com/thisisWindows
CCTV 만들기
샘플 영상
16
01장. 실습 환경 구축 http://cafe.naver.com/thisisWindows
와이파이에 고정 IP 설정하기
sudo nano /etc/network/interfaces
interfaces에 다음 추가
allow-hotplug wlan0
iface wlan0 inet static
address 192.168.0.48
netmask 255.255.255.0
gateway 192.168.0.1
wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf
17
01장. 실습 환경 구축 http://cafe.naver.com/thisisWindows
와이파이에 고정 IP 설정하기
sudo systemctl disable dhcpcd
sudo systemctl enable networking
sudo reboot
네트워크 정보 확인 : ifconfig
18
01장. 실습 환경 구축 http://cafe.naver.com/thisisWindows
CCTV 만들기(motion.conf 설정)
# Start in daemon (background) mode and release terminal (default: off)
daemon on
# Rotate image this number of degrees. The rotation affects all saved
images as well as movies. Valid values: 0 (default = no rotation), 90, 180
and 270.
rotate 180
19
01장. 실습 환경 구축 http://cafe.naver.com/thisisWindows
CCTV 만들기(motion.conf 설정)
# Image width (pixels). Valid range: Camera dependent, default: 320
width 640
# Image height (pixels). Valid range: Camera dependent, default: 240
height 480
# Maximum number of frames to be captured per second.
# Valid range: 2-100. Default: 100 (almost no limit).
framerate 100
20
01장. 실습 환경 구축 http://cafe.naver.com/thisisWindows
CCTV 만들기(motion.conf 설정)
# Container/Codec output videos
# Valid values: mpeg4, msmpeg4, swf,flv, ffv1, mov, mp4, mkv, hevc
ffmpeg_video_codec mp4
21
01장. 실습 환경 구축 http://cafe.naver.com/thisisWindows
CCTV 만들기(motion.conf 설정)
# Locate and draw a box around the moving object.
# Valid values: on, off, preview (default: off) 1Set to 'preview' will only draw a box in preview_shot pictures.
locate_motion_mode on
# Set the look and style of the locate box if enabled.
# Valid values: box, redbox, cross, redcross (default: box)
# Set to 'box' will draw the traditional box. # Set to 'redbox' will draw a red box.
# Set to 'cross' will draw a little cross to mark center.
# Set to 'redcross' will draw a little red cross to mark center.
locate_motion_style redbox
22
01장. 실습 환경 구축 http://cafe.naver.com/thisisWindows
CCTV 만들기(motion 설정)
# Target base directory for pictures and films
# Recommended to use absolute path. (Default: current working directory)
target_dir /home/pi/motion
타켓 디렉토리 생성 명령어
• mkdir /home/pi/motion
23
01장. 실습 환경 구축 http://cafe.naver.com/thisisWindows
CCTV 만들기(motion 설정)
# Restrict stream connections to localhost only (default: on)
stream_localhost off
# Set the authentication method (default: 0)
# 0 = disabled
# 1 = Basic authentication
# 2 = MD5 digest (the safer authentication)
stream_auth_method 1
24
01장. 실습 환경 구축 http://cafe.naver.com/thisisWindows
CCTV 만들기(motion 설정)
# Restrict control connections to localhost only (default: on)
webcontrol_localhost off
25
01장. 실습 환경 구축 http://cafe.naver.com/thisisWindows
CCTV 만들기
모션 실행하기
• sudo service motion start
• sudo service motion stop
• 모션 백그라운드로 실행하기
• sudo motion –b
• 데몬 확인하기 : netstat –nlpt
부팅 시 자동 실행 설정
• /etc/rc.local 파일 마지막에 추가
• sudo motion -b
26
01장. 실습 환경 구축 http://cafe.naver.com/thisisWindows
CCTV 만들기
아파치 웹서버 설치하기
• sudo apt-get install apache2
• 환경설정 파일
• /etc/apache2/apach2.conf
• /etc/apache2/sites-enabled/000-default.conf
27
01장. 실습 환경 구축 http://cafe.naver.com/thisisWindows
CCTV 만들기
환경설정 파일
• /etc/apache2/apach2.conf
• <Directory /home/pi/>
• Options Indexes FollowSymLinks
• AllowOverride All
• Require all granted
• </Directory>
• /etc/apache2/sites-enabled/000-default.conf
28
01장. 실습 환경 구축 http://cafe.naver.com/thisisWindows
CCTV 만들기
환경설정 파일
• /etc/apache2/sites-enabled/000-default.conf
• DocumentRoot /home/pi/motion
아파치 암호 설정하기
• sudo apt-get install apache2-utils
• sudo htpasswd -c /home/pi/.htpasswd pi
• sudo htpasswd /home/pi/.htpasswd pi2
29
01장. 실습 환경 구축 http://cafe.naver.com/thisisWindows
CCTV 만들기
sudo vi /etc/apache2/sites-enabled/000-default.conf
<Directory "/home/pi/mp4">
AuthType Basic
AuthName "Password Required"
AuthUserFile /home/pi/.htpasswd
Require valid-user
</Directory>
sudo apache2ctl configtest
Sudo systemctl restart apache2
30
01장. 실습 환경 구축 http://cafe.naver.com/thisisWindows
Pi 원격 관리 설정
라즈베리파이 원격 관리(VNC)
31
01장. 실습 환경 구축 http://cafe.naver.com/thisisWindows
Pi 원격 관리 설정
라즈베리파이 원격 관리(VNC)
32
01장. 실습 환경 구축 http://cafe.naver.com/thisisWindows
유무선 공유기 설정
유무선 공유기를 활용하여 외부에서 CCTV 관리하기
33
01장. 실습 환경 구축 http://cafe.naver.com/thisisWindows
유무선 공유기 설정
유무선 공유기를 활용하여 외부에서 CCTV 관리하기
34
01장. 실습 환경 구축 http://cafe.naver.com/thisisWindows
유무선 공유기 설정
유무선 공유기를 활용하여 외부에서 CCTV 관리하기
35
01장. 실습 환경 구축 http://cafe.naver.com/thisisWindows
MicroSD 메모리 백업
Win32 Disk Imager를 활용하여 MicroSD 메모리 백업
36
백업 복구
01장. 실습 환경 구축 http://cafe.naver.com/thisisWindows
클라우드 저장소 구축하기
Apache2와 SQLite 설치하기
• sudo apt-get install apache2 sqlite
• sudo service apache2 start
PHP 설치하기
• sudo apt-get install php php-gd php-sqlite3 php-curl libapache2-mod-
php
37
01장. 실습 환경 구축 http://cafe.naver.com/thisisWindows
클라우드 저장소 구축하기
Owncloud와 추가로 활용하는 응용
• sudo apt-get install smbclient
PHP 확장 모듈
• sudo apt-get install php-mysql php-mbstring php-gettext php-intl php-
redis php-imagick php-igbinary php-gmp php-curl php-gd php-zip php-
imap php-ldap php-bz2 php-phpseclib php-xml
38
01장. 실습 환경 구축 http://cafe.naver.com/thisisWindows
클라우드 저장소 구축하기
39
owncloud 신뢰할 수있는 키 등록
• sudo wget -nv
https://download.owncloud.org/download/repositories/production/Debia
n_9.0/Release.key -O Release.key
• sudo apt-key add - < Release.key
01장. 실습 환경 구축 http://cafe.naver.com/thisisWindows
클라우드 저장소 구축하기
40
Raspbian에 공식 OwnCloud 패키지 저장소 추가
• sudo vi /etc/apt/sources.list.d/owncloud.list
• deb
http://download.owncloud.org/download/repositories/production/Debia
n_9.0/ /
• sudo apt-get update
01장. 실습 환경 구축 http://cafe.naver.com/thisisWindows
클라우드 저장소 구축하기
41
MariaDB 설치
• sudo apt-get install mariadb-server mariadb-client
데이터베이스 구성
• sudo mysql -u root -p
• create database owncloud;
• CREATE USER IF NOT EXISTS 'owncloud'@'localhost' IDENTIFIED BY '1234';
• GRANT ALL PRIVILEGES ON owncloud.* TO 'owncloud'@'localhost';
• exit
01장. 실습 환경 구축 http://cafe.naver.com/thisisWindows
클라우드 저장소 구축하기
42
ownCloud 설치
• sudo apt-get install owncloud-files
Apache 구성
• Apache 기본 사이트 구성 파일 /etc/apache2/sites-enabled/000-default.conf
• DocumentRoot /var/www/html DocumentRoot /var/www/owncloud
sudo systemctl restart apache2
sudo chown www-data -R /var/www/owncloud
01장. 실습 환경 구축 http://cafe.naver.com/thisisWindows
클라우드 저장소 구축하기
43
웹브라우저 : http://localhost
Top Related