第一次寫博文,有很多疏漏之處,然后受逼乎影響較深,希望大家多多包涵!
_______________________________________________分割線是這樣畫的吧___________________________________________________________________________________________________
首先,你得有一個樹莓派,而且已經配好ssh(推薦xshell5),這里我不推薦用什么遠程桌面,因為很卡。
第一步,打開攝像頭ENABLE選項(不然攝像頭沒法工作)
輸入
1 sudo raspi-config
按照 5.interfacing options ->P1 camrea->select->enable->ok就可以打開攝像頭了,是不是很簡單呢?
第二步,下載必要的庫,mjpg-sreamer是必須要的。
大家可以到https://github.com/jacksonliam/mjpg-streamer/archive/master.zip上下載必須的庫文件,然后要導入到樹莓派上,我用的是FlashFXP,很方便的就把文件移到樹莓派上了。
但是這款軟件要錢啊,很貴。大家也可以直接這樣:
wget https://github.com/jacksonliam/mjpg-streamer/archive/master.zip
直接在樹莓派上下載。
第三步:安裝輔助工具,敲下如下兩行。
sudo apt-get install libjpeg8-dev sudo apt-get install cmake
其中編譯mjpg-streamer需要上面那個庫。對於一個大工程,編寫makefile實在是件復雜的事,於是人們又想,為什么不設計一個工具,讀入所有源文件之后,自動生成makefile呢,於是就出現了cmake工具,它能夠輸出各種各樣的makefile或者project文件,從而幫助程序員減輕負擔。
這里,小編有時候會忘了自己是否已經安裝了這個那個庫,不妨用這個技巧:
dpkg -l
你所有安裝的庫都會顯示出來。也可以用以下命令去具體查詢哪一個軟件。
dpkg -l|grep 你要查的軟件名
如圖,這種情況說明你已經安裝了vim。
第四步,解壓和編譯mjpg-streamer工程文件。
下載的是壓縮包需要先解壓
unzip master.zip
首先,我們先找到安裝文件的位置,可以直接ls,找到之后就敲:
cd mjpg-streamer-master/mjpg-streamer-experimental/
再接着:
make clean all
嘩嘩出現一大堆東西,只要沒有error,你就可以進行下面操作:
第五步:開啟攝像頭(raspicam;USB攝像頭)
./mjpg_streamer -i"./input_uvc.so" -o"./output_http.so -w ./www"
對於USB攝像頭:
./mjpg_streamer -i "input_uvc.so" -o "output_http.so -w ./www"
下面以樹莓派攝像頭為例說明:
這個命令是直接利用的8080端口,顯示的是demo網站,在你的地址欄敲http://你樹莓派的ip:8080/stream.html,不出意外,你就能看見:(我用的是火狐瀏覽器)
很帥的小伙啊,有木有。(不會告訴你那就是我啦!)
————————————————————————————————————認真的分割線————————————————————————————————
如果只是想看畫面的畫還有一個命令:
./mjpg_streamer -i "input_rpicam.so" -o "output_http.so -p 8090"
這個可以指定端口輸出:
之前還出現圖像模糊的情況,結果發現是鏡頭紙忘了取了,/emoji
之后我想起來,網上很多教程是命令帶參數的,但是我怎么敲都不行。我看了一下幫助
./mjpg_streamer -h
這應該是最最官方的說明吧。出現很多信息,這說明你的攝像頭正在運行。我運行USB攝像頭也行,但是也有很多bug,這是因為我的usb攝像頭只支持YUV格式的。
1 MJPG Streamer Version.: 2.0 2 i: Using V4L2 device.: /dev/video0 3 i: Desired Resolution: 640 x 480 4 i: Frames Per Second.: -1 5 i: Format............: JPEG 6 i: TV-Norm...........: DEFAULT 7 i: Could not obtain the requested pixelformat: MJPG , driver gave us: YUYV 8 ... will try to handle this by checking against supported formats. 9 ... Falling back to YUV mode (consider using -yuv option). Note that this requires much more CPU power 10 UVCIOC_CTRL_ADD - Error at Pan (relative): Inappropriate ioctl for device (25) 11 UVCIOC_CTRL_ADD - Error at Tilt (relative): Inappropriate ioctl for device (25) 12 UVCIOC_CTRL_ADD - Error at Pan Reset: Inappropriate ioctl for device (25) 13 UVCIOC_CTRL_ADD - Error at Tilt Reset: Inappropriate ioctl for device (25) 14 UVCIOC_CTRL_ADD - Error at Pan/tilt Reset: Inappropriate ioctl for device (25) 15 UVCIOC_CTRL_ADD - Error at Focus (absolute): Inappropriate ioctl for device (25) 16 UVCIOC_CTRL_MAP - Error at Pan (relative): Inappropriate ioctl for device (25) 17 UVCIOC_CTRL_MAP - Error at Tilt (relative): Inappropriate ioctl for device (25) 18 UVCIOC_CTRL_MAP - Error at Pan Reset: Inappropriate ioctl for device (25) 19 UVCIOC_CTRL_MAP - Error at Tilt Reset: Inappropriate ioctl for device (25) 20 UVCIOC_CTRL_MAP - Error at Pan/tilt Reset: Inappropriate ioctl for device (25) 21 UVCIOC_CTRL_MAP - Error at Focus (absolute): Inappropriate ioctl for device (25) 22 UVCIOC_CTRL_MAP - Error at LED1 Mode: Inappropriate ioctl for device (25) 23 UVCIOC_CTRL_MAP - Error at LED1 Frequency: Inappropriate ioctl for device (25) 24 UVCIOC_CTRL_MAP - Error at Disable video processing: Inappropriate ioctl for device (25) 25 UVCIOC_CTRL_MAP - Error at Raw bits per pixel: Inappropriate ioctl for device (25) 26 o: www-folder-path......: disabled 27 o: HTTP TCP port........: 8090 28 o: HTTP Listen Address..: (null) 29 o: username:password....: disabled 30 o: commands.............: enabled 31 [-fps | --framerate]...: set video framerate, default 5 frame/sec 32 [-x | --width ]........: width of frame capture, default 640 33 [-y | --height]........: height of frame capture, default 480 34 [-quality].............: set JPEG quality 0-100, default 85 35 [-usestills]...........: uses stills mode instead of video mode 36 [-preview].............: Enable full screen preview 37 [-timestamp]...........: Get timestamp for each frame 38 -sh : Set image sharpness (-100 to 100) 39 -co : Set image contrast (-100 to 100) 40 -br : Set image brightness (0 to 100) 41 -sa : Set image saturation (-100 to 100) 42 -ISO : Set capture ISO 43 -vs : Turn on video stablisation 44 -ev : Set EV compensation 45 -ex : Set exposure mode (see raspistill notes) 46 -awb : Set AWB mode (see raspistill notes) 47 -ifx : Set image effect (see raspistill notes) 48 -cfx : Set colour effect (U:V) 49 -mm : Set metering mode (see raspistill notes) 50 -rot : Set image rotation (0-359) 51 -stats : Compute image stats for each picture (reduces noise for -usestills) 52 -drc : Dynamic range compensation level (see raspistill notes) 53 -hf : Set horizontal flip 54 -vf : Set vertical flip 55 ---------------------------------------------------------------
但是上面也有很多有價值的參數 比如-x -y -fps,這樣我試着敲
./mjpg_streamer -i "input_raspicam.so -quality 100 -x 800 -y 640 -fps 20 " -o "output_http.so -w ./www"
成功了!但是畫面很卡,多少幀每秒,大家試試就知道啦。
然后教程就到這里了,如果要結束監控,敲ctrl + c就行了。
如果有什么問題,或者有更好的方法歡迎留言!
做監控的話,還要開發一下這個界面,能實現拍照,截屏,保存的基本功能。
下一篇:內網穿透實現外網訪問
參考資料:(感謝各位大佬)
1 https://jingyan.baidu.com/article/c33e3f48e88806ea14cbb57b.html 2 3 http://tieba.baidu.com/p/3981484977?traceid= 4 5 http://shumeipai.nxez.com/2017/05/14/raspberry-pi-mjpg-streamer-installation.html 6 7 http://shumeipai.nxez.com/2014/09/21/raspicam-documentation.html 8 9 https://dotblogs.com.tw/bowwowxx/2015/06/08/151511 10 11 https://github.com/jacksonliam/mjpg-streamer 12 13 http://blog.csdn.net/blueslime/article/details/12429411 14 15 http://blog.csdn.net/zhaole20094463/article/details/7026252