Raspberry Pi - Adafruit PiUART

OS/Raspberry Pi 2017.09.20 22:28 Posted by 파란크리스마스

출처 : Overview | Adafruit PiUART - USB Console and Power Add-on for Raspberry Pi | Adafruit Learning System
USB to UART Bridge VCP Drivers | Silicon Labs

Adafruit PiUART

PiUART는 Pi의 헤더에 꼽고 Micro 5Pin 케이블을 PC에 연력하면 쉽게 Serial 연결이 됩니다.

LAN연결 없이 터미널에 접속해서 Wifi나 유선LAN의 IP을 확인하는데 유용한 한것 같아 소개합니다.

두 개의 LED가 RX 및 TX에 연결되어 데이터를 보내거나 받을 때마다 깜박입니다.

 

Micro 5Pin 연결

Windows에 USB UART 추가

Windows 장치 관리자에서 COM 포트가 추가 된 것을 확인 할 수 있습니다.

Serial Console 활성화

2가지 방법이 있으며 2가지 모두 결과는 /boot/config.txt 파일에 enable_uart=1 내용이 추가됩니다.

방법1. /boot/config.txt 파일 직접 수정

$ sudo vi /boot/config.txt

내용 추가

enable_uart=1

방법2. raspi-config 유틸리티 사용

raspi-config 실행

$ sudo raspi-config

[Interfacing Options] 선택

[Serial] 선택

[Yes] 버튼 선택

[Ok] 버튼 선택

[Finish] 버튼 선택

SSH 클라이언트 설정

SSH 이용 Raspberry Pi 연결

저작자 표시
신고

Arduino - 버저, 피에조 스피커(Piezo Buzzer)

OS/Arduino 2017.09.16 18:30 Posted by 파란크리스마스

출처 : All I want to do is BEEP! to show that the program - Arduino Forum
버저, 피에조 스피커로 음악 연주 (슈퍼마리오 배경음악) | Hard Copy Arduino

Arduino - 버저, 피에조 스피커(Piezo Buzzer)

Spec.

전압 : 5V
직경 : 12mm
핀길이 : 6.5mm
높이 : 8.5mm

배선

BEEP음 출력 소스

#define SPKR 2 //this is the digital pin that you plugged the red       wire into

void setup()
{
   pinMode(SPKR, OUTPUT); //set the speaker as output
}

void loop() //do this over and over
{
   digitalWrite(SPKR, HIGH); //turn the speaker on
   delay(500);                     //wait for half a second
   digitalWrite(SPKR, LOW); //turn the speaker off
   delay(500);                    //wait for half a second
}

피에조 스피커로 음악 연주 (슈퍼마리오 배경음악)

출처 : 버저, 피에조 스피커로 음악 연주 (슈퍼마리오 배경음악) | Hard Copy Arduino

pitches.h(링크) 파일은 아두이노 사이트에서 받을 수 있습니다.

#include "pitches.h"
 
#define melodyPin 2
 
unsigned long prevPlayTime = 0;
unsigned long playDuration = 0;
int currentMelody = 0;
 
//Mario main theme melody
int melodySize = 55;
int melody[] = {
  NOTE_E7, NOTE_E7, 0, NOTE_E7, 0, NOTE_C7, NOTE_E7, 0, NOTE_G7, 0, 0,  0, NOTE_G6, 0, 0, 0, 
  NOTE_C7, 0, 0, NOTE_G6, 0, 0, NOTE_E6, 0, 0, NOTE_A6, 0, NOTE_B6, 0, NOTE_AS6, NOTE_A6, 0, 
  NOTE_G6, NOTE_E7, NOTE_G7, NOTE_A7, 0, NOTE_F7, NOTE_G7, 0, NOTE_E7, 0,NOTE_C7, NOTE_D7, NOTE_B6, 0, 0,
  NOTE_C7, 0, 0, NOTE_G6, 0, 0, NOTE_E6, 0, 0, NOTE_A6, 0, NOTE_B6, 0, NOTE_AS6, NOTE_A6, 0, 
  NOTE_G6, NOTE_E7, NOTE_G7, NOTE_A7, 0, NOTE_F7, NOTE_G7, 0, NOTE_E7, 0,NOTE_C7, NOTE_D7, NOTE_B6, 0, 0
};

//Mario main them tempo
int tempo[] = {
  12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 
  12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 
  9, 9, 9, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12,
  12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12,
  9, 9, 9, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12,
};

void sing() {
    if(millis() < prevPlayTime + playDuration) {
        // music is playing. do nothing
        return;
    }
    // stop the tone playing:
    noTone(8);
    
    if(currentMelody >= melodySize)
        currentMelody = 0;
    // to calculate the note duration, take one second
    // divided by the note type.
    //e.g. quarter note = 1000 / 4, eighth note = 1000/8, etc.
    int noteDuration = 1000/tempo[currentMelody];
 
    tone(melodyPin, melody[currentMelody], noteDuration);
    prevPlayTime = millis();
    playDuration = noteDuration * 1.30;
    
    currentMelody++;
}

void setup() {
  pinMode(melodyPin, OUTPUT);
}

void loop() {
  // play music
  sing();
}


저작자 표시
신고

Arduino - 서브모터(SG-90)

OS/Arduino 2017.09.16 03:35 Posted by 파란크리스마스

출처 : 5 pcs Flame Sensor Module Fire Detection Module Infrared Receiver Module For DIY Electronic Car Wavelength 760nm-1100nm - Aliexpress.com

Arduino - 서브모터(SG-90)

설명

크기 : 21.5mm X 11.8mm X 22.7mm
무게 : 9g
속도 : 0.12 초 / 60도 (4.8V)
1.2 스톨 토크 - 1.4 kg / cm (4.8V)
작동 온도 : -30도에서 +60도
작동 전압 : 4.8V-6V

인터페이스 설명 (선)

다크 그레이 : GND
레드 : VCC의 4.8-7.2V
오렌지 라인 : 펄스 입력

배선

서브모터(SG-90) 제어 소스

#include <Servo.h>

Servo servo;

int servoPin = 9;
int angle = 0; // servo position in degrees 

void setup()  { 
  servo.attach(servoPin);
} 

void loop() { 
  for(angle = 0; angle < 180; angle++)  { 
    servo.write(angle); 
    delay(15); 
  } 
}

서브모터(SG-90) 제어 실행


저작자 표시
신고

Arduino - 불꽃 감지 센서 (SZH-EK086, 파장 760nm-1100nm)

OS/Arduino 2017.09.16 01:31 Posted by 파란크리스마스

출처 : 5 pcs Flame Sensor Module Fire Detection Module Infrared Receiver Module For DIY Electronic Car Wavelength 760nm-1100nm - Aliexpress.com

Arduino - 불꽃 감지 센서

소개

이 민감한 불꽃, 동안 또한 감지 일반적인. 보통 사용 화재 경보. , 디지털 출력 인터페이스 직접 연결된 마이크로 IO. 멀리서 유지 불꽃, 높은 온도 손상 센서 모듈. 

설명

1. 검출 불꽃 또는 광원 의 파장 범위 760nm ~ 1100nm
2. 감지 각도 약 60도, 불꽃 스펙트럼 측정
3. 정확도 조정
4. 작동 전압 3.3V 또는 5V 
5. 출력 - 아날로그 전압 출력, 디지털 스위치 출력 (0 1)
6. PCB 크기: 3cm * 1.6cm
7. Chip LM393

인터페이스 설명 (선)

1. VCC -- 3.3 볼트 5 볼트 전압
2. GND -- GND
3. DO -- 보드 디지털 출력 인터페이스 (0 1)
4. AO -- 보드 아날로그 출력 인터페이스

배선

불꽃 감지 센서 측정 소스

int ledPin = 2;
int inputPin = A0;
int val = 0;    //센서출력값 저장 변수

void setup() {
  pinMode(ledPin, OUTPUT);   //LED 출력설정
  pinMode(inputPin, INPUT);    //불꽃센서 입력설정
  Serial.begin(9600);     //시리얼모니터 설정
}

void loop() {
  val = analogRead(inputPin);  //불꽃센서에서 값을 읽어옴
  Serial.println(val);     //불꽃센서 입력값 시리얼모니터로 출력
  if(val < 150)           //불꽃센서 입력값이 150이하이면 LED실행, 환경에 따라 적절한 값으로 조절필요
  {
    digitalWrite(ledPin,HIGH);  // LED 켜기
  }else{
    digitalWrite(ledPin,LOW);   // LED 끄기
  }
  delay(500);
}
저작자 표시
신고

BPI-M2 Berry - RDP 서버 설치

OS/Banana Pi 2017.09.15 02:10 Posted by 파란크리스마스

출처 : How to use RDP - BananaPro/Pi - LeMaker wiki

RDP 서버 설치

$ sudo apt-get install xrdp
$ sudo apt-get install tightvncserver

RDP 서버 서비스 등록

$ sudo systemctl enable xrdp
xrdp.service is not a native service, redirecting to systemd-sysv-install
Executing /lib/systemd/systemd-sysv-install enable xrdp

재부팅

$ sudo shutdown -r now


저작자 표시
신고

Arduino - 온습도센서(DHT-11)

OS/Arduino 2017.09.13 00:49 Posted by 파란크리스마스

출처 : 1PCS DHT11 DHT 11 Digital Temperature and Humidity Temperature sensor with Cable for Arduino-in Integrated Circuits from Electronic Components & Supplies on Aliexpress.com

Arduino - 온습도센서(DHT-11)

사양

습도 측정 범위 : 20 % ~ 90 % RH
습도 측정 오차 : 5 % RH ±
측정 온도 범위 : 0 ~ 60 ° C
온도 측정 오차 : ± 2 ° C
작동 전압 : DC 5V
크기 : 약. 30x13x8mm (L *의 W의 * H)

온습도센서 라이브러리 추가

온습도센서 라이브러리 다운로드

라이브러리 다운로드

다운로드 받은 라이브러리 추가

소스에 라이브러리 추가

편집창에 추가된 라이브러리 확인

배선

온습도센서(DHT-11) 측정 소스

#include <dht11.h>

int DHT11PIN = A0;            //Signal 이 연결된 아두이노의 핀번호

dht11 DHT11;
 
void setup()
{
  Serial.begin(9600);  //시리얼 통신속도 설정
}
 
void loop()
{
  int chk = DHT11.read(DHT11PIN);
 
  Serial.print("Temp: ");
  Serial.print((float)DHT11.temperature);
  Serial.print(" C ");
  
  Serial.print("/ RelF: ");
  Serial.print((float)DHT11.humidity);
  Serial.print(" %");

  Serial.println();
  
  delay(2000);
}

실행결과 (시리얼 모니터)

저작자 표시
신고

Arduino - LED 켜기

OS/Arduino 2017.09.13 00:49 Posted by 파란크리스마스

출처 : LED 한 개, 깜박이기 - 코코아팹

LED 모듈

배선

온습도센서(DHT-11) 측정 소스

int PIN_LED = 2;

void setup() {
  // 디지털 2번핀을 출력 핀으로 설정합니다. 
  pinMode(PIN_LED, OUTPUT);   
}

// setup() 함수가 호출된 이후, loop() 함수가 호출되며,
// 블록 안의 코드를 무한히 반복 실행합니다.
void loop() {
  digitalWrite(PIN_LED, HIGH);       // LED를 ON 합니다.
  delay(1000);                       // 1초간 대기합니다.
  digitalWrite(PIN_LED, LOW);        // LED를 OFF 합니다.
  delay(1000);                       // 1초간 대기합니다.
}


저작자 표시
신고

Raspberry Pi - VNC 서버 설치

OS/Raspberry Pi 2017.09.04 00:31 Posted by 파란크리스마스

출처 : Raspberry Pi 3를 VNC로 접속하여 원격 제어하는 방법 (x11vnc)

VNC 서버 설치

$ sudo apt-get install x11vnc xinetd

VNC 서버 해상도 설정

$ sudo vi /boot/config.txt

주석 제거

# uncomment to force a console size. By default it will be display's size minus
# overscan.
framebuffer_width=1280
framebuffer_height=720

재부팅

$ sudo shutdown -r now

암호 설정

$ sudo x11vnc -storepasswd /etc/x11vnc.pass
Enter VNC password: 
Verify password:    
Write password to /etc/x11vnc.pass?  [y]/n y
Password written to: /etc/x11vnc.pass

암호 설정

$ sudo vi /lib/systemd/system/x11vnc.service

주석 제거

[Unit]
Description="x11vnc"
Requires=display-manager.service
After=display-manager.service

[Service]
ExecStart=/usr/bin/x11vnc -xkb -loop -noxrecord -noxfixes -noxdamage -display :0 -auth guess -rfbauth /etc/x11vnc.pass
ExecStop=/usr/bin/killall x11vnc

[Install]
WantedBy=multi-user.target

VNC 서버 실행

$ sudo systemctl daemon-reload
$ sudo systemctl start x11vnc

VNC 서버 서비스 등록

$ sudo systemctl enable x11vnc
Created symlink from /etc/systemd/system/multi-user.target.wants/x11vnc.service to /lib/systemd/system/x11vnc.service.


저작자 표시
신고

BPI-M2 Berry - Python + OpenCV

OS/Banana Pi 2017.09.01 00:27 Posted by 파란크리스마스

출처 : BPI-M2 Ultra use OpenCV and face recognition - Banana Pi BPI-M2 Ultra / BPI-M2 Berry
Compile and Run OpenCV2 on Banana Pi - Banana Pi BPI-M2 - banana pi single board computer official forum SinoVoip BPI team
Raspberry Pi 3에 opencv_contrib 포함하여 OpenCV 3.2 설치 - 멈춤보단 천천히라도
Install guide: Raspberry Pi 3 + Raspbian Jessie + OpenCV 3
OpenCV 설치 - MechaWiki

Use bpi-update command to update kernel image

Update bpi-tools

$ git clone https://github.com/BPI-SINOVOIP/bpi-tools.git
Cloning into 'bpi-tools'...
remote: Counting objects: 89, done.
remote: Total 89 (delta 0), reused 0 (delta 0), pack-reused 89
Unpacking objects: 100% (89/89), done.
Checking connectivity... done.
$ cd bpi-tools
$ sudo ./bpi-tools -u -U
F_UPDATE=yes
F_UPGRADE=yes
BPIFILE=/home/pi/.bpi-tools.lst
Wait for download index file ...
OK!!\n
BPIFILE=/home/pi/.bpi-tools.lst
Wait for download index file ...
OK!!\n
 
bpi files:
bpi-tools       v1.2.0(github)
bpi-bootsel     v1.0.6a
bpi-copy        v1.0.11a
bpi-get         v1.0.3(github)
bpi-migrate     v1.3.2a(github)
bpi-hw          v1.2.8
bpi-update      v1.3.2a
 
download bpi files:
bpi-tools
bpi-tools: v1.2.1(github)
bpi-bootsel
bpi-bootsel: v1.2.1(github)
bpi-copy
bpi-copy: v1.2.1(github)
bpi-get
bpi-get: v1.0.3(github)
bpi-migrate
bpi-migrate: v1.3.5(github)
bpi-hw
bpi-hw: v1.2.8
bpi-update
bpi-update: v1.3.4(github)
 
upgrade bpi files:
/usr/bin/bpi-tools
/usr/bin/bpi-bootsel
/usr/bin/bpi-copy
/usr/bin/bpi-get
/usr/bin/bpi-migrate
/usr/bin/bpi-hw
/usr/bin/bpi-update
 
bpi files:
/usr/bin/bpi-tools      v1.2.1(github)
/usr/bin/bpi-bootsel    v1.2.1(github)
/usr/bin/bpi-copy       v1.2.1(github)
/usr/bin/bpi-get        v1.0.3(github)
/usr/bin/bpi-migrate    v1.3.5(github)
/usr/bin/bpi-hw v1.2.8
/usr/bin/bpi-update     v1.3.4(github)

Check bpi-tools version

$ bpi-tools -v
F_VERSION=yes
 
bpi files:
/usr/bin/bpi-tools      v1.2.1(github)
/usr/bin/bpi-bootsel    v1.2.1(github)
/usr/bin/bpi-copy       v1.2.1(github)
/usr/bin/bpi-get        v1.0.3(github)
/usr/bin/bpi-migrate    v1.3.5(github)
/usr/bin/bpi-hw v1.2.8
/usr/bin/bpi-update     v1.3.4(github)

Use bpi-update to update kerenl

$ mkdir update_file
$ cd update_file
$ sudo bpi-update -c bpi-m2u.conf
CONFFILE=bpi-m2u.conf
Wait for download bpi-m2u.conf ...
https://github.com/BPI-SINOVOIP/BPI-files/raw/master/others/for-bpi-tools/conf/board/bpi-m2u.conf
OK!!\n
BPIFILE=/home/pi/.bpi-update.lst
Wait for download index file ...
OK!!\n
INFO: /dev/mmcblk0 : SD/eMMC !!
umount device: /dev/mmcblk0
umount /dev/mmcblk0p1
 
######################
update /dev/mmcblk0p1(vfat) with BPI-BOOT-bpi-m2u.tgz
######################
 
 
Wait for download BPI-BOOT-bpi-m2u.tgz ...
https://github.com/BPI-SINOVOIP/BPI-files/raw/master/SD/BPI-BOOT/BPI-BOOT-bpi-m2u.tgz
OK!!\n
tar xf BPI-BOOT-bpi-m2u.tgz --keep-directory-symlink -C /mnt
total 28
drwxr-xr-x  4 root root 16384 Aug 24 08:04 .
drwxr-xr-x 22 root root  4096 Sep 13 10:24 ..
drwxr-xr-x  3 root root  4096 Aug 24 08:04 bananapi
drwxr-xr-x  2 root root  4096 Sep 13 04:35 System Volume Information
 
######################
update /dev/mmcblk0p2(root) with bpi-tools.tgz BOOTLOADER-bpi-m2u.tgz 3.10.107-BPI-M2U-Kernel.tgz libvdpau_sunxi.tgz bpi-service.tgz addons.tgz bt.tgz camera.tgz camera-apps.tgz brcm.tgz
######################
 
 
Wait for download bpi-tools.tgz ...
https://github.com/BPI-SINOVOIP/BPI-files/raw/master/SD/BPI-ROOT/bpi-tools.tgz
OK!!\n
tar xf bpi-tools.tgz --keep-directory-symlink -C /
Wait for download BOOTLOADER-bpi-m2u.tgz ...
https://github.com/BPI-SINOVOIP/BPI-files/raw/master/SD/BPI-ROOT/BOOTLOADER-bpi-m2u.tgz
OK!!\n
tar xf BOOTLOADER-bpi-m2u.tgz --keep-directory-symlink -C /
Wait for download 3.10.107-BPI-M2U-Kernel.tgz ...
https://github.com/BPI-SINOVOIP/BPI-files/raw/master/SD/BPI-ROOT/3.10.107-BPI-M2U-Kernel.tgz
OK!!\n
tar xf 3.10.107-BPI-M2U-Kernel.tgz --keep-directory-symlink -C /
Wait for download libvdpau_sunxi.tgz ...
https://github.com/BPI-SINOVOIP/BPI-files/raw/master/SD/BPI-ROOT/libvdpau_sunxi.tgz
OK!!\n
tar xf libvdpau_sunxi.tgz --keep-directory-symlink -C /
Wait for download bpi-service.tgz ...
https://github.com/BPI-SINOVOIP/BPI-files/raw/master/SD/BPI-ROOT/bpi-service.tgz
OK!!\n
tar xf bpi-service.tgz --keep-directory-symlink -C /
Wait for download addons.tgz ...
https://github.com/BPI-SINOVOIP/BPI-files/raw/master/SD/BPI-ROOT/addons.tgz
OK!!\n
tar xf addons.tgz --keep-directory-symlink -C /
Wait for download bt.tgz ...
https://github.com/BPI-SINOVOIP/BPI-files/raw/master/SD/BPI-ROOT/bt.tgz
OK!!\n
tar xf bt.tgz --keep-directory-symlink -C /
Wait for download camera.tgz ...
https://github.com/BPI-SINOVOIP/BPI-files/raw/master/SD/BPI-ROOT/camera.tgz
OK!!\n
tar xf camera.tgz --keep-directory-symlink -C /
Wait for download camera-apps.tgz ...
https://github.com/BPI-SINOVOIP/BPI-files/raw/master/SD/BPI-ROOT/camera-apps.tgz
OK!!\n
tar xf camera-apps.tgz --keep-directory-symlink -C /
Wait for download brcm.tgz ...
https://github.com/BPI-SINOVOIP/BPI-files/raw/master/SD/BPI-ROOT/brcm.tgz
OK!!\n
tar xf brcm.tgz --keep-directory-symlink -C /
total 92
drwxr-xr-x  22 root root  4096 Nov  8  2016 .
drwxr-xr-x  22 root root  4096 Nov  8  2016 ..
drwxr-xr-x   2 root root  4096 Nov 21  2016 bin
drwxr-xr-x   2 root root  4096 Apr 22  2016 boot
drwxr-xr-x  14 root root  4600 Sep 13 10:22 dev
drwxr-xr-x 150 root root 12288 Nov 22  2016 etc
drwxr-xr-x   3 root root  4096 Jul 13  2016 home
drwxr-xr-x  22 root root  4096 Nov 27  2015 lib
drwx------   2 root root 16384 Apr 22  2016 lost+found
drwxr-xr-x   3 root root  4096 Jul 21  2016 media
drwxr-xr-x   2 root root  4096 Apr 21  2016 mnt
drwxr-xr-x   3 root root  4096 Jul 20  2016 opt
dr-xr-xr-x 195 root root     0 Jan  1  1970 proc
drwx------   8 root root  4096 Aug 23 15:50 root
drwxr-xr-x  27 root root   880 Sep 13 10:24 run
drwxr-xr-x   2 root root  4096 Aug  1 10:54 sbin
drwxr-xr-x   2 root root  4096 Apr 21  2016 srv
dr-xr-xr-x  12 root root     0 Sep 13 10:21 sys
drwxr-xr-x   4 root root  4096 Nov 27  2015 system
drwxrwxrwt  10 root root  4096 Sep 13 15:47 tmp
drwxr-xr-x  12 root root  4096 Dec 21  2016 usr
drwxr-xr-x  13 root root  4096 Jul  4  2016 var
INFO: online system: skip umount /

기존에 설치된 OpenCV 제거

OpenCV 설치 여부 확인 - 설치가 안 된경우

$ pkg-config --modversion opencv
Package opencv was not found in the pkg-config search path.
Perhaps you should add the directory containing `opencv.pc'
to the PKG_CONFIG_PATH environment variable
No package 'opencv' found

OpenCV 설치 여부 확인 - 설치 되어 있는 경우

$  pkg-config --modversion opencv
2.4.9.1

설치되어 있는 OpenCV 삭제

$ sudo apt-get purge libopencv* python-opencv
$ sudo apt-get autoremove

OS 업그레이드

$ sudo apt-get update
$ sudo apt-get upgrade

개발 도구와 관련 패키지 설치

$ sudo apt-get install build-essential cmake pkg-config

이미지(JPEG, PNG, TIFF, 기타 등등...) 처리 관련 패키지 설치

$ sudo apt-get install libjpeg-dev libtiff5-dev libjasper-dev libpng12-dev

비디오 처리 관련 패키지 설치

$ sudo apt-get install libavcodec-dev libavformat-dev libswscale-dev libv4l-dev
$ sudo apt-get install libxvidcore-dev libx264-dev

Video4Linux 패키지 설치

$ sudo apt-get install libv4l-dev v4l-utils

GTK 패키지 설치

$ sudo apt-get install libgtk2.0-dev

OpenCV 관련 패키지 설치

$ sudo apt-get install libatlas-base-dev gfortran libeigen3-dev

Python 설치

$ sudo apt-get install python2.7-dev python3-dev

NumPy 설치

출처 : 예제로 배우는 파이썬 프로그래밍 - numpy 사용하기

$ sudo apt-get install python-numpy python3-numpy

OpenCV 소스 다운로드 및 압축해제

$ cd ~
$ wget -O opencv.zip https://github.com/Itseez/opencv/archive/3.2.0.zip
$ unzip opencv.zip

OpenCV Extra Modules 소스 다운로드 및 압축해제

$ wget -O opencv_contrib.zip https://github.com/Itseez/opencv_contrib/archive/3.2.0.zip
$ unzip opencv_contrib.zip

cmake

$ cd ~/opencv-3.2.0/
$ mkdir build
$ cd build
$ cmake -D CMAKE_BUILD_TYPE=RELEASE \
-D CMAKE_INSTALL_PREFIX=/usr/local \
-D BUILD_ZLIB=ON \
-D BUILD_PNG=ON \
-D WITH_TBB=OFF \
-D WITH_IPP=OFF \
-D WITH_1394=OFF \
-D BUILD_WITH_DEBUG_INFO=OFF \
-D BUILD_DOCS=OFF \
-D INSTALL_C_EXAMPLES=ON \
-D INSTALL_PYTHON_EXAMPLES=ON \
-D BUILD_EXAMPLES=OFF \
-D BUILD_TESTS=OFF \
-D BUILD_PERF_TESTS=OFF \
-D ENABLE_NEON=ON \
-D OPENCV_EXTRA_MODULES_PATH=~/opencv_contrib-3.2.0/modules \
-D WITH_V4L=ON  \
-D WITH_FFMPEG=ON \
-D WITH_XINE=ON \
-D BUILD_NEW_PYTHON_SUPPORT=ON \
../
 
-- 
-- General configuration for OpenCV 3.2.0 =====================================
--   Version control:               unknown
-- 
--   Extra modules:
--     Location (extra):            /home/pi/opencv_contrib-3.2.0/modules
--     Version control (extra):     unknown
-- 
--   Platform:
--     Timestamp:                   2017-09-12T15:12:16Z
--     Host:                        Linux 3.10.107-BPI-M2U-Kernel armv7l
--     CMake:                       3.5.1
--     CMake generator:             Unix Makefiles
--     CMake build tool:            /usr/bin/make
--     Configuration:               RELEASE
-- 
--   C/C++:
--     Built as dynamic libs?:      YES
--     C++ Compiler:                /usr/bin/c++  (ver 5.4.0)
--     C++ flags (Release):         -fsigned-char -W -Wall -Werror=return-type -Werror=non-virtual-dtor -Werror=address -Werror=sequence-point -Wformat -Werror=format-security -Wmissing-declarations -Wundef -Winit-self -Wpointer-arith -Wshadow -Wsign-promo -Wno-narrowing -Wno-delete-non-virtual-dtor -Wno-comment -fdiagnostics-show-option -pthread -fomit-frame-pointer -mfp16-format=ieee -mfpu=neon -ffunction-sections -fvisibility=hidden -fvisibility-inlines-hidden -O3 -DNDEBUG  -DNDEBUG
--     C++ flags (Debug):           -fsigned-char -W -Wall -Werror=return-type -Werror=non-virtual-dtor -Werror=address -Werror=sequence-point -Wformat -Werror=format-security -Wmissing-declarations -Wundef -Winit-self -Wpointer-arith -Wshadow -Wsign-promo -Wno-narrowing -Wno-delete-non-virtual-dtor -Wno-comment -fdiagnostics-show-option -pthread -fomit-frame-pointer -mfp16-format=ieee -mfpu=neon -ffunction-sections -fvisibility=hidden -fvisibility-inlines-hidden -g  -O0 -DDEBUG -D_DEBUG
--     C Compiler:                  /usr/bin/cc
--     C flags (Release):           -fsigned-char -W -Wall -Werror=return-type -Werror=non-virtual-dtor -Werror=address -Werror=sequence-point -Wformat -Werror=format-security -Wmissing-declarations -Wmissing-prototypes -Wstrict-prototypes -Wundef -Winit-self -Wpointer-arith -Wshadow -Wno-narrowing -Wno-comment -fdiagnostics-show-option -pthread -fomit-frame-pointer -mfp16-format=ieee -mfpu=neon -ffunction-sections -fvisibility=hidden -O3 -DNDEBUG  -DNDEBUG
--     C flags (Debug):             -fsigned-char -W -Wall -Werror=return-type -Werror=non-virtual-dtor -Werror=address -Werror=sequence-point -Wformat -Werror=format-security -Wmissing-declarations -Wmissing-prototypes -Wstrict-prototypes -Wundef -Winit-self -Wpointer-arith -Wshadow -Wno-narrowing -Wno-comment -fdiagnostics-show-option -pthread -fomit-frame-pointer -mfp16-format=ieee -mfpu=neon -ffunction-sections -fvisibility=hidden -g  -O0 -DDEBUG -D_DEBUG
--     Linker flags (Release):
--     Linker flags (Debug):
--     ccache:                      NO
--     Precompiled headers:         YES
--     Extra dependencies:          /usr/lib/arm-linux-gnueabihf/libtiff.so /usr/lib/arm-linux-gnueabihf/libjasper.so /usr/lib/arm-linux-gnueabihf/libjpeg.so gtk-3 gdk-3 pangocairo-1.0 pango-1.0 atk-1.0 cairo-gobject cairo gdk_pixbuf-2.0 gio-2.0 gobject-2.0 glib-2.0 gthread-2.0 avcodec-ffmpeg avformat-ffmpeg avutil-ffmpeg swscale-ffmpeg dl m pthread rt
--     3rdparty dependencies:       zlib libwebp libpng IlmImf libprotobuf tegra_hal
-- 
--   OpenCV modules:
--     To be built:                 core flann imgproc ml photo reg surface_matching video dnn freetype fuzzy imgcodecs shape videoio highgui objdetect plot superres xobjdetect xphoto bgsegm bioinspired dpm face features2d line_descriptor saliency text calib3d ccalib datasets rgbd stereo tracking videostab xfeatures2d ximgproc aruco optflow phase_unwrapping stitching structured_light python2 python3
--     Disabled:                    world contrib_world
--     Disabled by dependency:      -
--     Unavailable:                 cudaarithm cudabgsegm cudacodec cudafeatures2d cudafilters cudaimgproc cudalegacy cudaobjdetect cudaoptflow cudastereo cudawarping cudev java ts viz cnn_3dobj cvv hdf matlab sfm
-- 
--   GUI: 
--     QT:                          NO
--     GTK+ 3.x:                    YES (ver 3.18.9)
--     GThread :                    YES (ver 2.48.2)
--     GtkGlExt:                    NO
--     OpenGL support:              NO
--     VTK support:                 NO
-- 
--   Media I/O: 
--     ZLib:                        build (ver 1.2.8)
--     JPEG:                        /usr/lib/arm-linux-gnueabihf/libjpeg.so (ver )
--     WEBP:                        build (ver 0.3.1)
--     PNG:                         build (ver 1.6.24)
--     TIFF:                        /usr/lib/arm-linux-gnueabihf/libtiff.so (ver 42 - 4.0.6)
--     JPEG 2000:                   /usr/lib/arm-linux-gnueabihf/libjasper.so (ver 1.900.1)
--     OpenEXR:                     build (ver 1.7.1)
--     GDAL:                        NO
--     GDCM:                        NO
-- 
--   Video I/O:
--     DC1394 1.x:                  NO
--     DC1394 2.x:                  NO
--     FFMPEG:                      YES
--       avcodec:                   YES (ver 56.60.100)
--       avformat:                  YES (ver 56.40.101)
--       avutil:                    YES (ver 54.31.100)
--       swscale:                   YES (ver 3.1.101)
--       avresample:                NO
--     GStreamer:                   NO
--     OpenNI:                      NO
--     OpenNI PrimeSensor Modules:  NO
--     OpenNI2:                     NO
--     PvAPI:                       NO
--     GigEVisionSDK:               NO
--     Aravis SDK:                  NO
--     UniCap:                      NO
--     UniCap ucil:                 NO
--     V4L/V4L2:                    NO/YES
--     XIMEA:                       NO
--     Xine:                        NO
--     gPhoto2:                     NO
-- 
--   Parallel framework:            pthreads
-- 
--   Other third-party libraries:
--     Use IPP:                     NO
--     Use VA:                      NO
--     Use Intel VA-API/OpenCL:     NO
--     Use Lapack:                  NO
--     Use Eigen:                   YES (ver 3.2.92)
--     Use Cuda:                    NO
--     Use OpenCL:                  YES
--     Use OpenVX:                  NO
--     Use custom HAL:              YES (carotene (ver 0.0.1))
-- 
--   OpenCL:                        <Dynamic loading of OpenCL library>
--     Include path:                /home/pi/opencv-3.2.0/3rdparty/include/opencl/1.2
--     Use AMDFFT:                  NO
--     Use AMDBLAS:                 NO
-- 
--   Python 2:
--     Interpreter:                 /usr/bin/python2.7 (ver 2.7.12)
--     Libraries:                   /usr/lib/arm-linux-gnueabihf/libpython2.7.so (ver 2.7.12)
--     numpy:                       /usr/lib/python2.7/dist-packages/numpy/core/include (ver 1.11.0)
--     packages path:               lib/python2.7/dist-packages
-- 
--   Python 3:
--     Interpreter:                 /usr/bin/python3 (ver 3.5.2)
--     Libraries:                   /usr/lib/arm-linux-gnueabihf/libpython3.5m.so (ver 3.5.2)
--     numpy:                       /usr/lib/python3/dist-packages/numpy/core/include (ver 1.11.0)
--     packages path:               lib/python3.5/dist-packages
-- 
--   Python (for build):            /usr/bin/python2.7
-- 
--   Java:
--     ant:                         NO
--     JNI:                         NO
--     Java wrappers:               NO
--     Java tests:                  NO
-- 
--   Matlab:                        Matlab not found or implicitly disabled
-- 
--   Tests and samples:
--     Tests:                       NO
--     Performance tests:           NO
--     C/C++ Examples:              NO
-- 
--   Install path:                  /usr/local
-- 
--   cvconfig.h is in:              /home/pi/opencv-3.2.0/build
-- -----------------------------------------------------------------
-- 
-- Configuring done
-- Generating done
-- Build files have been written to: /home/pi/opencv-3.2.0/build

빌드 (BPI-M2 Berry 에는 4 개의 코어가 있으므로 OpenCV를 더 빠르게 컴파일 할 수 있도록 -j4 옵션추가)

$ cat /proc/cpuinfo | grep processor | wc -l
4
$ make -j4

OpenCV 설치

$ sudo make install

/etc/ld.so.conf.d/ 디렉토리에 /usr/local/lib를 포함하는 설정파일이 있는지 확인

$ cat /etc/ld.so.conf.d/*
#/opt/vc/lib
/usr/lib/mali
## Multiarch support
/lib/arm-linux-gnueabihf
/usr/lib/arm-linux-gnueabihf
/usr/lib/arm-linux-gnueabihf/mesa-egl
/usr/lib/arm-linux-gnueabihf/mesa
## libc default configuration
/usr/local/lib
/opt/vc/lib

OpenCV 설치

$ sudo ldconfig

OpenCV 설치 확인 - 1

$ pkg-config --modversion opencv
3.2.0

OpenCV 설치 확인 - 2

$ pkg-config --libs --cflags opencv
-I/usr/local/include/opencv -I/usr/local/include -L/usr/local/lib -lopencv_stitching -lopencv_superres -lopencv_videostab -lopencv_aruco -lopencv_bgsegm -lopencv_bioinspired -lopencv_ccalib -lopencv_dpm -lopencv_freetype -lopencv_fuzzy -lopencv_line_descriptor -lopencv_optflow -lopencv_reg -lopencv_saliency -lopencv_stereo -lopencv_structured_light -lopencv_phase_unwrapping -lopencv_rgbd -lopencv_surface_matching -lopencv_tracking -lopencv_datasets -lopencv_text -lopencv_face -lopencv_plot -lopencv_dnn -lopencv_xfeatures2d -lopencv_shape -lopencv_video -lopencv_ximgproc -lopencv_calib3d -lopencv_features2d -lopencv_flann -lopencv_xobjdetect -lopencv_objdetect -lopencv_ml -lopencv_xphoto -lopencv_highgui -lopencv_videoio -lopencv_imgcodecs -lopencv_photo -lopencv_imgproc -lopencv_core

용량 확보를 위해서 다운로드 받은 소스 파일 삭제

$ cd ~
$ rm -rf opencv-3.2.0 opencv_contrib-3.2.0

python3에서 OpenCV 버전확인

$ python3
Python 3.4.2 (default, Oct 19 2014, 13:31:11) 
[GCC 4.9.1] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import cv2
>>> cv2.__version__
'3.2.0'

python3에서 얼굴인식 예제 실행 (Camera 인식 실패로 Camera 직접 제어는 포기)

$ python3 /usr/local/share/OpenCV/samples/python/facedetect.py --cascade "/usr/local/share/OpenCV/haarcascades/haarcascade_frontalface_alt.xml" --nested-cascade "/usr/local/share/OpenCV/haarcascades/haarcascade_eye_tree_eyeglasses.xml" /dev/video0
 
 
face detection using haar cascades
 
USAGE:
    facedetect.py [--cascade <cascade_fn>] [--nested-cascade <cascade_fn>] [<video_source>]
 
Warning: unable to open video source:  /dev/video0
Warning: unable to open video source:  synth
Traceback (most recent call last):
  File "/usr/local/share/OpenCV/samples/python/facedetect.py", line 52, in <module>
    ret, img = cam.read()
AttributeError: 'NoneType' object has no attribute 'read'

python3에서 얼굴인식 예제 작성 (mjpg-streamer에서 Camera 영상을 받아 오도록 수정)

#!/usr/bin/env python

'''
face detection using haar cascades

USAGE:
    facedetect.py [--cascade <cascade_fn>] [--nested-cascade <cascade_fn>] [<video_source>]
'''

# Python 2/3 compatibility
from __future__ import print_function

import numpy as np
import cv2
import requests

# local modules
# from video import create_capture
from common import clock, draw_str

BYTES_NONE = b'';

def detect(img, cascade):
    rects = cascade.detectMultiScale(img, scaleFactor=1.3, minNeighbors=4, minSize=(30, 30),
                                     flags=cv2.CASCADE_SCALE_IMAGE)
    if len(rects) == 0:
        return []
    rects[:,2:] += rects[:,:2]
    return rects

def draw_rects(img, rects, color):
    for x1, y1, x2, y2 in rects:
        cv2.rectangle(img, (x1, y1), (x2, y2), color, 2)

if __name__ == '__main__':
    import sys, getopt
    print(__doc__)

    args, video_src = getopt.getopt(sys.argv[1:], '', ['cascade=', 'nested-cascade='])
    try:
        video_src = video_src[0]
    except:
        video_src = 0
    args = dict(args)
    cascade_fn = args.get('--cascade', "../../data/haarcascades/haarcascade_frontalface_alt.xml")
    nested_fn  = args.get('--nested-cascade', "../../data/haarcascades/haarcascade_eye.xml")

    cascade = cv2.CascadeClassifier(cascade_fn)
    nested = cv2.CascadeClassifier(nested_fn)

    #cam = create_capture(video_src, fallback='synth:bg=../data/lena.jpg:noise=0.05')

    while True:
        r = requests.get('http://127.0.0.1:8080/?action=snapshot"', auth=('user', 'password'), stream=True)
        if (r.status_code == 200):
            bytes = BYTES_NONE
            for chunk in r.iter_content(chunk_size=1024):
                bytes += chunk
                a = bytes.find(b'\xff\xd8')
                b = bytes.find(b'\xff\xd9')
                if a != -1 and b != -1:
                    jpg = bytes[a:b + 2]
                    bytes = bytes[b + 2:]

                    # ret, img = cam.read()
                    # ret, \
                    img = cv2.imdecode(np.fromstring(jpg, dtype=np.uint8), cv2.IMREAD_COLOR)
                    gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
                    gray = cv2.equalizeHist(gray)

                    t = clock()
                    rects = detect(gray, cascade)
                    vis = img.copy()
                    draw_rects(vis, rects, (0, 255, 0))
                    if not nested.empty():
                        for x1, y1, x2, y2 in rects:
                            roi = gray[y1:y2, x1:x2]
                            vis_roi = vis[y1:y2, x1:x2]
                            subrects = detect(roi.copy(), nested)
                            draw_rects(vis_roi, subrects, (255, 0, 0))
                    dt = clock() - t

                    draw_str(vis, (20, 20), 'time: %.1f ms' % (dt*1000))
                    cv2.imshow('facedetect', vis)

        if cv2.waitKey(5) == 27:
            break
    cv2.destroyAllWindows()
$ python3 /usr/local/share/OpenCV/samples/python/facedetect.py --cascade "/usr/local/share/OpenCV/haarcascades/haarcascade_frontalface_alt.xml" --nested-cascade "/usr/local/share/OpenCV/haarcascades/haarcascade_eye_tree_eyeglasses.xml" /dev/video0

python3에서 얼굴인식 예제 실행




얼굴인식 예제 컴파일, 실행 (컴파일 실패로 CPP 예제는 포기)

$ cp /usr/local/share/OpenCV/samples/cpp/facedetect.cpp ./
$ g++ -o facedetect facedetect.cpp $(pkg-config --libs --cflags opencv) 
/usr/bin/ld: /tmp/ccWuwUjB.o: undefined reference to symbol 'fopen@@GLIBC_2.4'
//lib/arm-linux-gnueabihf/libc.so.6: error adding symbols: DSO missing from command line
collect2: error: ld returned 1 exit status

cmake 다른 옵션

$ cmake -D CMAKE_BUILD_TYPE=RELEASE \
-D CMAKE_INSTALL_PREFIX=/usr/local \
-D BUILD_SHARED_LIBS=OFF \
-D BUILD_ZLIB=ON \
-D BUILD_PNG=ON \
-D WITH_TBB=OFF \
-D WITH_IPP=OFF \
-D WITH_1394=OFF \
-D BUILD_WITH_DEBUG_INFO=OFF \
-D BUILD_DOCS=OFF \
-D INSTALL_C_EXAMPLES=ON \
-D INSTALL_PYTHON_EXAMPLES=ON \
-D BUILD_EXAMPLES=OFF \
-D BUILD_TESTS=OFF \
-D BUILD_PERF_TESTS=OFF \
-D ENABLE_NEON=ON \
-D OPENCV_EXTRA_MODULES_PATH=~/opencv_contrib-3.2.0/modules \
-D WITH_V4L=ON  \
-D WITH_FFMPEG=ON \
-D WITH_XINE=ON \
-D BUILD_NEW_PYTHON_SUPPORT=ON \
../


저작자 표시
신고

BPI-M2 Berry mjpg-streamer

OS/Banana Pi 2017.09.01 00:07 Posted by 파란크리스마스

BPI-M2 Berry mjpg-streamer

출처 : 【BPI-M2+】之mjpg-streamer测试和体验- Bananap讨论区- 烽火社区 ...
MJPG-Streamer › Wiki › ubuntuusers.de
라즈베리파이에서 웹캠 mjpg-streamer 따라하기|작성자 서리
mjpg-streamer 웹캠 영상 스트리밍 | Mungrrr

관련 라이브러리 설치

$ sudo apt-get install libjpeg8-dev libv4l-dev subversion
$ sudo apt-get install imagemagick

mjpg-streamer 소스 다운로드

출처 : http://www.lavrsen.dk/svn/motion/tags/3.2.9/picture.c

$ svn co https://svn.code.sf.net/p/mjpg-streamer/code/mjpg-streamer mjpg-streamer
$ cd mjpg-streamer

input_ov5640.so 컴파일 관련 내용 추가

input_ov5640.so 소스는 누락되어 있습니다.(참고용)

$ vi Makefile

Makefile 내용 일부

# define the name of the program
APP_BINARY = mjpg_streamer

# define the names and targets of the plugins
PLUGINS = input_ov5640.so              # bluexmas : 추가
PLUGINS += input_uvc.so

... 생략 ...

# bluexmas : 추가
ifeq ($(USE_LIBV4L2),true)
input_ov5640.so: mjpg_streamer.h utils.h
	make -C plugins/input_ov5640 USE_LIBV4L2=true all
	cp plugins/input_ov5640/input_ov5640.so .
else
input_ov5640.so: mjpg_streamer.h utils.h
	make -C plugins/input_ov5640 all
	cp plugins/input_ov5640/input_ov5640.so .
endif

ifeq ($(USE_LIBV4L2),true)
input_uvc.so: mjpg_streamer.h utils.h

... 생략 ...

# cleanup
clean:
	make -C plugins/input_ov5640 $@           # bluexmas : 추가
	make -C plugins/input_uvc $@

mjpg-streamer 컴파일 및 설치

$ make USE_LIBV4L2=true clean all
$ sudo make install
install --mode=755 mjpg_streamer /usr/local/bin
install --mode=644 input_ov5640.so input_uvc.so output_file.so output_udp.so output_http.so input_testpicture.so input_file.so /usr/local/lib/
install --mode=755 -d /usr/local/www
install --mode=644 -D www/* /usr/local/www

input_ov5640.so

input_ov5640.so.tgz

mjpg-streamer의 input_uvc.so는 YUV만 지원하고, BPI-M2 Berry의 카메라인 OV5640는 YUV420코덱만 지원하기 때문에, mjpg-streamer에서 사용 할 수 없습니다.

제가 작업한 OV5640의 YUV420코덱을 지원하는 so 파일을 공개 합니다.
BPI-M2 Berry의 카메라인 OV5640를 사용해서 mjpg-streamer로 스트리밍 하시려면 첨부한 파일을 사용하세요.

LD_LIBRARY_PATH 경로 추가

$ echo "export LD_LIBRARY_PATH=\$LD_LIBRARY_PATH:/usr/local/lib:/usr/local/lib/mjpg-streamer" | sudo tee -a /etc/profile

mjpg-streamer 실행

$ mjpg_streamer -i "input_ov5640.so -y -n" -o "output_http.so -w /usr/local/www"
MJPG Streamer Version: svn rev: 3:172M
 i: Using V4L2 device.: /dev/video0
 i: Desired Resolution: 640 x 480
 i: Frames Per Second.: 5
 i: Format............: YUV420
 i: JPEG Quality......: 80
 o: www-folder-path...: /usr/local/www/
 o: HTTP TCP port.....: 8080
 o: username:password.: disabled
 o: commands..........: enabled

서비스등록

$ sudo vi /etc/init.d/mjpg-streamer

mjpg-streamer 파일 내용

#!/bin/bash
# /etc/init.d/mjpg-streamer
# v0.2 phillips321.co.uk
### BEGIN INIT INFO
# Provides:          mjpg_streamer.sh
# Required-Start:    $network
# Required-Stop:     $network
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: mjpg_streamer for webcam
# Description:       Streams /dev/video0 to http://IP/?action=stream
### END INIT INFO

#
export width=640
export height=480
export fps=10
export SHUTDOWN_WAIT=2
export QUALITY=95

if [ -n "$2" ]; then
  width=$2 
fi

if [ -n "$3" ]; then
  height=$3
fi

if [ -n "$4" ]; then
  fps=$4
fi

export LD_MJPG_STREAMER=/usr/local/lib

f_message(){
        echo "[+] $1"
}

mjpg_streamer_pid() {
  echo `ps aux | grep mjpg_service | grep -v grep | awk '{ print $2 }'`
}

start() {
  pid=$(mjpg_streamer_pid)
  if [ -n "$pid" ] 
  then
    echo "mjpg_streamer is already running (pid: $pid)"
  else
    # Start mjpg_streamer
		f_message "Starting mjpg_streamer"
		mjpg_streamer -b -i "$LD_MJPG_STREAMER/input_ov5640.so -r "$width"x"$height" -f $fps -q $QUALITY -y" -o "$LD_MJPG_STREAMER/output_http.so -p 8080 -w /usr/local/www" mjpg_service
		sleep 2
		f_message "mjpg_streamer started"
  fi

  return 0
}

stop() {
  pid=$(mjpg_streamer_pid)
  if [ -n "$pid" ]
  then
    f_message "Stopping mjpg_streamer..."
    kill -9 $pid

    let kwait=$SHUTDOWN_WAIT
    let count=0;
    until [ `ps -p $pid | grep -c $pid` = '0' ] || [ $count -gt $kwait ]
    do
      echo -n -e "\nwaiting for processes to exit";
      sleep 1
      let count=$count+1;
    done

    if [ $count -gt $kwait ]; then
      echo -n -e "\nkilling processes which didn't stop after $SHUTDOWN_WAIT seconds\n"
      kill -9 $pid
    fi
  else
    echo "mjpg_streamer is not running"
  fi
 
  return 0
}

# Carry out specific functions when asked to by the system
case "$1" in
        start)
                 start
                 ;;
        stop)
                 stop
                 ;;
        restart)
                 stop
                 sleep 2
                 start
                 ;;
        resolution)
                resolution=`ps axu | grep mjpg_streamer | grep -v grep | awk '{ print $16 }'`
                currfps=`ps axu | grep mjpg_streamer | grep -v grep | awk '{ print $18 }'`
                if [ -n "$resolution" ];
                then
                        echo "${resolution}"x"$currfps"
                else
                        echo "0x0x0"
                fi
                ;;
        status)
                pid=`ps -A | grep mjpg_streamer | grep -v "grep" | grep -v mjpg_streamer. | awk '{print $1}' | head -n 1`
                if [ -n "$pid" ];
                then
                        f_message "mjpg_streamer is running with pid ${pid}"
                        f_message "mjpg_streamer was started with the following command line"
                        cat /proc/${pid}/cmdline ; echo ""
                else
                        f_message "Could not find mjpg_streamer running"
                fi
                ;;
        *)
                f_message "Usage: $0 {start|stop|status|restart}"
                exit 1
                ;;
esac
exit 0

등록

$ sudo chmod u+x /etc/init.d/mjpg-streamer
$ sudo update-rc.d mjpg-streamer defaults

서비스 실행 및 실행 확인

$ sudo service mjpg-streamer start
$ sudo service mjpg-streamer status
● mjpg-streamer.service - LSB: mjpg_streamer for webcam
   Loaded: loaded (/etc/init.d/mjpg-streamer; bad; vendor preset: enabled)
   Active: active (running) since Thu 2017-08-31 20:14:42 CST; 2min 28s ago
     Docs: man:systemd-sysv-generator(8)
  Process: 5108 ExecStart=/etc/init.d/mjpg-streamer start (code=exited, status=0/SUCCESS)
   Memory: 1.0M
      CPU: 1min 18.585s
   CGroup: /system.slice/mjpg-streamer.service
           └─5117 mjpg_streamer -b -i /usr/local/lib/input_ov5640.so -r 640x480 -f 10 -q 95 -y -o /usr/local/lib/output_http.so -p 8080 -w /
 
Aug 31 20:14:40 bpi-iot-ros-ai mjpg_streamer[5117]: MJPG-streamer [5117]: Format............: YUV420
Aug 31 20:14:40 bpi-iot-ros-ai mjpg_streamer[5117]: MJPG-streamer [5117]: JPEG Quality......: 95
Aug 31 20:14:41 bpi-iot-ros-ai mjpg_streamer[5117]: MJPG-streamer [5117]: www-folder-path...: /usr/local/www/
Aug 31 20:14:41 bpi-iot-ros-ai mjpg_streamer[5117]: MJPG-streamer [5117]: HTTP TCP port.....: 8080
Aug 31 20:14:41 bpi-iot-ros-ai mjpg_streamer[5117]: MJPG-streamer [5117]: username:password.: disabled
Aug 31 20:14:41 bpi-iot-ros-ai mjpg_streamer[5117]: MJPG-streamer [5117]: commands..........: enabled
Aug 31 20:14:41 bpi-iot-ros-ai mjpg_streamer[5117]: MJPG-streamer [5117]: starting input plugin /usr/local/lib/input_ov5640.so
Aug 31 20:14:41 bpi-iot-ros-ai mjpg_streamer[5117]: MJPG-streamer [5117]: starting output plugin: /usr/local/lib/output_http.so (ID: 00)
Aug 31 20:14:42 bpi-iot-ros-ai mjpg-streamer[5108]: [+] mjpg_streamer started
Aug 31 20:14:42 bpi-iot-ros-ai systemd[1]: Started LSB: mjpg_streamer for webcam.
lines 1-20/20 (END)

실행

-b 옵션 백드라운드로 실행

$ mjpg_streamer -b -i "input_ov5640.so -r "640"x"480" -f 10 -q 75 -y" -o "output_http.so -p 8080 -w /usr/local/www"
enabling daemon modeforked to background (10942)

motion

출처 : mjpegtoyuv420p patch for Logitech Quickcam Pro

$ svn co http://www.lavrsen.dk/svn/motion/trunk motion
$ cd motion
$ ./configure
$ make


저작자 표시
신고


 

티스토리 툴바