找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
广告投放联系QQ68610888
查看: 4361|回复: 6

在路由宝实现实时监控并上传百度云

[复制链接]

准备工作:
1、刷潘多拉系统;
2、安装python、python-requests;
3、插入USB摄像头并安装摄像头驱动和motion;
4、下载bypy,并把bypy.py放到/usr/bin/中。

先看效果,可以保存相片和视频,一秒钟大概保存2到3张照片,相片有地理位置信息。



http://blog.csdn.net/myscnu/article/details/45567153

编写on_picture_save.sh

#!/bin/bashSHELL=/bin/bashUSER=rootPATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/binPWD=/rootLANG=en_GB.UTF-8SHLVL=1HOME=/rootLOGNAME=root_=/usr/bin/envOLDPWD=/tmp/motionpython /root/exif.py $1  >> /tmp/motion/picture.log 2>&1bypy.py -v upload $1 /picture/`date +%Y`/`date +%Y%m`/`date +%Y%m%d`/ >> /tmp/motion/picture.log 2>&1rm -rf $1exit 0
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19

编写on_moive_end.sh

#!/bin/bashSHELL=/bin/bashUSER=rootMAIL=/var/mail/rootPATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/binPWD=/rootLANG=en_GB.UTF-8SHLVL=1HOME=/rootLOGNAME=root_=/usr/bin/envOLDPWD=/tmp/motionbypy.py -v upload $1 /movie/`date +%Y`/`date +%Y%m`/`date +%Y%m%d`/ >> /tmp/motion/movie.log 2>&1rm -rf $1exit 0
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19

修改motion.conf
在on_picture_save和on_movie_end那些指向上述脚本
output_all on
max_mpeg_time 600 #十分钟上传一次,可以改

启动motion -c motion.conf就可以了。

本来上面那样就可以了,但是上传的图都没有exif,在百度云中显示为神秘时间,看着不爽,继续折腾。

编写location.py

#!/usr/bin/python# -*- coding: utf-8 -*-"""Created on Wed May 06 15:26:19 2015@author: HP"""import json, urllib2import reimport pickleimport stringimport fractionsclass Getmyip:    def getip(self):        try:            myip = self.visit("http://www.123cha.com/")        except:            try:                myip = self.visit("http://www.bliao.com/ip.phtml")            except:                try:                    myip = self.visit("http://www.whereismyip.com/")                except:                    myip = "So sorry!!!"        return myip    def visit(self,url):        opener = urllib2.urlopen(url)        if url == opener.geturl():            str = opener.read()        return re.search('\d+\.\d+\.\d+\.\d+',str).group(0)getmyip = Getmyip()localip = getmyip.getip()print localipclass location_baidu():    '''build the mapping of the ip address and its location.the geo info is from <freegeoip.net>'''    def __init__(self, ip):        '''Constructor of location_freegeoip class'''        self.ip = ip        self.ak = 'KMdRKwHjWHCtMLe72bnTWEpq'        self.api_url = 'http://api.map.baidu.com/location/ip?ak=%s&ip=%s&coor=bd09ll' % (self.ak, self.ip)        urlobj = urllib2.urlopen(self.api_url)        data = urlobj.read()        self.datadict = json.loads(data, encoding='utf-8')# print datadict    def get_address(self):        key = 'address'        return self.datadict[key]#    def get_region(self):#        key = 'region_name'#        return self.datadict[key]##    def get_city(self):#        key = 'city'#        return self.datadict[key]    def get_latitude(self):        lati = string.atof(self.datadict['content']['point']['y'])        a = fractions.Fraction(int(lati), 1)        b = fractions.Fraction(int((lati - int(lati)) * 60), 1)        c = fractions.Fraction(int(((lati - int(lati)) * 60 - b) * 60), 1)        return [a, b, c]    def get_longitude(self):        lati = string.atof(self.datadict['content']['point']['x'])        a = fractions.Fraction(int(lati), 1)        b = fractions.Fraction(int((lati - int(lati)) * 60), 1)        c = fractions.Fraction(int(((lati - int(lati)) * 60 - b) * 60), 1)        return [a, b, c]if __name__ == '__main__':    iploc = location_baidu(localip)    print iploc.get_latitude()    print iploc.get_longitude()    f = file('gea.pickle', 'w')    pickle.dump([iploc.get_latitude(), iploc.get_longitude()], f) # dump the object to a file    f.close()
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
  • 64
  • 65
  • 66
  • 67
  • 68
  • 69
  • 70
  • 71
  • 72
  • 73
  • 74
  • 75
  • 76
  • 77
  • 78
  • 79
  • 80
  • 81
  • 82
  • 83
  • 84
  • 85
  • 86
  • 87
  • 88
  • 89
  • 90
  • 91
  • 92

上面脚本每次网络连接的时候运行就可以了,可以在if-up.d设一个脚本启动它。

接下来就是写exif的exif.py

#!/usr/bin/env pythonimport datetimefrom fractions import Fractionimport sysimport pyexiv2import picklef=file('/root/gea.pickle')gea=pickle.load(f)f.close()metadata = pyexiv2.ImageMetadata(sys.argv[1])metadata.read()nowtime = datetime.datetime.now()metadata['Exif.Image.DateTime'] = pyexiv2.ExifTag('Exif.Image.DateTime', nowtime)metadata['Exif.Photo.DateTimeDigitized'] = pyexiv2.ExifTag('Exif.Photo.DateTimeDigitized', nowtime)metadata['Exif.Photo.DateTimeOriginal'] = pyexiv2.ExifTag('Exif.Photo.DateTimeOriginal', nowtime)metadata['Exif.Image.Make'] = pyexiv2.ExifTag('Exif.Image.Make', 'Youku')metadata['Exif.Image.Model'] = pyexiv2.ExifTag('Exif.Image.Model', 'Router Bitch')#metadata['Exif.Image.GPSTag'] = pyexiv2.ExifTag('Exif.Image.GPSTag', '1598L')metadata['Exif.GPSInfo.GPSLatitudeRef'] = pyexiv2.ExifTag('Exif.GPSInfo.GPSLatitudeRef', 'N')metadata['Exif.GPSInfo.GPSLatitude'] = pyexiv2.ExifTag('Exif.GPSInfo.GPSLatitude', gea[0])metadata['Exif.GPSInfo.GPSLongitudeRef'] = pyexiv2.ExifTag('Exif.GPSInfo.GPSLongitudeRef', 'E')metadata['Exif.GPSInfo.GPSLongitude'] = pyexiv2.ExifTag('Exif.GPSInfo.GPSLongitude', gea[1])metadata['Exif.GPSInfo.GPSAltitudeRef'] = pyexiv2.ExifTag('Exif.GPSInfo.GPSAltitudeRef', '0')metadata['Exif.GPSInfo.GPSAltitude'] = pyexiv2.ExifTag('Exif.GPSInfo.GPSAltitude', Fraction(19179, 866))metadata['Exif.GPSInfo.GPSTimeStamp'] = pyexiv2.ExifTag('Exif.GPSInfo.GPSTimeStamp', [Fraction(1, 1), Fraction(20, 1), Fraction(104, 25)])metadata['Exif.GPSInfo.GPSSpeedRef'] = pyexiv2.ExifTag('Exif.GPSInfo.GPSSpeedRef', 'K')metadata['Exif.GPSInfo.GPSSpeed'] = pyexiv2.ExifTag('Exif.GPSInfo.GPSSpeed', Fraction(0, 1))metadata['Exif.GPSInfo.GPSDateStamp'] = pyexiv2.ExifTag('Exif.GPSInfo.GPSDateStamp', datetime.date.today())metadata.write()
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33

到此,照片里面根据IP地址加入了GPS位置,还有时间什么的了。


我的恩山、我的无线 The best wifi forum is right here.
太乱了,你不能整理一下吗?
发个清爽点的:http://blog.csdn.net/myscnu/article/details/45567153
我的恩山、我的无线 The best wifi forum is right here.
回复

使用道具 举报

看不懂............
我的恩山、我的无线 The best wifi forum is right here.
回复

使用道具 举报

这货就是说能做,但绝不是做的最好
我的恩山、我的无线 The best wifi forum is right here.
回复

使用道具 举报

网络摄像头那个多比这货做的更好
我的恩山、我的无线 The best wifi forum is right here.
回复

使用道具 举报

技术流,膜拜
我的恩山、我的无线 The best wifi forum is right here.
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

有疑问请添加管理员QQ86788181|手机版|小黑屋|Archiver|恩山无线论坛(常州市恩山计算机开发有限公司版权所有) ( 苏ICP备05084872号 )

GMT+8, 2024-4-27 20:26

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

| 江苏省互联网有害信息举报中心 举报信箱:js12377 | @jischina.com.cn 举报电话:025-88802724 本站不良内容举报信箱:68610888@qq.com 举报电话:0519-86695797

快速回复 返回顶部 返回列表