码迷,mamicode.com
首页 > 编程语言 > 详细

Python 摄像头截图

时间:2014-06-10 18:44:17      阅读:390      评论:0      收藏:0      [点我收藏+]

标签:python   摄像头   截图   监控   摄像头监控   

先容哥叹息一句,此奥~,这什么g8情况,没头脑的装了将近3g的OpenCV,结果没啥用。。。

入题!!环境为Python2.7

严格按照一下步骤操作,必成功:

所需软件如下:

VideoCapture:  http://videocapture.sourceforge.net/VideoCapture-0.9-5.zip

MyEclipse 插件PyDev: http://ncu.dl.sourceforge.net/project/pydev/pydev/PyDev%202.7.1/PyDev%202.7.1.zip

PIL : http://effbot.org/media/downloads/PIL-1.1.7.win32-py2.7.exe

1.      VideoCapture解压后,找到Python27,把里面的东西复制到自己安装Python对应目录中。建议把Python27外面的src tools啥的只要对应的都复制过去。

bubuko.com,布布扣

2.      PIL直接安装即可

3.      PyDev解压后直接复制到MyEclipse中的dropins,这里的环境配置网上一抓一大把。

环境准备完成,代码如下:

 

fromVideoCapture import Device

importtime, string

interval= 2

 

cam =Device(devnum=0, showVideoWindow=0)

 

#cam.setResolution(648,480)

cam.saveSnapshot(‘image.jpg‘,timestamp=3, boldfont=1, quality=75)

 

i = 0

quant =interval * .1

starttime= time.time()

while 1:

    lasttime = now = int((time.time() -starttime) / interval)

    print i

    cam.saveSnapshot(‘image.jpg‘, timestamp=3,boldfont=1)

 

    i += 1

    while now == lasttime:

        now = int((time.time() - starttime) /interval)

       time.sleep(quant)

直接执行即可。

试运行,哈哈:

 bubuko.com,布布扣

 

详解及延伸:

对于DEVICE的各项参数解释官档解释如下:

class Device:

    """Create instances of this class which will then representvideo devices.

 

    For the lifetime of the instance, thedevice is blocked, so it can not be

    used by other applications (which is quitenormal Windows behavior).

    If you want to access the device fromanother program, you have to delete

    the instance first (e.g. del cam).

 

    """

    def __init__(self, devnum=0, showVideoWindow=0):

        """devnum: VideoCapture enumerates the available video capture devices

                    on your system.  If you have more than one device, specify

                    the desired one here.  The device number starts from 0.

 

           showVideoWindow: 0 ... do notdisplay a video window (the default)

                            1 ... display avideo window

 

                            Mainly used fordebugging, since the video window

                            can not be closedor moved around.

saveSnapshot的各项参数解释如下:

def saveSnapshot(self, filename, timestamp=0, boldfont=0,textpos=default_textpos, **keywords):

        """Saves a snapshot to the harddisk.

 

        The filetype depends on thefilename extension.  Everything that PIL

        can handle can be specified (foo.jpg,foo.gif, foo.bmp, ...).

 

        filename:   String containing the name of the resultingfile.

 

        timestamp:  see getImage()

 

        boldfont:   see getImage()

 

        textpos:    see getImage()

 

        Additional keyword arguments can begive which are just passed to the

        save() method of the Image class.  For example you can specify the

        compression level of a JPEG image byquality=75 (which is the default

        value anyway).

getImage的各项参数解释如下:

def getImage(self, timestamp=0, boldfont=0, textpos=default_textpos):

        """Returns a PIL Image instance.

 

        timestamp:  0 ... no timestamp (the default)

                    1 ... simple timestamp

                    2 ... timestamp withshadow

                    3 ... timestamp withoutline

 

        boldfont:   0 ... normal font (the default)

                    1 ... bold font

 

        textpos:    The position of the timestamp can bespecified by a string

                    containing a combination oftwo characters.  One character

                    must be either t or b, theother one either l, c or r.

 

                    t ... top

                    b ... bottom

 

                    l ... left

                    c ... center

                    r ... right

 

                    The default value is ‘bl

自己写的助于理解上述程序的程序:

import time

 

a=2

b=a*.1

i=0

print b

stime = time.time()

print stime

m=2

while m>i:

   lasttime = now = int((time.time()-stime)/a)

   print (‘i is: %s‘) %i

 

   i+=1

   print ‘进入while循环‘

   while now ==lasttime:

       now = int((time.time()-stime)/a)

       print (time.time()-stime)/a

       print (‘now is: %s‘) %now

       print (‘lasttime is: %s‘) %lasttime

       if now ==lasttime:

           print (‘lasttime == now‘)

       else:

           print (‘lasttime 不等于 now‘)

       time.sleep(b)

        print ‘休眠了%s秒‘ %b

Python 摄像头截图,布布扣,bubuko.com

Python 摄像头截图

标签:python   摄像头   截图   监控   摄像头监控   

原文地址:http://blog.csdn.net/woody891/article/details/29829509

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!