From 7595df97433d1cda4a1fe6a7d6c169b6b9895dee Mon Sep 17 00:00:00 2001 From: MALtUNEsmu <139252220+MALtUNEsmu@users.noreply.github.com> Date: Fri, 6 Oct 2023 17:14:05 +0200 Subject: [PATCH] UPD correctino in qr_extractor.py and update document preview --- .../document_preview/docker/requirements.txt | 1 + processing/document_preview/docker/script.py | 6 +++++- processing/qrcode_extractor/qr_extractor.py | 18 +++++++++--------- 3 files changed, 15 insertions(+), 10 deletions(-) diff --git a/processing/document_preview/docker/requirements.txt b/processing/document_preview/docker/requirements.txt index 81e4f37..75a0741 100644 --- a/processing/document_preview/docker/requirements.txt +++ b/processing/document_preview/docker/requirements.txt @@ -1,2 +1,3 @@ pdf2image==1.16.0 Pillow==9.3.0 +opencv-python==4.8.0.76 \ No newline at end of file diff --git a/processing/document_preview/docker/script.py b/processing/document_preview/docker/script.py index 598850c..df92441 100644 --- a/processing/document_preview/docker/script.py +++ b/processing/document_preview/docker/script.py @@ -2,6 +2,7 @@ import os from pdf2image import convert_from_path import re +import cv2 def pdftoimages(target, max_pages): @@ -36,7 +37,6 @@ def libreofficeconversion(args): print('error: libreoffice could not convert file to PDF') return False - def main(args): # if office file, convert to pdf file with libreoffice library @@ -48,6 +48,10 @@ def main(args): pdftoimages(args.target, args.max_pages) # if another type # try to convert to pdf with libreoffice + elif args.target_type == 'jpg' or args.target_type == 'png' or args.target_type == 'jpeg': + #cv2.imread(args, cv2.IMREAD_ANYCOLOR) + cv2.imwrite('./output/output_1.jpeg') + pass else: print('warning: Unsupported target file') print('warning: libreoffice will try to convert the file to PDF') diff --git a/processing/qrcode_extractor/qr_extractor.py b/processing/qrcode_extractor/qr_extractor.py index d4cf378..1e64367 100644 --- a/processing/qrcode_extractor/qr_extractor.py +++ b/processing/qrcode_extractor/qr_extractor.py @@ -23,7 +23,7 @@ class QrCodeExtractor(ProcessingModule): name = "qr_extractor" description = "Analyze files (via screenchot) and pictures (directly) to find QRcodes and decode them with two different libs." acts_on = ["png", "pdf", "word", "html", "excel", "powerpoint"] - #triggered_by = "document_preview" + triggered_by = "document_preview" config = [ { "name": "skip_safe_file_review", @@ -47,8 +47,8 @@ def initialize(self): # possibly => mutualize Read image target # decode QRcode - def extract_qr_code_by_opencv(target): - image = cv2.imread(target, 0) + def extract_qr_code_by_opencv(img): + image = cv2.imread(img, 0) try: detect = cv2.QRCodeDetector() value, points, straight_qrcode = detect.detectAndDecode(image) @@ -57,8 +57,8 @@ def extract_qr_code_by_opencv(target): except: return - def extract_qr_code_by_pyzbar(target): - image = cv2.imread(target, 0) + def extract_qr_code_by_pyzbar(img): + image = cv2.imread(img, 0) try: value = decode(image) print(value) @@ -70,12 +70,12 @@ def each(self, target): self.results = {} # Get QRcode - self.results[">PYZBAR"] = extract_qr_code_by_pyzbar(target) - self.results[">OPENCV"] = extract_qr_code_by_opencv(target) - # add ioc for the url decoded + self.results[">PYZBAR"] = self.extract_qr_code_by_pyzbar(target) + self.results[">OPENCV"] = self.extract_qr_code_by_opencv(target) + self.add_ioc(results) + #TO-DO add ioc for the url decoded only #if filetype == "url" and not target.startswith("http"): # target = "http://{}".format(target) - #if filetype == "url": # self.add_ioc(target) return True