Commit 21a04dbc authored by Michael Murtaugh's avatar Michael Murtaugh

new printer

parent 6dcca5ff
Pipeline #436 failed with stages
......@@ -3,3 +3,7 @@
apt get install python-opencv
pip install imutils picamera python-escpos
<https://github.com/adafruit/Python-Thermal-Printer/blob/master/Adafruit_Thermal.py>
......@@ -5,8 +5,8 @@ import argparse
import os, sys
import cv2
from PIL import Image, ImageOps
# from escpos.exceptions import USBNotFoundError
from escpos.printer import Usb, Serial
from escpos.printer import Usb
from escpos.exceptions import USBNotFoundError
from time import sleep
import imutils
......@@ -98,7 +98,7 @@ def fit_size (im, box):
def make_print_version(im):
im = im.convert("L")
rw, rh = fit_size(im, (400, 10000))
rw, rh = fit_size(im, (384, 10000))
print ("rw, rh", rw, rh)
im = im.resize((rw, rh), resample=Image.BICUBIC) # Image.BICUBIC
......@@ -106,12 +106,9 @@ def make_print_version(im):
im = im.convert("1")
return im
def print_image (path, rotate=False):
def print_image_usb (path, rotate=False):
try:
if args.usb:
p = Usb(USB1,USB2) #, 0
else:
p = Serial(args.serial, args.baud)
p = Usb(USB1,USB2,0)
if path.startswith("http"):
f = urlopen(i['image'])
im = Image.open(f)
......@@ -119,6 +116,7 @@ def print_image (path, rotate=False):
im = Image.open(path)
if rotate:
im = im.rotate(90)
p.image(im)
p.cut()
# p.text("\n"*2)
......@@ -143,6 +141,11 @@ ap.add_argument("--baud", default=19200)
# escpos.printer.Serial(devfile=u'/dev/ttyS0', baudrate=9600, bytesize=8, timeout=1, parity='N', stopbits=1, xonxoff=False, dsrdtr=True, *args, **kwargs)
args = ap.parse_args()
if not args.usb:
from Adafruit_Thermal import *
printer = Adafruit_Thermal("/dev/serial0", 19200, timeout=5)
MODELS = os.path.expanduser(args.models)
os.system("mkdir -p images")
......@@ -203,4 +206,7 @@ while True:
current_face_pil = Image.fromarray(cv2.cvtColor(current_face_bgr,cv2.COLOR_BGR2RGB))
current_face_pil = make_print_version(current_face_pil)
current_face_pil.save(fname)
print_image(fname)
if args.usb:
print_image_usb(fname)
else:
printer.printImage(current_face_pil)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment