-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathQR.py
More file actions
76 lines (61 loc) · 1.62 KB
/
QR.py
File metadata and controls
76 lines (61 loc) · 1.62 KB
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
import cv2
import math
import os
import shutil
from PIL import Image
from pyzbar.pyzbar import decode
import xlwt
from xlwt import Workbook
cap = cv2.VideoCapture(0)
if not cap.isOpened():
raise IOError("Cannot open webcam")
path = "/Users/nikhilanu/Desktop/projects/opencv/data"
try:
shutil.rmtree(path)
except OSError:
print ("Deletion of the directory %s failed" % path)
else:
print ("Successfully deleted the directory %s" % path)
try:
os.makedirs(path)
except OSError:
print ("Creation of the directory %s failed" % path)
else:
print ("Successfully created the directory %s" % path)
currentframe = 0
l=[]
j=0
while True:
ret, frame = cap.read()
frame = cv2.resize(frame, None, fx=0.5, fy=0.5, interpolation=cv2.INTER_AREA)
cv2.imshow('Input', frame)
if ret:
name = './data/frame' + str(currentframe) + '.jpg'
#print ('Creating...' + name)
cv2.imwrite(name, frame)
decoded = decode(Image.open('./data/frame' + str(currentframe) + '.jpg'))
if decoded!=[]:
data=decoded[0].data
data=data.decode('utf-8')
if data in l:
pass
else:
l.append(data)
j=j+1
print(data)
currentframe += 1
else:
break
c = cv2.waitKey(1)
if c == 27:
break
wb = Workbook()
sheet1 = wb.add_sheet('Sheet 1')
for k in range (0,j):
words = l[k].split()
x=len(words)
for z in range (0,x):
sheet1.write(k, z, words[z])
wb.save('/Users/Desktop/xlwt example.xls')
cap.release()
cv2.destroyAllWindows()