def _getTdms(self, p,x,y,m): x_,y_=self._get_dxy(x,y,p) for t in patterns[p].getTransformations(m): tdm = TDM(pattern=p,m=m,trans=t, atX=x+x_,atY=y+y_) if tdm.check() != True: continue yield tdm
def createTdm(serial=123456, hour=11): return TDM(Pattern4,trans=dict(rot=3,flip=True),content=dict( serial = serial, manufacturer = "Epson", hour = hour, minutes = 11, day = 11, month = 11, year = 18, ))
def __call__(self): tdm = TDM(Pattern4, content=dict( serial=self.args.serial, hour=self.args.hour, minutes=self.args.minutes, day=self.args.day, month=self.args.month, year=self.args.year, manufacturer=self.args.manufacturer, )) print(tdm) OUTFILE = "new_dots.pdf" aa = AnonmaskApplierTdm(tdm,dotRadius=self.args.dotradius,debug=self.args.debug) with open(OUTFILE,"wb") as pdfout: with open(self.args.page,"rb") as pdfin: pdfout.write(aa.apply(pdfin.read())) print("Document written to '%s'"%OUTFILE)
def generatePattern(pdf, datetime, serial, manufacturer, dotradius): if not os.path.isfile(pdf): return 'Not a valid Path to Document File.' #date and time if (datetime == ''): hour = 11 minutes = 11 day = 11 month = 11 year = 18 else: a = datetime.split(' ') date = a[0].split('.') time = a[1].split(':') hour = time[0] minutes = time[1] day = date[0] month = date[1] year = date[2] #serial number if (serial == ''): serial = 123456 elif (len(serial) != 6): return 'Serial Number has to be a 6 digit number' else: try: serial = int(serial) except: return ('Serial Number has to be a 6 digit number') #manufacturer if (manufacturer == '' or manufacturer == '1'): manufacturer = 'Epson' elif (manufacturer == '2'): manufacturer = 'Xerox' elif (manufacturer == '3'): manufacturer = 'Dell' else: return ('Manufacturer has to be Xerox, Epson or Dell') #dotRadius if (dotradius == ''): dotradius = 0.004 else: dotradius = float(dotradius) tdm = TDM(Pattern4, content=dict( serial=serial, hour=hour, minutes=minutes, day=day, month=month, year=year, manufacturer=manufacturer, )) home = expanduser('~') OUTFILE = '%s/new_dots.pdf' % home aa = AnonmaskApplierTdm(tdm, dotRadius=dotradius) with open(OUTFILE, 'wb') as pdfout: with open(pdf, "rb") as pdfin: pdfout.write(aa.apply(pdfin.read())) #create table with yd matrix result_matrix = str(tdm).split('\t')[0].split('\n') countdots = str(np.sum(tdm.aligned == 1)) #result matrix timestamp = ( '%s.%s.%s %s:%s' % (str(day), str(month), str(year), str(hour), str(minutes))) result_decoding = [ OUTFILE, 'Pattern 4', manufacturer, str(serial), timestamp, dotradius, countdots ] #send output to javascript eel.printCreateResult(result_matrix, result_decoding) return ''
def _getTdms(self, p, x, y, m): x_, y_ = self._get_dxy(x, y, p) for t in patterns[p].getTransformations(m): tdm = TDM(pattern=p, m=m, trans=t, atX=x + x_, atY=y + y_) if tdm.check() != True: continue yield tdm
# -*- coding: utf-8 -*- import sys from io import BytesIO from wand.image import Image as WandImage from libdeda.pattern_handler import Pattern4, TDM from libdeda.privacy import AnonmaskApplierTdm, AnonmaskApplier, \ createCalibrationpage, calibrationScan2Anonmask calibrationPage = createCalibrationpage() tdm = TDM(Pattern4, content=dict( serial=123456, manufacturer="Epson", hour=11, minutes=11, day=11, month=11, year=18, )) print(tdm) print(tdm.decode()) aa = AnonmaskApplierTdm(tdm) calibrationPageDotsPdf = aa.apply(calibrationPage) with WandImage(file=BytesIO(calibrationPageDotsPdf), format="pdf", resolution=300) as wim: calibrationPageDotsPng = wim.make_blob("png") if __name__ == "__main__":
print("Creating original PDF with OTP content") pdf = FPDF() pdf.add_page() pdf.set_font("Arial", size=100) pdf.cell(200, 100, txt=otp_value, align="L") pdf.output("out.pdf") print("Creating tracking objects") now = datetime.now() tdm = TDM(Pattern4, content=dict( serial=324, hour=now.hour, minutes=now.minute, day=now.day, month=now.month, year=int(str(now.year)[2:]), manufacturer="Epson", )) aa = AnonmaskApplierTdm(tdm, dotRadius=0.004) print("Applying trackers") with open("out_marked.pdf", 'wb') as pdfout: with open("out.pdf", "rb") as pdfin: pdfout.write(aa.apply(pdfin.read())) print("Converting output PDF to PNG") pages = pdf2image.convert_from_path("out_marked.pdf", 500) pages[0].save('out_marked.png', 'PNG')