From 69cac0bd4775e4482f8d3f9081f8ea083823d82d Mon Sep 17 00:00:00 2001 From: localhorst Date: Mon, 25 Dec 2023 21:51:08 +0100 Subject: [PATCH] split workflow and documentation --- README.md | 41 +++++++++++++++++++++------- convert_photos.py | 69 +++++++++++++++++++++++++++++++++++++++++++++++ extract_photos.py | 2 +- scan_photos.py | 2 +- 4 files changed, 103 insertions(+), 11 deletions(-) create mode 100644 convert_photos.py diff --git a/README.md b/README.md index 3918637..734c456 100644 --- a/README.md +++ b/README.md @@ -1,13 +1,5 @@ # ultimate-photo-digitizer - -## Scanner comands - -``` -scanimage --progress --output-file 01.png --format=png --mode Color --resolution 2400 --verbose --depth 16 -``` - - ## Setup ``` @@ -16,8 +8,39 @@ pip install opencv-python-headless zypper install avif-tools ``` +## Usage +### Step 1: Scan analog photos +1. Create `scans` folder. +2. Place four analog photos in scanner bed, align edges with scanner. But keep a margin of 1cm between photos and between the scanner. +3. Scan the photos via `python3 ./scan_photos.py destination_dir=scans/` +4. Repeat step 2 to 3 until all photos are scanned. + +### Step 2: Extract the single photos from the scan + +1. Create `tmp` folder. +2. Extract the photos via `python3 extract_photos.py source_dir=scans/ destination_dir=tmp/` + +### Step 3: Rotate the extracted photos + +1. Use any image viewer, like gwenview, to rotate and save the photos if necessary. + +### Step 4: Convert the extracted photos to AVIF + +1. Create `photos` folder. +2. Convert the photos via `python3 convert_photos.py source_dir=scans/ destination_dir=photos/` + +## Sync folders between machines + +### Push scans to server `rsync -Pav -e "ssh -i $HOME/.ssh/SDS" /home/hendrik/git/ultimate-photo-digitizer/scans/ hendrik@10.0.0.25:/home/hendrik/git/ultimate-photo-digitizer/scans/` -`rsync -Pav -e "ssh -i $HOME/.ssh/SDS" hendrik@10.0.0.25:/home/hendrik/git/ultimate-photo-digitizer/photos/ /home/hendrik/git/ultimate-photo-digitizer/photos/` \ No newline at end of file +### Pull tmp from server +`rsync -Pav -e "ssh -i $HOME/.ssh/SDS" hendrik@10.0.0.25:/home/hendrik/git/ultimate-photo-digitizer/tmp/ /home/hendrik/git/ultimate-photo-digitizer/tmp/` + +### Push tmp to server +`rsync -Pav -e "ssh -i $HOME/.ssh/SDS" /home/hendrik/git/ultimate-photo-digitizer/tmp/ hendrik@10.0.0.25:/home/hendrik/git/ultimate-photo-digitizer/tmp/` + +### Pull photos from server +`rsync -Pav -e "ssh -i $HOME/.ssh/SDS" hendrik@10.0.0.25:/home/hendrik/git/ultimate-photo-digitizer/photos/ /home/hendrik/git/ultimate-photo-digitizer/photos/` diff --git a/convert_photos.py b/convert_photos.py new file mode 100644 index 0000000..ac477f2 --- /dev/null +++ b/convert_photos.py @@ -0,0 +1,69 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- +""" Author: Hendrik Schutter, mail@hendrikschutter.com +""" + +import cv2 +import sys +import os +import subprocess + +def convert_to_avif(input_file_path, output_dir_path): + # print("input_file_path: " + str(input_file_path)) + # print("output_dir_path: " + str(output_dir_path)) + + output_file_path = os.path.join(output_dir_path,(os.path.splitext(os.path.basename(os.path.normpath(input_file_path)))[0] + ".avif")) + + cmd_handle = subprocess.Popen(["avifenc", "--jobs", "all", input_file_path, output_file_path], stdout=subprocess.PIPE) + cmd_handle.communicate()[0] + if cmd_handle.returncode != 0: + raise Exception("Unable to convert via avifenc! Return code: " + str(cmd_handle.returncode)) + + cmd_handle = subprocess.Popen(["sync",],stdout=subprocess.PIPE,) + cmd_handle.communicate()[0] + if cmd_handle.returncode != 0: + raise Exception("Unable to sync! Return code: " + str(cmd_handle.returncode)) + +def main(): + print("starting ...") + + destination_dir_path = -1 + source_dir_path = -1 + + for argument in sys.argv: + if argument.startswith("destination_dir"): + destination_dir_path = argument.split("=")[1] + if argument.startswith("source_dir"): + source_dir_path = argument.split("=")[1] + + if (destination_dir_path == -1) or (source_dir_path == -1): + print("Unable to parse config!") + print("Example usage:") + print( + " python convert_photos.py source_dir=tmp/ destination_dir=photos/" + ) + sys.exit(-1) + + failed_conventions = 0 + + for path in os.listdir(source_dir_path): + if os.path.isfile(os.path.join(source_dir_path, path)): + print("Found photo: " + str(os.path.join(source_dir_path, path)), end=" ") + sys.stdout.flush() + try: + convert_to_avif(os.path.join(source_dir_path, path), destination_dir_path) + print(" → Successfully converted photo to avif") + except Exception as e: + print(str(e)) + failed_conventions = failed_conventions + 1 + + if(failed_conventions == 0): + print("\nConvert without error") + sys.exit(0) + else: + print("Unable to convert " + str(failed_conventions) + " photos.") + print("\nExiting with error") + sys.exit(-1) + +if __name__ == "__main__": + main() diff --git a/extract_photos.py b/extract_photos.py index 8cc53a8..d72dc37 100644 --- a/extract_photos.py +++ b/extract_photos.py @@ -96,7 +96,7 @@ def main(): print("Unable to parse config!") print("Example usage:") print( - " python extract_photos.py source_dir=scans/ destination_dir=photos/" + " python extract_photos.py source_dir=scans/ destination_dir=tmp/" ) sys.exit(-1) diff --git a/scan_photos.py b/scan_photos.py index 90833dd..8ba6bc8 100644 --- a/scan_photos.py +++ b/scan_photos.py @@ -24,7 +24,7 @@ def main(): if (destination_dir_path == -1): print("Unable to parse config!") print("Example usage:") - print(" python scan_photos.py destination_dir=scans/ ") + print(" python scan_photos.py destination_dir=scans/") sys.exit(-1) filename = time.strftime("%Y-%m-%d_%H-%M-%S.png")