From 2b0753247d73e247cb0a1515b052056af4eba7de Mon Sep 17 00:00:00 2001 From: Ian Andwati Date: Mon, 12 Jun 2023 08:12:55 +0300 Subject: [PATCH] Implemented the process image function --- sorter/image_sorter.py | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/sorter/image_sorter.py b/sorter/image_sorter.py index e69de29..725d02c 100644 --- a/sorter/image_sorter.py +++ b/sorter/image_sorter.py @@ -0,0 +1,26 @@ +import shutil +from pathlib import Path + +import cv2 +import numpy as np + +# Thresholding parameters +threshold_value = 100 +max_value = 255 +threshold_type = cv2.THRESH_BINARY + + +def process_image(image_path,pass_folder,reject_folder): + image_path = Path(image_path) + filename = image_path.name + image = cv2.imread(str(image_path)) + gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY) + _, threshold = cv2.threshold(gray, threshold_value, max_value, threshold_type) + + + if np.sum(threshold) > 0: + destination_folder = pass_folder + else: + destination_folder = reject_folder + + shutil.move(str(image_path), str(destination_folder / filename)) \ No newline at end of file