2
# -*- coding: utf-8 -*-
5
# Copyright (C) 2013 ~ 2014 National University of Defense Technology(NUDT) & Kylin Ltd
8
# This program is free software: you can redistribute it and/or modify it
9
# under the terms of the GNU General Public License version 3, as published
10
# by the Free Software Foundation.
12
# This program is distributed in the hope that it will be useful, but
13
# WITHOUT ANY WARRANTY; without even the implied warranties of
14
# MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
15
# PURPOSE. See the GNU General Public License for more details.
17
# You should have received a copy of the GNU General Public License along
18
# with this program. If not, see <http://www.gnu.org/licenses/>.
20
#sudo apt-get install python-pygame
25
from pygame.locals import *
28
def get_local_format_time():
30
year-month-day hour:minute:second
33
local_date = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(time.time()))
36
#class Capture(object):
37
class Capture(threading.Thread):
39
threading.Thread.__init__(self)
43
def judge_camera(self):
44
clist = pygame.camera.list_cameras()#['/dev/video0']
47
# raise ValueError("Sorry, no cameras detected.")
51
def call_camera(self):
52
threading.Thread(target=self.call_camera_real, name='Capture').start()
54
def call_camera_real(self):
56
self.clist = pygame.camera.list_cameras()#['/dev/video0']
57
self.display = pygame.display.set_mode(self.size, 0)
58
self.snapshot = pygame.surface.Surface(self.size, 0, self.display)
59
self.cam = pygame.camera.Camera(self.clist[0], self.size,"RGB")
62
timevalue = "00-00-00"
64
events = pygame.event.get()
66
if e.type == QUIT or (e.type == KEYDOWN and e.key == K_ESCAPE):
68
pic_name = get_local_format_time() + '.png'
71
if self.cam.query_image():
72
self.snapshot = self.cam.get_image(self.snapshot)
73
self.display.blit(self.snapshot, (0,0))
75
pic_path = os.path.expanduser('~') + '/' + pic_name
76
#pic_path = os.path.join('/home/trusty', pic_name)
77
#os.path.expanduser('~')
78
#pic_name = '/home/trusty/' + timevalue + '.png'
79
pygame.image.save(self.snapshot, pic_path)
83
#if __name__ == '__main__':
85
# if mycam.judge_camera():