-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutil.py
More file actions
78 lines (59 loc) · 2.06 KB
/
util.py
File metadata and controls
78 lines (59 loc) · 2.06 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
77
78
import cv2
import qrcode
from PIL import Image, ImageEnhance
import numpy as np
from escpos.printer import Usb
def imageCombine(frame_path, image, index):
# 공백 프레임 가져오기
main_frame = cv2.imread('./image/frames/bin.png')
# 프레임 이미지 생성
frame = cv2.imread(frame_path, cv2.IMREAD_UNCHANGED)
# frame = cv2.add(frame, 100)
# 프레임 마스크 생성
_, mask = cv2.threshold(frame[:,:,3], 0, 255, cv2.THRESH_BINARY)
mask_inv = cv2.bitwise_not(mask)
mask_inv = cv2.bitwise_not(mask_inv)
# 영상 스크린샷 사이즈 조절
# image = saturate_contrast2(image, 2)
dst = cv2.resize(image, dsize=(640 // 2, 480 // 2), interpolation=cv2.INTER_AREA)
# br = ImageEnhance.Brightness(dst)
# dst = br.enhance(1.5)
# dst = cv2.add(dst, 100)
if index % 2 == 0:
main_frame[0:240, 160:480] = dst
else:
main_frame[0:240, 0:320] = dst
framed = cv2.bitwise_and(frame, frame, mask_inv)[:, :, :3]
main_frame[mask_inv > 0] = framed[mask_inv > 0]
return main_frame
def qrGenerate(url, id):
qrimg = cv2.imread('./image/frames/logo/sscc.jpg')
qr = qrcode.QRCode(version=1, box_size=3, border=5)
qr.add_data(url+"images/"+id)
qr.make(fit=True)
qr_temp = qr.make_image(fill_color = "black", back_color="white")
qr_temp.save('./image/capture/temp/qr.jpg')
qr_img = cv2.imread('./image/capture/temp/qr.jpg')
qrimg[0:128, 384:512] = qr_img[0:128, 0:128]
# print(qr_img)
cv2.imwrite("image/capture/temp.jpg", qrimg)
return
def saturate_contrast2(p, num):
pic = p.copy()
pic = pic.astype('int32')
pic = np.clip(pic+(pic-128)*num, 0, 255)
pic = pic.astype('uint8')
return pic
def serial_print(target):
p = Usb(0x1fc9, 0x2016, in_ep=0x81, out_ep=0x01)
try:
p.set(font="a", height=2, align="center")
p.image(target, fragment_height=3)
except:
print("PRINT ERROR OCCURED")
def serial_cut():
p = Usb(0x1fc9, 0x2016, in_ep=0x81, out_ep=0x01)
try:
p.cut()
except:
...