LoginSignup
4
3

More than 5 years have passed since last update.

Raspberryで wifi Spycam

Posted at

ラズパイでスパイカムを作成する

下ごしらえ

image.png
1.MicroSD カードを用意する
2.Fat32でフォーマットする。
https://www.raspberrypi.org/documentation/installation/sdxc_formatting.md
image.png

FAT32でないとダメダメ ハマるよ!!!!

  1. Raspbianのダウンロード https://www.raspberrypi.org/downloads/
  2. イメージをMicro SDに展開 https://www.techspot.com/downloads/6931-etcher.html
  3. ラズパイに挿入 成功すると image.png

早速SSHを使えるようにする。
https://qiita.com/Halhira/items/1da2ae543217be26988a

手間がかかりますです。

ラズパイやっているとラズベリーケークが食べたくなりました。

ついでに手作りです。ラズパイ夜食で~す

image.png

手作りケーキの作り方お教えします。

いいよね くださいね!

open CVを導入します。
https://qiita.com/mt08/items/e8e8e728cf106ac83218
を参照に導入
sudo apt autoremove -y libopencv{3,4}、は、以前にインストールしたものを取り除くものなので、インストールされてなければ、エラーを無視してすすめてください。
bottleをインストール

sudo pip3 install bottle

プログラムを転送 Rlogin のSSHを使っています。
image.png

11.raspberry pi
2.余っているWeb Camera
3.Python Program
システムポンチ絵(システム概要図みたいなもの)
image.png
簡単なプログラム

spycam.py
from bottle import *
import cv2
class VideoCamera(object):
    def __init__(self):
        self.video = cv2.VideoCapture(0)
    def __del__(self):
        self.video.release()    
    def get_frame(self):
        return cv2.imencode('.jpg', self.video.read()[1])[1].tobytes()
def gen(camera):
    while True:
        yield (b'--frame\r\nContent-Type: image/jpeg\r\n\r\n' + camera.get_frame() + b'\r\n\r\n')
@route('/video_feed')
def video_feed():
    response.content_type = 'multipart/x-mixed-replace; boundary=frame'
    return gen(VideoCamera())
@route('/')
def index(): 
    return '<div align="center"><h1>Video Streaming</h1><img src="/video_feed"></div>'
run(host='0.0.0.0', port=8081)

wifiを確認(アドレス 例は、192168.1.111)する。
1.下記のプログラムをRaspberry PIに入れる。
2.実行する

解説


return cv2.imencode('.jpg', self.video.read()[1])[1].tobytes()

tupleで返される値を一行に書いた。
一般的な御作法で書くと・・・

success, image = self.video.read()       
ret, jpeg = cv2.imencode('.jpg', image)
return jpeg.tobytes()

yieldを用いてmotion jpegを作成

yield (b'--frame\r\nContent-Type: image/jpeg\r\n\r\n' + camera.get_frame() + b'\r\n\r\n')

「Stupid Phone」から http://192.168.1.111:8081 アクセスする。

4
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
3