From 075ea792a0efb46893798b1d181937488ff1bc64 Mon Sep 17 00:00:00 2001 From: sanketshivale Date: Mon, 4 Mar 2024 12:55:39 +0530 Subject: [PATCH 1/4] Add Docker instructions for running OMRChecker --- Dockerfile | 39 ++++++++++++++++++++++++++++++ README.md | 52 ++++++++++++++++++++++++++++++++++++++++ src/utils/interaction.py | 8 +++++-- 3 files changed, 97 insertions(+), 2 deletions(-) create mode 100644 Dockerfile diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 00000000..1caceafb --- /dev/null +++ b/Dockerfile @@ -0,0 +1,39 @@ +# Use the Python 3.11 slim image as the base image +FROM python:3.11-slim + +# Set the working directory inside the container +WORKDIR /app + +# Enable non-interactive mode for debconf +RUN echo 'debconf debconf/frontend select Noninteractive' | debconf-set-selections + +# Update the package repository and install required dependencies +RUN apt-get update -y && \ + apt-get install -y build-essential cmake unzip pkg-config \ + libjpeg-dev libpng-dev libtiff-dev \ + libavcodec-dev libavformat-dev libswscale-dev libv4l-dev \ + libatlas-base-dev gfortran && \ + apt-get clean && \ + apt-get -y autoremove + +# Install Python dependencies +RUN pip3 install --user opencv-python opencv-contrib-python + +# Copy over the development and production requirements files +COPY ./requirements.dev.txt /app +COPY ./requirements.txt /app + +# Install additional Python dependencies for development +RUN pip3 install -r requirements.dev.txt + +# Copy the entire project into the container +COPY . /app + +# Clean up pip cache +RUN pip3 cache purge + +# Set environment variables +ENV OMR_CHECKER_CONTAINER True + +# Set the default command to run the main Python script +CMD ["python3", "/app/main.py", "--inputDir", "/app/inputs/", "--outputDir", "/app/outputs/"] diff --git a/README.md b/README.md index cd9acb4d..c31656ec 100644 --- a/README.md +++ b/README.md @@ -214,6 +214,58 @@ Command: python3 -m pip install --user --upgrade pip Link to Solution: #70 +## Running OMRChecker in a Docker Container + +If you prefer to run OMRChecker in isolation without impacting your system's Python environment, you can utilize Docker. Follow the steps below to set it up: + +### Docker Installation + +1. **Install Docker Desktop:** + - For Windows and macOS users, download and install Docker Desktop from [Docker Hub](https://docs.docker.com/desktop/install/windows-install/). + - For Linux users, follow the instructions provided in the official [Docker documentation](https://docs.docker.com/desktop/install/linux-install/) for your specific distribution. + +2. **Verify Installation:** + - After installation, open a terminal (or command prompt) and run the following command to verify that Docker is installed correctly: + ```bash + docker --version + ``` + - This should display the installed Docker version, indicating that Docker is installed successfully. + + +### Running OMRChecker in Docker + +Once Docker is installed, you can run OMRChecker within a Docker container by following these steps: + +1. Clone the repository and navigate into it: + + ```bash + git clone https://github.com/Udayraj123/OMRChecker + cd OMRChecker/ + ``` + +2. Build the Docker container image (Initial build may take up to 2 minutes depending on your network connection): + + ```bash + docker buildx build -t omrchecker:1.0 . + ``` + +3. Run the Docker container to process the exam images: + + - First, ensure you have your exam images, target image, and `template.json` file ready in the `inputs` directory. + + - Now, run the container, which will automatically mark the exams and place the results in the `outputs/` directory: + + ```bash + docker run -t --rm -v $(pwd)/inputs/:/app/inputs/ -v $(pwd)/outputs/:/app/outputs/ omrchecker:1.0 + ``` + + This command mounts the `inputs/` and `outputs/` directories from your host machine to the respective directories inside the container, allowing data exchange. + +4. After the process completes, you can find the marked exams in the `outputs/` directory. + +By following these steps, you can efficiently use OMRChecker within a Docker container without affecting your local Python environment. + + ## OMRChecker for custom OMR Sheets 1. First, [create your own template.json](https://github.com/Udayraj123/OMRChecker/wiki/User-Guide). diff --git a/src/utils/interaction.py b/src/utils/interaction.py index 1036f5b3..4dc78af0 100644 --- a/src/utils/interaction.py +++ b/src/utils/interaction.py @@ -1,12 +1,16 @@ from dataclasses import dataclass import cv2 -from screeninfo import get_monitors +import os +from screeninfo import get_monitors, Monitor from src.logger import logger from src.utils.image import ImageUtils -monitor_window = get_monitors()[0] +#If running in a container, make a fake monitor +monitor_window = Monitor(0, 0, 1000, 1000, 100, 100, 'FakeMonitor', False) \ + if os.environ.get("OMR_CHECKER_CONTAINER") \ + else get_monitors()[0] @dataclass From 6007abb43906fdbd80f83c522c216ae6ebace619 Mon Sep 17 00:00:00 2001 From: Sanket Shivale <85338561+sanketshivale@users.noreply.github.com> Date: Mon, 4 Mar 2024 15:13:18 +0530 Subject: [PATCH 2/4] Update interaction.py --- src/utils/interaction.py | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/utils/interaction.py b/src/utils/interaction.py index 4dc78af0..0c27cfec 100644 --- a/src/utils/interaction.py +++ b/src/utils/interaction.py @@ -1,16 +1,18 @@ +import os from dataclasses import dataclass import cv2 -import os -from screeninfo import get_monitors, Monitor +from screeninfo import Monitor, get_monitors from src.logger import logger from src.utils.image import ImageUtils -#If running in a container, make a fake monitor -monitor_window = Monitor(0, 0, 1000, 1000, 100, 100, 'FakeMonitor', False) \ - if os.environ.get("OMR_CHECKER_CONTAINER") \ - else get_monitors()[0] +# If running in a container, make a fake monitor +monitor_window = ( + Monitor(0, 0, 1000, 1000, 100, 100, "FakeMonitor", False) + if os.environ.get("OMR_CHECKER_CONTAINER") + else get_monitors()[0] +) @dataclass From 0413bb0214a013aa2cb193276429aa7b8daf3363 Mon Sep 17 00:00:00 2001 From: Sanket Shivale <85338561+sanketshivale@users.noreply.github.com> Date: Sun, 5 May 2024 20:53:06 +0530 Subject: [PATCH 3/4] Update README.md Co-authored-by: Udayraj Deshmukh --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index cfbf3f89..27a3dd21 100644 --- a/README.md +++ b/README.md @@ -217,7 +217,7 @@ If you prefer to run OMRChecker in isolation without impacting your system's Pyt ### Docker Installation 1. **Install Docker Desktop:** - - For Windows and macOS users, download and install Docker Desktop from [Docker Hub](https://docs.docker.com/desktop/install/windows-install/). + - For Windows and macOS users, download and install Docker Desktop from [Docker Hub](https://docs.docker.com/desktop/). - For Linux users, follow the instructions provided in the official [Docker documentation](https://docs.docker.com/desktop/install/linux-install/) for your specific distribution. 2. **Verify Installation:** From 545368d19a57f6ae57d2f262a85b0ec97723d7d0 Mon Sep 17 00:00:00 2001 From: sanketshivale Date: Mon, 6 May 2024 23:44:00 +0530 Subject: [PATCH 4/4] feat: Update Dockerfile to use headless versions of OpenCV --- Dockerfile | 2 +- src/utils/.Dockerignore | 2 ++ src/utils/interaction.py | 3 +++ 3 files changed, 6 insertions(+), 1 deletion(-) create mode 100644 src/utils/.Dockerignore diff --git a/Dockerfile b/Dockerfile index 1caceafb..67d3ee42 100644 --- a/Dockerfile +++ b/Dockerfile @@ -17,7 +17,7 @@ RUN apt-get update -y && \ apt-get -y autoremove # Install Python dependencies -RUN pip3 install --user opencv-python opencv-contrib-python +RUN pip3 install --user opencv-python-headless opencv-contrib-python-headless # Copy over the development and production requirements files COPY ./requirements.dev.txt /app diff --git a/src/utils/.Dockerignore b/src/utils/.Dockerignore new file mode 100644 index 00000000..ecc4fc60 --- /dev/null +++ b/src/utils/.Dockerignore @@ -0,0 +1,2 @@ +samples/ +src/tests/ \ No newline at end of file diff --git a/src/utils/interaction.py b/src/utils/interaction.py index 0c27cfec..d0d0be5f 100644 --- a/src/utils/interaction.py +++ b/src/utils/interaction.py @@ -31,6 +31,9 @@ class InteractionUtils: @staticmethod def show(name, origin, pause=1, resize=False, reset_pos=None, config=None): + if(os.environ.get("OMR_CHECKER_CONTAINER")): + return + image_metrics = InteractionUtils.image_metrics if origin is None: logger.info(f"'{name}' - NoneType image to show!")