Skip to content

Commit

Permalink
UPD correctino in qr_extractor.py and update document preview
Browse files Browse the repository at this point in the history
  • Loading branch information
MALtUNEsmu committed Oct 6, 2023
1 parent 2cdf594 commit 7595df9
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 10 deletions.
1 change: 1 addition & 0 deletions processing/document_preview/docker/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
pdf2image==1.16.0
Pillow==9.3.0
opencv-python==4.8.0.76
6 changes: 5 additions & 1 deletion processing/document_preview/docker/script.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import os
from pdf2image import convert_from_path
import re
import cv2


def pdftoimages(target, max_pages):
Expand Down Expand Up @@ -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
Expand All @@ -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')
Expand Down
18 changes: 9 additions & 9 deletions processing/qrcode_extractor/qr_extractor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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
Expand Down

0 comments on commit 7595df9

Please sign in to comment.