-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtest4.py
executable file
·61 lines (44 loc) · 1.39 KB
/
test4.py
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
#!/usr/bin/env python
import pygame
from pygame.locals import QUIT, KEYDOWN
import sys
import os
import re
URL_RE = re.compile(r'((mailto\:|(news|(ht|f)tp(s?))\://){1}\S+)')
import opencv
from opencv import highgui
import zbar
def get_image(camera):
im = highgui.cvQueryFrame(camera)
return opencv.adaptors.Ipl2PIL(im)
def get_code(img):
w, h = img.size
zimg = zbar.Image(w, h, 'Y800', img.convert('L').tostring())
proc = zbar.ImageScanner()
if proc.scan(zimg):
[sym] = list(zimg.symbols)
return sym.data
if __name__ == '__main__':
camera = highgui.cvCreateCameraCapture(0)
fps = 25
pygame.init()
window = pygame.display.set_mode((640,480))
pygame.display.set_caption("Get QR Code")
screen = pygame.display.get_surface()
while True:
events = pygame.event.get()
for event in events:
if event.type == QUIT or event.type == KEYDOWN:
sys.exit(0)
im = get_image(camera)
code = get_code(im)
if code:
if code:
os.system("beep")
os.system("echo")
print code
break
pg_img = pygame.image.frombuffer(im.tostring(), im.size, im.mode)
screen.blit(pg_img, (0,0))
pygame.display.flip()
pygame.time.delay(int(1000 * 1.0/fps))