树莓派motion摄像头监控并将图片上传百度云盘

sudo apt-get install motion  


sudo vim /etc/motion/motion.conf
Daemon = off改为on  
webcam_localhost = on改为off   (新版叫:stream_localhost)
target_dir /var/lib/motion 照片和录像保存地址,改成别的保存地址 /mnt/udisk/motion 我之前没改,网页http://192.168.1.188:8081/会挂掉
width 640
height 480

webcam_port 8081  

framerate 2 自动监控拍照,帧率没必要太高,否则输出的文件很多

threshold 3000 多少个像素发生改变的时候,保存当前照片

videodevice /dev/video0  //这个可以查看下 ls /dev  如果看到video0则说明usb摄像头已经挂载,可以使用了

#下面这句是说一旦有照片被拍下来,则执行upload.sh命令, 
#其中%f参数会自动转化为当前图片文件的路径,传给upload.sh: 
on_picture_save /home/pi/baidu/upload.sh %f


sudo vim /etc/default/motion
start_motion_daemon=no改为yes 

sudo service motion start  或 restart

查看http://192.168.1.188:8081/


异常:

如果网页http://192.168.1.188:8081图像经常挂掉,可能是保存图片的文件夹权限不正确导致的,可以设置下文件夹属性。

pi@raspberrypi:/media/pi/72B6-D9E0 $ sudo service motion restart

pi@raspberrypi:/media/pi/72B6-D9E0 $ sudo service motion status
● motion.service - LSB: Start Motion detection
   Loaded: loaded (/etc/init.d/motion)
   Active: active (running) since Sun 2016-04-17 22:31:43 CST; 3s ago
  Process: 15095 ExecStop=/etc/init.d/motion stop (code=exited, status=0/SUCCESS)
  Process: 15101 ExecStart=/etc/init.d/motion start (code=exited, status=0/SUCCESS)
   CGroup: /system.slice/motion.service
           └─15114 /usr/bin/motion


Apr 17 22:31:43 raspberrypi motion[15114]: [1] [NTC] [VID] v4l2_scan_controls:         "Hue", default -8193, current 0
Apr 17 22:31:43 raspberrypi motion[15114]: [1] [NTC] [VID] v4l2_scan_controls: found control 0x00980910, "Gamma", range 72,500
Apr 17 22:31:43 raspberrypi motion[15114]: [1] [NTC] [VID] v4l2_scan_controls:         "Gamma", default 57343, current 100
Apr 17 22:31:43 raspberrypi motion[15114]: [1] [NTC] [VID] v4l2_scan_controls: found control 0x00980913, "Gain", range 0,100
Apr 17 22:31:43 raspberrypi motion[15114]: [1] [NTC] [VID] v4l2_scan_controls:         "Gain", default 57343, current 0
Apr 17 22:31:43 raspberrypi motion[15114]: [1] [NTC] [VID] vid_v4lx_start: Using V4L2
Apr 17 22:31:43 raspberrypi motion[15114]: [1] [NTC] [ALL] image_ring_resize: Resizing pre_capture buffer to 1 items
Apr 17 22:31:44 raspberrypi motion[15114]: [1] [NTC] [STR] http_bindsock: motion-stream testing : IPV4 addr: 0.0.0.0 port: 8081
Apr 17 22:31:44 raspberrypi motion[15114]: [1] [NTC] [STR] http_bindsock: motion-stream Bound : IPV4 addr: 0.0.0.0 port: 8081
Apr 17 22:31:44 raspberrypi motion[15114]: [1] [NTC] [ALL] motion_init: Started motion-stream server in port 8081 auth Disabled

打开网页显示图像,在摄像头前晃晃手,图片挂了。此时:

pi@raspberrypi:/media/pi/72B6-D9E0 $ sudo service motion status
● motion.service - LSB: Start Motion detection
   Loaded: loaded (/etc/init.d/motion)
   Active: active (running) since Sun 2016-04-17 22:31:43 CST; 18s ago
  Process: 15095 ExecStop=/etc/init.d/motion stop (code=exited, status=0/SUCCESS)
  Process: 15101 ExecStart=/etc/init.d/motion start (code=exited, status=0/SUCCESS)
   CGroup: /system.slice/motion.service
           └─15114 /usr/bin/motion


Apr 17 22:32:00 raspberrypi motion[15114]: [1] [ERR] [ALL] myfopen: Error opening file /var/lib/motion/01-20160417223200-00.jpg with mode w:
Apr 17 22:32:00 raspberrypi motion[15114]: [1] [ERR] [ALL] put_picture: Can't write picture to file /var/lib/motion/01-20160417223200-00.jpg - check a...directory
                                           Thread is going to finish due to this fatal error:
Apr 17 22:32:00 raspberrypi motion[15114]: [0] [NTC] [STR] httpd_run: motion-httpd - Finishing
Apr 17 22:32:00 raspberrypi motion[15114]: [0] [NTC] [STR] httpd_run: motion-httpd Closing
Apr 17 22:32:00 raspberrypi motion[15114]: [0] [NTC] [STR] motion_web_control: motion-httpd thread exit
Apr 17 22:32:00 raspberrypi motion[15114]: [1] [NTC] [ALL] motion_loop: Thread exiting
Apr 17 22:32:00 raspberrypi motion[15114]: [1] [NTC] [STR] stream_stop: Closing motion-stream listen socket & active motion-stream sockets
Apr 17 22:32:00 raspberrypi motion[15114]: [1] [NTC] [STR] stream_stop: Closed motion-stream listen socket & active motion-stream sockets
Apr 17 22:32:00 raspberrypi motion[15114]: [1] [NTC] [VID] vid_close: Closing video device /dev/video0
Apr 17 22:32:01 raspberrypi motion[15114]: [0] [NTC] [ALL] main: Threads finished
Hint: Some lines were ellipsized, use -l to show in full.

可以看到提示错误:

[ERR] [ALL] myfopen: Error opening file /var/lib/motion/01-20160417223200-00.jpg with mode w:

这时查看文件夹属性:

drwxr-xr-x 2 root     root     4096 Sep  8  2014 motion

sudo chmod 777 motion/

drwxrwxrwx 2 root     root     4096 Sep  8  2014 motion

sudo service motion restart

此时,摄像头就正常了。




上传百度云:

将https://github.com/houtianze/bypy里的bypy.py bypygui.pyw setup.py上传到baidu目录里,并chmod 755 bypy.py权限

需要先认证:

pi@raspberrypi:~/code/baidu $ sudo python bypy.py syncup
Please visit:
https://openapi.baidu.com/oauth/2.0/authorize?scope=basic+netdisk&redirect_uri=oob&response_type=code&client_id=q8WE4xxxxxxxxxxxxxxxx
And authorize this app
Paste the Authorization Code here within 10 minutes.
Press [Enter] when you are done
3ead6bbe8ea730735810af937bxxxxx
Authorizing, please be patient, it may take upto 60.0 seconds...
Authorizing/refreshing with the OpenShift server ...
Successfully authorized  说明认证成功


sudo vim /etc/motion/motion.conf

on_picture_save /home/pi/baidu/upload.sh %f  拍照后执行upload.sh


sudo vim upload.sh

#!/bin/sh
sudo python /home/code/baidu/bypy.py syncup /mnt/udisk/motion


sudo chmod 755 upload.sh





用设置上面的方法不好使,只能用下面的办法,每30秒上传图片到百度网盘,然后删除本地图片 :

#!/usr/bin/python
import os,sys
import time

while True:
        try:
                os.system("sudo python /home/pi/alex/code/motion_pic2baidu/bypy.py syncup /var/lib/motion")  #这里一定要用绝对路径,不然开机启动会找不到文件,默认是root账户目录
                os.system("sudo rm -rf /var/lib/motion/*")

                time.sleep(30)
        except Exception,e:
                with open("log.log","a") as f:
                        f.write("error!\n")


保存后可直接运行:

python upload.py &


开机启动:

sudo vi /etc/rc.local    

在exit 0前加上:

sudo python /home/pi/alex/code/motion_pic2baidu/upload.py &


  • 3
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值