Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature]: Extends Pull Request #152 Regarding Docker File and Configuration #172

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -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 && \
sanketshivale marked this conversation as resolved.
Show resolved Hide resolved
apt-get clean && \
apt-get -y autoremove

# Install Python dependencies
RUN pip3 install --user opencv-python-headless opencv-contrib-python-headless

# 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
sanketshivale marked this conversation as resolved.
Show resolved Hide resolved

# 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/"]
52 changes: 52 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,58 @@ Command: <code>python3 -m pip install --user --upgrade pip</code>
Link to Solution: <a href="https://github.com/Udayraj123/OMRChecker/issues/70#issuecomment-1268094136">#70</a>
</details>

## 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/).
- 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:
Copy link
Owner

@Udayraj123 Udayraj123 May 10, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's move this section into a dedicated file.

Suggested change
Once Docker is installed, you can run OMRChecker within a Docker container by following these steps:
For running OMRChecker using docker, please check the [readme-docker.md](https://github.com/Udayraj123/OMRChecker/tree/master/readme-docker.md)

Move this section details into a top level file readme-docker.md


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):
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After merging the dev branch, we will also consider publishing a docker image on dockerhub


```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.
sanketshivale marked this conversation as resolved.
Show resolved Hide resolved

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).
Expand Down
2 changes: 2 additions & 0 deletions src/utils/.Dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
samples/
src/tests/
13 changes: 11 additions & 2 deletions src/utils/interaction.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
import os
from dataclasses import dataclass

import cv2
from screeninfo import get_monitors
from screeninfo import Monitor, get_monitors

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")
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we shall also disable the call for imshow using this code change -

def show(name, origin, pause=1, resize=False, reset_pos=None, config=None):
        if(os.environ.get("OMR_CHECKER_CONTAINER")):
            return

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I required some assistance with these. As of now, I understand that we aim to refrain from displaying image metrics in DOCKER CONTAINER. If I am correct in this understanding, then with my current knowledge, I attempted to address the issue on my end. Please let me know if any clarification is needed.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can test it once by setting show_image_level to 5 in one of the samples, the code should still finish without any errors. If that works fine, above change should suffice.

else get_monitors()[0]
)


@dataclass
Expand All @@ -25,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!")
Expand Down