updating extraction scripts
This commit is contained in:
140
.image-extraction/.gitignore
vendored
Normal file
140
.image-extraction/.gitignore
vendored
Normal file
@@ -0,0 +1,140 @@
|
|||||||
|
# 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/
|
||||||
|
|
||||||
|
|
||||||
0
.image-extraction/__init__.py
Normal file
0
.image-extraction/__init__.py
Normal file
41
.image-extraction/add_new_shikigami.md
Normal file
41
.image-extraction/add_new_shikigami.md
Normal file
@@ -0,0 +1,41 @@
|
|||||||
|
# Adding new Shikigami
|
||||||
|
|
||||||
|
Remove all current images:
|
||||||
|
|
||||||
|
`fd -e png -x rm {}**`
|
||||||
|
|
||||||
|
After convert, copy to the character folder in assets:
|
||||||
|
|
||||||
|
`fd -e png hououka -x mv {} /Users/dtomlinson/git-repos/web-dev/onmyoji-deck-builder/src/assets/cards/hououka`
|
||||||
|
|
||||||
|
Print all cards (excluding char and avatar):
|
||||||
|
|
||||||
|
`fd -E '*char*' -E '*avatar*'`
|
||||||
|
|
||||||
|
Blank JSON template:
|
||||||
|
|
||||||
|
- Paste template in
|
||||||
|
- Fill in with new char name
|
||||||
|
- Fill in filenames
|
||||||
|
- Copy `cards`
|
||||||
|
- Select all items in `cards`
|
||||||
|
- New line and paste to duplicate
|
||||||
|
- Update GUID
|
||||||
|
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"name": "Hououka",
|
||||||
|
"character_card": "hououka/hououka-char.png",
|
||||||
|
"cards": [
|
||||||
|
{ "id": "d6fc26b2", "name": "", "url": "" },
|
||||||
|
{ "id": "1217f957", "name": "", "url": "" },
|
||||||
|
{ "id": "a507638d", "name": "", "url": "" },
|
||||||
|
{ "id": "a3e876ec", "name": "", "url": "" },
|
||||||
|
{ "id": "8fa65d84", "name": "", "url": "" },
|
||||||
|
{ "id": "914c6cbb", "name": "", "url": "" },
|
||||||
|
{ "id": "f1f8ce7d", "name": "", "url": "" },
|
||||||
|
{ "id": "1d30d350", "name": "", "url": "" },
|
||||||
|
],
|
||||||
|
"avatar": "hououka/hououka-avatar.png"
|
||||||
|
}
|
||||||
|
```
|
||||||
52
.image-extraction/extract_all.py
Normal file
52
.image-extraction/extract_all.py
Normal file
@@ -0,0 +1,52 @@
|
|||||||
|
import glob
|
||||||
|
|
||||||
|
import extract_combat
|
||||||
|
import extract_spell
|
||||||
|
import extract_form
|
||||||
|
|
||||||
|
SHIKIGAMI_NAME = "ubume"
|
||||||
|
|
||||||
|
|
||||||
|
def main(shikigami_name: str):
|
||||||
|
# combat cards
|
||||||
|
for image in glob.glob(
|
||||||
|
"/Users/dtomlinson/git-repos/web-dev/onmyoji-deck-builder/."
|
||||||
|
"image-extraction/images/combat/*.*"
|
||||||
|
):
|
||||||
|
print(image)
|
||||||
|
extract_combat.extract_image(
|
||||||
|
image,
|
||||||
|
"/Users/dtomlinson/git-repos/web-dev/onmyoji-deck-builder/."
|
||||||
|
"image-extraction/images/combat/out",
|
||||||
|
shikigami_name,
|
||||||
|
)
|
||||||
|
|
||||||
|
# spell cards
|
||||||
|
for image in glob.glob(
|
||||||
|
"/Users/dtomlinson/git-repos/web-dev/onmyoji-deck-builder/."
|
||||||
|
"image-extraction/images/spells/*.*"
|
||||||
|
):
|
||||||
|
print(image)
|
||||||
|
extract_spell.extract_image(
|
||||||
|
image,
|
||||||
|
"/Users/dtomlinson/git-repos/web-dev/onmyoji-deck-builder/."
|
||||||
|
"image-extraction/images/spells/out",
|
||||||
|
shikigami_name,
|
||||||
|
)
|
||||||
|
|
||||||
|
# form cards
|
||||||
|
for image in glob.glob(
|
||||||
|
"/Users/dtomlinson/git-repos/web-dev/onmyoji-deck-builder/."
|
||||||
|
"image-extraction/images/forms/*.*"
|
||||||
|
):
|
||||||
|
print(image)
|
||||||
|
extract_form.extract_image(
|
||||||
|
image,
|
||||||
|
"/Users/dtomlinson/git-repos/web-dev/onmyoji-deck-builder/."
|
||||||
|
"image-extraction/images/forms/out",
|
||||||
|
shikigami_name,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main(SHIKIGAMI_NAME)
|
||||||
@@ -65,6 +65,9 @@ def extract_image(filename: str, output_path: str) -> None:
|
|||||||
# convert back to an image
|
# convert back to an image
|
||||||
extracted_image = Image.fromarray(extracted_image_array, "RGBA")
|
extracted_image = Image.fromarray(extracted_image_array, "RGBA")
|
||||||
|
|
||||||
|
# crop
|
||||||
|
extracted_image = extracted_image.crop((533, 57, 769, 512))
|
||||||
|
|
||||||
# save the image
|
# save the image
|
||||||
extracted_image.save(f"{output_path}/{filename.split('/')[-1].split('.')[-2]}.png")
|
extracted_image.save(f"{output_path}/{filename.split('/')[-1].split('.')[-2]}.png")
|
||||||
|
|
||||||
@@ -72,7 +75,7 @@ def extract_image(filename: str, output_path: str) -> None:
|
|||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
for image in glob.glob(
|
for image in glob.glob(
|
||||||
"/Users/dtomlinson/git-repos/web-dev/onmyoji-deck-builder/."
|
"/Users/dtomlinson/git-repos/web-dev/onmyoji-deck-builder/."
|
||||||
"image-extraction/images/characters/in/*.*"
|
"image-extraction/images/characters/*.*"
|
||||||
):
|
):
|
||||||
print(image)
|
print(image)
|
||||||
extract_image(
|
extract_image(
|
||||||
|
|||||||
@@ -1,10 +1,8 @@
|
|||||||
import glob
|
|
||||||
|
|
||||||
import numpy
|
import numpy
|
||||||
from PIL import Image, ImageDraw
|
from PIL import Image, ImageDraw
|
||||||
|
|
||||||
|
|
||||||
def extract_image(filename: str, output_path: str) -> None:
|
def extract_image(filename: str, output_path: str, shikigami_name: str) -> None:
|
||||||
"""
|
"""
|
||||||
Extract a combat card from a screenshot from a device. Screenshot for each card
|
Extract a combat card from a screenshot from a device. Screenshot for each card
|
||||||
taken from the Hyakabun scrollery. Image will be resized and the card extracted.
|
taken from the Hyakabun scrollery. Image will be resized and the card extracted.
|
||||||
@@ -60,19 +58,13 @@ def extract_image(filename: str, output_path: str) -> None:
|
|||||||
|
|
||||||
# convert back to an image
|
# convert back to an image
|
||||||
extracted_image = Image.fromarray(extracted_image_array, "RGBA")
|
extracted_image = Image.fromarray(extracted_image_array, "RGBA")
|
||||||
|
print(extracted_image.size)
|
||||||
|
|
||||||
|
# crop
|
||||||
|
extracted_image = extracted_image.crop((495, 38, 788, 567))
|
||||||
|
|
||||||
# save the image
|
# save the image
|
||||||
extracted_image.save(f"{output_path}/{filename.split('/')[-1].split('.')[-2]}.png")
|
extracted_image.save(
|
||||||
|
f"{output_path}/{shikigami_name}-"
|
||||||
|
f"{filename.split('/')[-1].split('.')[-2]}.png"
|
||||||
if __name__ == "__main__":
|
)
|
||||||
for image in glob.glob(
|
|
||||||
"/Users/dtomlinson/git-repos/web-dev/onmyoji-deck-builder/."
|
|
||||||
"image-extraction/images/combat/in/*.*"
|
|
||||||
):
|
|
||||||
print(image)
|
|
||||||
extract_image(
|
|
||||||
image,
|
|
||||||
"/Users/dtomlinson/git-repos/web-dev/onmyoji-deck-builder/."
|
|
||||||
"image-extraction/images/combat/out",
|
|
||||||
)
|
|
||||||
|
|||||||
@@ -81,6 +81,9 @@ def extract_image(filename: str, output_path: str) -> None:
|
|||||||
# convert back to an image
|
# convert back to an image
|
||||||
extracted_image = Image.fromarray(extracted_image_array, "RGBA")
|
extracted_image = Image.fromarray(extracted_image_array, "RGBA")
|
||||||
|
|
||||||
|
# crop
|
||||||
|
extracted_image = extracted_image.crop((490, 42, 803, 568))
|
||||||
|
|
||||||
# save the image
|
# save the image
|
||||||
extracted_image.save(f"{output_path}/{filename.split('/')[-1].split('.')[-2]}.png")
|
extracted_image.save(f"{output_path}/{filename.split('/')[-1].split('.')[-2]}.png")
|
||||||
|
|
||||||
@@ -88,7 +91,7 @@ def extract_image(filename: str, output_path: str) -> None:
|
|||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
for image in glob.glob(
|
for image in glob.glob(
|
||||||
"/Users/dtomlinson/git-repos/web-dev/onmyoji-deck-builder/."
|
"/Users/dtomlinson/git-repos/web-dev/onmyoji-deck-builder/."
|
||||||
"image-extraction/images/fields/in/*.*"
|
"image-extraction/images/fields/*.*"
|
||||||
):
|
):
|
||||||
print(image)
|
print(image)
|
||||||
extract_image(
|
extract_image(
|
||||||
|
|||||||
@@ -1,10 +1,8 @@
|
|||||||
import glob
|
|
||||||
|
|
||||||
import numpy
|
import numpy
|
||||||
from PIL import Image, ImageDraw
|
from PIL import Image, ImageDraw
|
||||||
|
|
||||||
|
|
||||||
def extract_image(filename: str, output_path: str) -> None:
|
def extract_image(filename: str, output_path: str, shikigami_name: str) -> None:
|
||||||
"""
|
"""
|
||||||
Extract a form card from a screenshot from a device. Screenshot for each card
|
Extract a form card from a screenshot from a device. Screenshot for each card
|
||||||
taken from the Hyakabun scrollery. Image will be resized and the card extracted.
|
taken from the Hyakabun scrollery. Image will be resized and the card extracted.
|
||||||
@@ -65,18 +63,11 @@ def extract_image(filename: str, output_path: str) -> None:
|
|||||||
# convert back to an image
|
# convert back to an image
|
||||||
extracted_image = Image.fromarray(extracted_image_array, "RGBA")
|
extracted_image = Image.fromarray(extracted_image_array, "RGBA")
|
||||||
|
|
||||||
|
# crop
|
||||||
|
extracted_image = extracted_image.crop((495, 39, 789, 567))
|
||||||
|
|
||||||
# save the image
|
# save the image
|
||||||
extracted_image.save(f"{output_path}/{filename.split('/')[-1].split('.')[-2]}.png")
|
extracted_image.save(
|
||||||
|
f"{output_path}/{shikigami_name}-"
|
||||||
|
f"{filename.split('/')[-1].split('.')[-2]}.png"
|
||||||
if __name__ == "__main__":
|
)
|
||||||
for image in glob.glob(
|
|
||||||
"/Users/dtomlinson/git-repos/web-dev/onmyoji-deck-builder/."
|
|
||||||
"image-extraction/images/forms/in/*.*"
|
|
||||||
):
|
|
||||||
print(image)
|
|
||||||
extract_image(
|
|
||||||
image,
|
|
||||||
"/Users/dtomlinson/git-repos/web-dev/onmyoji-deck-builder/."
|
|
||||||
"image-extraction/images/forms/out",
|
|
||||||
)
|
|
||||||
|
|||||||
@@ -1,10 +1,8 @@
|
|||||||
import glob
|
|
||||||
|
|
||||||
import numpy
|
import numpy
|
||||||
from PIL import Image, ImageDraw
|
from PIL import Image, ImageDraw
|
||||||
|
|
||||||
|
|
||||||
def extract_image(filename: str, output_path: str) -> None:
|
def extract_image(filename: str, output_path: str, shikigami_name: str) -> None:
|
||||||
"""
|
"""
|
||||||
Extract a spell card from a screenshot from a device. Mask is valid for 1304x603
|
Extract a spell card from a screenshot from a device. Mask is valid for 1304x603
|
||||||
screenshot from an iPhone 12 Pro.
|
screenshot from an iPhone 12 Pro.
|
||||||
@@ -59,18 +57,11 @@ def extract_image(filename: str, output_path: str) -> None:
|
|||||||
# convert back to an image
|
# convert back to an image
|
||||||
extracted_image = Image.fromarray(extracted_image_array, "RGBA")
|
extracted_image = Image.fromarray(extracted_image_array, "RGBA")
|
||||||
|
|
||||||
|
# crop
|
||||||
|
extracted_image = extracted_image.crop((496, 59, 788, 567))
|
||||||
|
|
||||||
# save the image
|
# save the image
|
||||||
extracted_image.save(f"{output_path}/{filename.split('/')[-1].split('.')[-2]}.png")
|
extracted_image.save(
|
||||||
|
f"{output_path}/{shikigami_name}-"
|
||||||
|
f"{filename.split('/')[-1].split('.')[-2]}.png"
|
||||||
if __name__ == "__main__":
|
)
|
||||||
for image in glob.glob(
|
|
||||||
"/Users/dtomlinson/git-repos/web-dev/onmyoji-deck-builder/."
|
|
||||||
"image-extraction/images/spells/in/*.jpeg"
|
|
||||||
):
|
|
||||||
print(image)
|
|
||||||
extract_image(
|
|
||||||
image,
|
|
||||||
"/Users/dtomlinson/git-repos/web-dev/onmyoji-deck-builder/."
|
|
||||||
"image-extraction/images/spells/out",
|
|
||||||
)
|
|
||||||
|
|||||||
Reference in New Issue
Block a user