fzliu
/
emulate-sign-and-scan
copied
committed by
Frank Liu
commit
074b55b906
6 changed files with 380 additions and 0 deletions
@ -0,0 +1,35 @@ |
|||
# .gitattributes |
|||
|
|||
# Source files |
|||
# ============ |
|||
*.pxd text diff=python |
|||
*.py text diff=python |
|||
*.py3 text diff=python |
|||
*.pyw text diff=python |
|||
*.pyx text diff=python |
|||
*.pyz text diff=python |
|||
*.pyi text diff=python |
|||
|
|||
# Binary files |
|||
# ============ |
|||
*.db binary |
|||
*.p binary |
|||
*.pkl binary |
|||
*.pickle binary |
|||
*.pyc binary export-ignore |
|||
*.pyo binary export-ignore |
|||
*.pyd binary |
|||
|
|||
# Jupyter notebook |
|||
*.ipynb text |
|||
|
|||
# Model files |
|||
*.bin.* filter=lfs diff=lfs merge=lfs -text |
|||
*.lfs.* filter=lfs diff=lfs merge=lfs -text |
|||
*.bin filter=lfs diff=lfs merge=lfs -text |
|||
*.h5 filter=lfs diff=lfs merge=lfs -text |
|||
*.tflite filter=lfs diff=lfs merge=lfs -text |
|||
*.tar.gz filter=lfs diff=lfs merge=lfs -text |
|||
*.ot filter=lfs diff=lfs merge=lfs -text |
|||
*.onnx filter=lfs diff=lfs merge=lfs -text |
|||
*.msgpack filter=lfs diff=lfs merge=lfs -text |
|||
@ -0,0 +1,209 @@ |
|||
### Linux ### |
|||
*~ |
|||
|
|||
# temporary files which can be created if a process still has a handle open of a deleted file |
|||
.fuse_hidden* |
|||
|
|||
# KDE directory preferences |
|||
.directory |
|||
|
|||
# Linux trash folder which might appear on any partition or disk |
|||
.Trash-* |
|||
|
|||
# .nfs files are created when an open file is removed but is still being accessed |
|||
.nfs* |
|||
|
|||
### OSX ### |
|||
# General |
|||
.DS_Store |
|||
.AppleDouble |
|||
.LSOverride |
|||
|
|||
# Icon must end with two \r |
|||
Icon |
|||
|
|||
|
|||
# Thumbnails |
|||
._* |
|||
|
|||
# Files that might appear in the root of a volume |
|||
.DocumentRevisions-V100 |
|||
.fseventsd |
|||
.Spotlight-V100 |
|||
.TemporaryItems |
|||
.Trashes |
|||
.VolumeIcon.icns |
|||
.com.apple.timemachine.donotpresent |
|||
|
|||
# Directories potentially created on remote AFP share |
|||
.AppleDB |
|||
.AppleDesktop |
|||
Network Trash Folder |
|||
Temporary Items |
|||
.apdisk |
|||
|
|||
### Python ### |
|||
# Byte-compiled / optimized / DLL files |
|||
__pycache__/ |
|||
*.py[cod] |
|||
*$py.class |
|||
|
|||
# C extensions |
|||
*.so |
|||
|
|||
# Distribution / packaging |
|||
.Python |
|||
build/ |
|||
develop-eggs/ |
|||
dist/ |
|||
downloads/ |
|||
eggs/ |
|||
.eggs/ |
|||
lib/ |
|||
lib64/ |
|||
parts/ |
|||
sdist/ |
|||
var/ |
|||
wheels/ |
|||
share/python-wheels/ |
|||
*.egg-info/ |
|||
.installed.cfg |
|||
*.egg |
|||
MANIFEST |
|||
|
|||
# PyInstaller |
|||
# Usually these files are written by a python script from a template |
|||
# before PyInstaller builds the exe, so as to inject date/other infos into it. |
|||
*.manifest |
|||
*.spec |
|||
|
|||
# Installer logs |
|||
pip-log.txt |
|||
pip-delete-this-directory.txt |
|||
|
|||
# Unit test / coverage reports |
|||
htmlcov/ |
|||
.tox/ |
|||
.nox/ |
|||
.coverage |
|||
.coverage.* |
|||
.cache |
|||
nosetests.xml |
|||
coverage.xml |
|||
*.cover |
|||
*.py,cover |
|||
.hypothesis/ |
|||
.pytest_cache/ |
|||
cover/ |
|||
|
|||
# Translations |
|||
*.mo |
|||
*.pot |
|||
|
|||
# Django stuff: |
|||
*.log |
|||
local_settings.py |
|||
db.sqlite3 |
|||
db.sqlite3-journal |
|||
|
|||
# Flask stuff: |
|||
instance/ |
|||
.webassets-cache |
|||
|
|||
# Scrapy stuff: |
|||
.scrapy |
|||
|
|||
# Sphinx documentation |
|||
docs/_build/ |
|||
|
|||
# PyBuilder |
|||
.pybuilder/ |
|||
target/ |
|||
|
|||
# Jupyter Notebook |
|||
.ipynb_checkpoints |
|||
|
|||
# IPython |
|||
profile_default/ |
|||
ipython_config.py |
|||
|
|||
# pyenv |
|||
# For a library or package, you might want to ignore these files since the code is |
|||
# intended to run in multiple environments; otherwise, check them in: |
|||
# .python-version |
|||
|
|||
# pipenv |
|||
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. |
|||
# However, in case of collaboration, if having platform-specific dependencies or dependencies |
|||
# having no cross-platform support, pipenv may install dependencies that don't work, or not |
|||
# install all needed dependencies. |
|||
#Pipfile.lock |
|||
|
|||
# PEP 582; used by e.g. github.com/David-OConnor/pyflow |
|||
__pypackages__/ |
|||
|
|||
# Celery stuff |
|||
celerybeat-schedule |
|||
celerybeat.pid |
|||
|
|||
# SageMath parsed files |
|||
*.sage.py |
|||
|
|||
# Environments |
|||
.env |
|||
.venv |
|||
env/ |
|||
venv/ |
|||
ENV/ |
|||
env.bak/ |
|||
venv.bak/ |
|||
|
|||
# Spyder project settings |
|||
.spyderproject |
|||
.spyproject |
|||
|
|||
# Rope project settings |
|||
.ropeproject |
|||
|
|||
# mkdocs documentation |
|||
/site |
|||
|
|||
# mypy |
|||
.mypy_cache/ |
|||
.dmypy.json |
|||
dmypy.json |
|||
|
|||
# Pyre type checker |
|||
.pyre/ |
|||
|
|||
# pytype static type analyzer |
|||
.pytype/ |
|||
|
|||
# Cython debug symbols |
|||
cython_debug/ |
|||
|
|||
### Windows ### |
|||
# Windows thumbnail cache files |
|||
Thumbs.db |
|||
Thumbs.db:encryptable |
|||
ehthumbs.db |
|||
ehthumbs_vista.db |
|||
|
|||
# Dump file |
|||
*.stackdump |
|||
|
|||
# Folder config file |
|||
[Dd]esktop.ini |
|||
|
|||
# Recycle Bin used on file shares |
|||
$RECYCLE.BIN/ |
|||
|
|||
# Windows Installer files |
|||
*.cab |
|||
*.msi |
|||
*.msix |
|||
*.msm |
|||
*.msp |
|||
|
|||
# Windows shortcuts |
|||
*.lnk |
|||
@ -0,0 +1,50 @@ |
|||
# Operator: emulate-sign-and-scan |
|||
|
|||
Author: |
|||
|
|||
## Overview |
|||
|
|||
|
|||
|
|||
## Interface |
|||
|
|||
```python |
|||
__init__(self, model_name: str, framework: str = 'pytorch') |
|||
``` |
|||
|
|||
Args: |
|||
|
|||
- model_name: |
|||
- the model name for embedding |
|||
- supported types: str, for example 'xxx' or 'xxx' |
|||
- framework: |
|||
- the framework of the model |
|||
- supported types: str, default is 'pytorch' |
|||
|
|||
```python |
|||
__call__(self, call_arg_1: xxx) |
|||
``` |
|||
|
|||
Args: |
|||
|
|||
- call_arg_1: |
|||
- xxx(description about call_arg_1) |
|||
- supported types: xxx |
|||
Returns: |
|||
|
|||
The Operator returns a tuple Tuple[('results_1', xxx)] containing following fields: |
|||
|
|||
- results_1: |
|||
- xxx(description of results_1) |
|||
- data type: xxx |
|||
- shape: (xxx,) |
|||
|
|||
## Requirements |
|||
|
|||
|
|||
|
|||
## How it works |
|||
|
|||
|
|||
|
|||
## Reference |
|||
@ -0,0 +1,72 @@ |
|||
|
|||
import subprocess |
|||
from typing import NamedTuple |
|||
|
|||
from towhee.operator.base import Operator |
|||
from towhee.types import Image |
|||
|
|||
|
|||
class EmulateSignAndScan(Operator): |
|||
""" |
|||
A one line summary of this class. |
|||
|
|||
Args: |
|||
init_arg_1 (`xxx`): |
|||
This argument is ... |
|||
""" |
|||
def __init__(self) -> None: |
|||
super().__init__() |
|||
|
|||
def __call__(self, doc_path: str, out_path: str, sig_img: Image = None, x_off: int = 0, y_off: int = 0) -> NamedTuple('Outputs', [('out_path', str)]): |
|||
""" |
|||
A one line summary of this function. |
|||
|
|||
Args: |
|||
doc_path (`str`): |
|||
Document which needs to be signed and scanned in PDF format. |
|||
|
|||
out_path (`str`): |
|||
Output document path. |
|||
|
|||
sig_img (`towhee.types.Image`): |
|||
Image containing the cropped signature |
|||
|
|||
x_off (`int`): |
|||
`x` offset value (used to place the signature in the document.). |
|||
|
|||
y_off (`int`): |
|||
`y` offset_value (used to place the signature in the document.) |
|||
|
|||
Returns: |
|||
(`Tuple[('result_1', xxx)]`) |
|||
A tuple with one values, which is ... |
|||
""" |
|||
|
|||
# step 1: copy signature image into document |
|||
if sig_img: |
|||
cv2.imwrite(sig_img.to_ndarray(), "/tmp/pdf2scan-sig-img.jpg") |
|||
cmd = ["composite", |
|||
"-density", "150", |
|||
"-gravity", "NorthWest", |
|||
"-geometry", "+{0}+{1}".format(x_off, y_off), |
|||
"/tmp/pdf2scan-sig-img.jpg", |
|||
doc_path, |
|||
out_path] |
|||
else: |
|||
cmd = ["cp", doc_path, out_path] |
|||
subprocess.call(cmd) |
|||
|
|||
# step 2: "scanify" the document |
|||
cmd = ["convert", |
|||
"-density", "150", |
|||
out_path, |
|||
"-rotate", "-0.66", |
|||
"-attenuate", "0.2", |
|||
"+noise", "Multiplicative", |
|||
"-colorspace", "Gray", |
|||
"-blur", "3x0.5", |
|||
out_path] |
|||
subprocess.call(cmd) |
|||
|
|||
Output = NamedTuple('Output', [('out_path', str)]) |
|||
return Output(out_path) |
|||
@ -0,0 +1,14 @@ |
|||
name: 'emulate-sign-and-scan' |
|||
labels: |
|||
recommended_framework: # Such as pytorch1.9.0 |
|||
class: # Such 'image-embedding' |
|||
others: |
|||
operator: 'fzliu/emulate-sign-and-scan' |
|||
init: |
|||
model_name: str |
|||
framework: str |
|||
call: |
|||
input: |
|||
call_arg_1: xxx |
|||
output: |
|||
result_1: xxx |
|||
Loading…
Reference in new issue