generated from Tauffer-Consulting/domino_pieces_repository_template
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
92 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
# Use the base image | ||
FROM ghcr.io/tauffer-consulting/domino-base-piece:latest | ||
|
||
# Update package lists and install necessary dependencies | ||
RUN apt-get update && \ | ||
apt-get install -y \ | ||
python3-dev \ | ||
python3-pip \ | ||
libopencv-dev | ||
|
||
# Install OpenCV using pip (Python package manager) | ||
RUN pip3 install opencv-python-headless | ||
|
||
# Set working directory (optional) | ||
WORKDIR /app |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
{ | ||
"name": "OpenCVFilterPiece", | ||
"description": "Piece that uses OpenCV filter on an Image", | ||
"dependency": { | ||
"dockerfile": "Dockerfile_opencv" | ||
}, | ||
"tags": [ | ||
"image", | ||
"processing", | ||
"filter" | ||
], | ||
"style": { | ||
"node_label": "OpenCV Filter Piece", | ||
"node_style": { | ||
"backgroundColor": "#38b2be" | ||
}, | ||
"icon_class_name": "material-symbols:image-outline" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
from pydantic import BaseModel, Field | ||
from enum import Enum | ||
|
||
class FilterNaem(str, Enum): | ||
canny = "canny" | ||
binary = "binary" | ||
|
||
class InputModel(BaseModel): | ||
image_path: str = Field( | ||
title="Image Path", | ||
description="The path to the image to apply filter.", | ||
json_schema_extra={"from_upstream": "always"} | ||
) | ||
filter_name: FilterNaem = Field( | ||
title="Filter Name", | ||
description="The name of the filter to apply.", | ||
default="canny", | ||
) | ||
|
||
|
||
class OutputModel(BaseModel): | ||
image_path: str = Field( | ||
title="Output image Path", | ||
description="The path to the image with the filter applied.", | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
from domino.base_piece import BasePiece | ||
from .models import InputModel, OutputModel | ||
import pandas as pd | ||
from pathlib import Path | ||
from plotly.subplots import make_subplots | ||
import cv2 | ||
from pathlib import Path | ||
|
||
|
||
class OpenCVFilterPiece(BasePiece): | ||
|
||
def piece_function(self, input_data: InputModel): | ||
image = cv2.imread(input_data.image_path) | ||
gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY) | ||
if input_data.filter_name == "canny": | ||
edged = cv2.Canny(gray, 50, 100) | ||
elif input_data.filter_name == "binary": | ||
_, edged = cv2.threshold(gray, 100, 255, cv2.THRESH_BINARY) | ||
else: | ||
raise ValueError(f"Unknown filter name: {input_data.filter_name}") | ||
|
||
output_image_path = Path(self.results_path) / "opencv_image.png" | ||
cv2.imwrite(str(output_image_path), edged) | ||
self.display_result = { | ||
"file_type": "png", | ||
"file_path": str(output_image_path) | ||
} | ||
|
||
return OutputModel( | ||
image_path=str(output_image_path) | ||
) | ||
|
||
|