RasPi: MJPG-streamer 영상편지를 받아서 한번 해봤어요.


RasPi로 물체를 검출하고 싶은데...
USB 카메라부터 받아서 사용해 봤어요.
물론 Ras Pi Camera도 있습니다. 여기서 USB 카메라를 연결하면 방법이 있을까요?
어쨌든 DL을 사용하는 물체는 환경과 성능을 측정하기 어려워서 다음 두 가지를 시도해 봤기 때문에 기록하고 싶습니다.
1.MJPG-streamer, 와이파이 내 애니메이션
2. OpenCV를 사용하여 애니메이션 처리 및 저장
둘 다 거의 완전히 움직여서 힘들지 않아요!
이번에는 1을 해봤다는 MJPG-streamer가 실렸다.

JPG-streamer, Wifi 내 애니메이션 배너 사용


참고 사이트에서 보듯이 설치 후 이동합니다.
[참고]
제8회: MJPG-streamer 설치
Raspberry Pi에 웹 카메라 사용하기 (4) M-JPEG streamer의 스트리밍
Raspberry Pi로 웹카메라 영상을 보내는 방법(MJPG-streamer 편제)
가지와 잎은 다르지만 참고 사이트는 모두 같은 순서로 실시되기 때문에 아래에서 이동한다.
요점은 어디에 설치하고 싶은지 미리 결정하고 Dir를 만드는 것이다.
$ cd ~
$ mkdir mjpg-streamer
$ cd mjpg-streamer
그리고 다음 명령을 실행하십시오.
$ sudo apt-get install subversion libjpeg-dev imagemagick
$ svn co https://mjpg-streamer.svn.sourceforge.net/svnroot/mjpg-streamer mjpg-streamer
$ cd mjpg-streamer/mjpg-streamer
$ make
$ sudo install
start_server.sh
#!/bin/sh

PORT="8080" #ポート番号
ID="xxxx" #IDは好きなもの
PW="xxxxxxxx" #パスワード
SIZE="640x480" #画面サイズ
FRAMERATE="20" #フレームレート
export LD_LIBRARY_PATH=/usr/local/lib
./mjpg_streamer \
    -i "input_uvc.so -f $FRAMERATE -r $SIZE -d /dev/video0 -y -n" \
    -o "output_http.so -w /usr/local/www -p $PORT -c $ID:$PW"
$ sh start_server.sh를 실행하면 다음과 같은 내용이 RasPi 콘솔에 표시됩니다.
$ sh start_server.sh
MJPG Streamer Version: svn rev: 3:172
 i: Using V4L2 device.: /dev/video0
 i: Desired Resolution: 640 x 480
 i: Frames Per Second.: 20
 i: Format............: YUV
 i: JPEG Quality......: 80
 o: www-folder-path...: /usr/local/www/
 o: HTTP TCP port.....: 8080
 o: username:password.: xxxx:xxxxxxxx
 o: commands..........: enabled
그런 다음 브라우저에서
http://xxx.xxx.xxx.xxx:8080
에서 설명한 대로 해당 매개변수의 값을 수정합니다.

그나저나 와이파이를 통해 연결된 다른 PC에도 접근할 수 있습니다.
원격 RasPi USB 카메라로 쉽게 모니터링할 수 있다는 것이다.
또한 이번에는 외부 인터넷에서 액세스하기 위해 참고하십시오Raspberry Pi로 웹카메라 영상을 보내는 방법(MJPG-streamer 편제) 뒷부분에 기재된 방법으로 발송할 수 있습니다.
유감스럽게도 우왕에 공유기를 설치할 수 없지만 아래의 자바스크립트입니다.html이 와이파이에서 접근했습니다.
javascript.html
var imageNr = 0;
var finished = new Array();

function createImageLayer() {
  var img = new Image();
  img.style.position = "absolute";
  img.style.zIndex = -1;
  img.onload = imageOnload;
  img.src = "http://192.168.0.15:8080?action=snapshot&n=" + (++imageNr);
  var webcam = document.getElementById("webcam");
  webcam.insertBefore(img, webcam.firstChild);
}

function imageOnload() {
  this.style.zIndex = imageNr;
  while (1 < finished.length) {
    var del = finished.shift();
    del.parentNode.removeChild(del);
  }
  finished.push(this);
  createImageLayer();
}

<body onload="createImageLayer();">
    <div id="webcam"><noscript><img src="http://192.168.0.15:8080?action=snapshot" /></noscript></div>
</body>
action=snapshot, 이렇게 하면 매끄러운 fps로 발송할 수 있습니다.

총결산


・mjpg-streamer를 통해 RasPi의 USB 카메라를 사용하여 애니메이션 배신 가능
・ 이걸 사용하면 실내외 감시를 간단히 할 수 있어요.
외부 인터넷에서 접속하고 싶다~

경품


이 화면의 왼쪽을 클릭하면 각각 표시되고,Hints의here를 클릭하면 html 등 샘플이 표시됩니다.
사용 방법 자유!
그리고 Javascript에서 fps를 표시합니다.Runtime info:
120 ms (8.3 fps)
Avg28 : 137 ms (7.3 fps)
・Static
static_simple.html
<html>
  <head>
    <title>MJPG-Streamer - Static Example</title>
    <!-- refresh page after a few seconds, this works nearly in every browser -->
    <meta http-equiv="refresh" content="10" />
  </head>
  <body>
    <center>
      <img src="/?action=snapshot" alt="This is a static snapshot" />
    </center>
  </body>
</html>
흐르다
stream_simple.html
<html>
  <head>
    <title>MJPG-Streamer - Stream Example</title>
  </head>
  <body>
    <center>
      <img src="/?action=stream" />
    </center>
  </body>
</html>
・Javascript
javascript_simple.html
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>MJPEG-Streamer</title>
</head>
<script type="text/javascript">

/* Copyright (C) 2007 Richard Atterer, richardยฉatterer.net
   This program is free software; you can redistribute it and/or modify it
   under the terms of the GNU General Public License, version 2. See the file
   COPYING for details. */

var imageNr = 0; // Serial number of current image
var finished = new Array(); // References to img objects which have finished downloading
var paused = false;

function createImageLayer() {
  var img = new Image();
  img.style.position = "absolute";
  img.style.zIndex = -1;
  img.onload = imageOnload;
  img.onclick = imageOnclick;
  img.src = "/?action=snapshot&n=" + (++imageNr);
  var webcam = document.getElementById("webcam");
  webcam.insertBefore(img, webcam.firstChild);
}

// Two layers are always present (except at the very beginning), to avoid flicker
function imageOnload() {
  this.style.zIndex = imageNr; // Image finished, bring to front!
  while (1 < finished.length) {
    var del = finished.shift(); // Delete old image(s) from document
    del.parentNode.removeChild(del);
  }
  finished.push(this);
  if (!paused) createImageLayer();
}

function imageOnclick() { // Clicking on the image will pause the stream
  paused = !paused;
  if (!paused) createImageLayer();
}

</script>
<body onload="createImageLayer();">

<div id="webcam"><noscript><img src="/?action=snapshot" /></noscript></div>

</body>
</html>

dphys-swapfile 크기를 변경하여 RasPi 안정화


이동하면서 일반적인 텍스트 편집과vi를 진행하는데 쓰기 오류가 발생했습니다...
다음 편집은 쓰기 후에 다시 시작할 수 있습니다.
$ sudo service dphys-swapfile stop
$ cat /etc/dphys-swapfile 
...
CONF_SWAPSIZE=100
$ sudo nano /etc/dphys-swapfile 
$ cat /etc/dphys-swapfile 
...
CONF_MAXSWAP=4096
...
$ sudo service dphys-swapfile start
[참고]
Raspbian Jessie 및 스왑 메모리 용량 변경(구성 계속)
라즈베리 파이 각양각색.[그 2->Swap 로케일, 암호 변경, 패키지 업데이트]

좋은 웹페이지 즐겨찾기