From fe7bc6a8d398ab3f494a10bd1ab60037c9f3cbd3 Mon Sep 17 00:00:00 2001 From: dongwlin Date: Fri, 27 Dec 2024 15:40:21 +0800 Subject: [PATCH] refactor: remove crop roi tool --- tools/CropRoi/.gitignore | 163 --------------------------------- tools/CropRoi/README.md | 36 -------- tools/CropRoi/dst/.gitkeep | 0 tools/CropRoi/main.py | 121 ------------------------ tools/CropRoi/pdm.lock | 60 ------------ tools/CropRoi/pyproject.toml | 12 --- tools/CropRoi/requirements.txt | 5 - tools/CropRoi/src/.gitkeep | 0 tools/CropRoi/start.bat | 2 - 9 files changed, 399 deletions(-) delete mode 100644 tools/CropRoi/.gitignore delete mode 100644 tools/CropRoi/README.md delete mode 100644 tools/CropRoi/dst/.gitkeep delete mode 100644 tools/CropRoi/main.py delete mode 100644 tools/CropRoi/pdm.lock delete mode 100644 tools/CropRoi/pyproject.toml delete mode 100644 tools/CropRoi/requirements.txt delete mode 100644 tools/CropRoi/src/.gitkeep delete mode 100644 tools/CropRoi/start.bat diff --git a/tools/CropRoi/.gitignore b/tools/CropRoi/.gitignore deleted file mode 100644 index 8a62dc8..0000000 --- a/tools/CropRoi/.gitignore +++ /dev/null @@ -1,163 +0,0 @@ -### Python template -# 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 - -# poetry -# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control. -# This is especially recommended for binary packages to ensure reproducibility, and is more -# commonly ignored for libraries. -# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control -#poetry.lock - -# pdm -# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control. -#pdm.lock -# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it -# in version control. -# https://pdm.fming.dev/#use-with-ide -.pdm.toml -.pdm-python - -# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm -__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/ - -# PyCharm -# JetBrains specific template is maintained in a separate JetBrains.gitignore that can -# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore -# and can be added to the global gitignore or merged into this file. For a more nuclear -# option (not recommended) you can uncomment the following to ignore the entire idea folder. -#.idea/ - diff --git a/tools/CropRoi/README.md b/tools/CropRoi/README.md deleted file mode 100644 index 8e3480c..0000000 --- a/tools/CropRoi/README.md +++ /dev/null @@ -1,36 +0,0 @@ -# 截图工具 - -## 环境 - -需要 `python` 环境 - -## 依赖 - -在./tools/CropRoi下执行以下命令 - -(如果已经安装过pipx和pdm可以跳过直接使用pdm install) - -```shell -python -m pip install pipx -pipx ensurepath -``` - -重启终端 - -```shell -pipx install pdm -pdm install -``` - -## 使用 - -截图需预先保存到 `./src/` 路径下, 产物将会保存在 `./dst/` 路径下 - -打开cmd, 执行以下命令 - -```shell -.venv\Scripts\Activate.ps1 -pdm run python main.py -``` - -在弹出窗口中使用鼠标左键画框, `s` 键保存, `q` 键退出 diff --git a/tools/CropRoi/dst/.gitkeep b/tools/CropRoi/dst/.gitkeep deleted file mode 100644 index e69de29..0000000 diff --git a/tools/CropRoi/main.py b/tools/CropRoi/main.py deleted file mode 100644 index ecbf522..0000000 --- a/tools/CropRoi/main.py +++ /dev/null @@ -1,121 +0,0 @@ -import cv2 -import os -from typing import List, Tuple - -print( - "Usage:\n" - "Put the 16:9 images under ./src, and run this script, it will be auto converted to 720p.\n" - "Drag mouse to select ROI, press 'S' to save, press 'Q' to quit.\n" - "The cropped images will be saved in ./dst\n" -) - -# 初始化参考点列表和布尔值标志:是否正在执行裁剪 -refPt: List[Tuple[int, int]] = [] -cropping = False - - -# 点击并裁剪ROI区域 -# -events 鼠标事件(如按下鼠标左键,释放鼠标左键,鼠标移动等) -# -x x坐标 -# -y y坐标 -# -flages params 其他参数 -def click_and_crop(event: int, x: int, y: int, *args) -> None: - # 获取全局变量的引用 - - global refPt, cropping - - # 如果鼠标左被单击,记录(x,y)坐标并显示裁剪正在进行 - if event == cv2.EVENT_LBUTTONDOWN: - refPt = [(x, y)] - cropping = True - # 检测鼠标是否移动 - elif event == cv2.EVENT_MOUSEMOVE: - if cropping: - # 创建图像副本以绘制动态矩形 - draw = image.copy() - cv2.rectangle(draw, refPt[0], (x, y), (0, 255, 0), 2) - cv2.imshow("image", draw) - # 检测鼠标左键是否释放 - elif event == cv2.EVENT_LBUTTONUP: - # 记录结束(x,y)坐标,并显示裁剪结束 - refPt.append((x, y)) - cropping = False - - draw = image.copy() - cv2.rectangle(draw, refPt[0], refPt[1], (0, 255, 0), 2) - cv2.imshow("image", draw) - - -std_width: int = 1280 -std_height: int = 720 -std_ratio = std_width / std_height - -cv2.namedWindow("image") -cv2.setMouseCallback("image", click_and_crop) - -for filename in os.listdir("./src"): - if not (filename.endswith(".png") or filename.endswith(".jpg")): - continue - - print("src:", filename) - image = cv2.imread(f"./src/{filename}") - - cur_ratio = image.shape[1] / image.shape[0] - - if cur_ratio >= std_ratio: - dsize_width = int(cur_ratio * std_height) - dsize_height = std_height - else: - dsize_width = std_width - dsize_height = int(std_width / cur_ratio) - - dsize = (dsize_width, dsize_height) - image = cv2.resize(image, dsize, interpolation=cv2.INTER_AREA) - - while True: - cv2.imshow("image", image) - key = cv2.waitKey(0) & 0xFF - if key == ord("s"): - break - elif key == ord("q"): - exit() - - # 如果参考点列表里有俩个点,则裁剪区域并展示 - if len(refPt) == 2: - pt1, pt2 = sorted(refPt) - - left, top = pt1 - right, bottom = pt2 - - roi = image[top:bottom, left:right] - - horizontal_expansion = 100 - vertical_expansion = 100 - - # 计算扩展后的左上角坐标,并确保不超出图像边界 - filename_x = max(0, left - horizontal_expansion // 2) - filename_y = max(0, top - vertical_expansion // 2) - - # 计算扩展后的宽度和高度,并进行边界检查 - filename_w = min( - dsize_width - filename_x, (right - left) + horizontal_expansion - ) - filename_h = min(dsize_height - filename_y, (bottom - top) + vertical_expansion) - - dst_filename: str = ( - f"{filename}_{filename_x},{filename_y},{filename_w},{filename_h}.png" - ) - print("dst:", dst_filename) - - print( - f"original roi: {left}, {top}, {right - left}, {bottom - top}, \n" - f"amplified roi: {filename_x}, {filename_y}, {filename_w}, {filename_h}\n\n" - ) - - cv2.imwrite(f"./dst/{dst_filename}", roi) - - refPt: List[Tuple[int, int]] = [] - cropping = False - -# 关闭所有打开的窗口 -cv2.destroyAllWindows() diff --git a/tools/CropRoi/pdm.lock b/tools/CropRoi/pdm.lock deleted file mode 100644 index f7d1ffe..0000000 --- a/tools/CropRoi/pdm.lock +++ /dev/null @@ -1,60 +0,0 @@ -# This file is @generated by PDM. -# It is not intended for manual editing. - -[metadata] -groups = ["default"] -strategy = ["cross_platform"] -lock_version = "4.4" -content_hash = "sha256:c8ef58caa94bb224e56b87703c59a64edc481e38be9413403097d225ff9caccb" - -[[package]] -name = "numpy" -version = "1.26.2" -requires_python = ">=3.9" -summary = "Fundamental package for array computing in Python" -files = [ - {file = "numpy-1.26.2-cp311-cp311-macosx_10_9_x86_64.whl", hash = "sha256:b96e7b9c624ef3ae2ae0e04fa9b460f6b9f17ad8b4bec6d7756510f1f6c0c841"}, - {file = "numpy-1.26.2-cp311-cp311-macosx_11_0_arm64.whl", hash = "sha256:aa18428111fb9a591d7a9cc1b48150097ba6a7e8299fb56bdf574df650e7d1f1"}, - {file = "numpy-1.26.2-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:06fa1ed84aa60ea6ef9f91ba57b5ed963c3729534e6e54055fc151fad0423f0a"}, - {file = "numpy-1.26.2-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:96ca5482c3dbdd051bcd1fce8034603d6ebfc125a7bd59f55b40d8f5d246832b"}, - {file = "numpy-1.26.2-cp311-cp311-musllinux_1_1_aarch64.whl", hash = "sha256:854ab91a2906ef29dc3925a064fcd365c7b4da743f84b123002f6139bcb3f8a7"}, - {file = "numpy-1.26.2-cp311-cp311-musllinux_1_1_x86_64.whl", hash = "sha256:f43740ab089277d403aa07567be138fc2a89d4d9892d113b76153e0e412409f8"}, - {file = "numpy-1.26.2-cp311-cp311-win32.whl", hash = "sha256:a2bbc29fcb1771cd7b7425f98b05307776a6baf43035d3b80c4b0f29e9545186"}, - {file = "numpy-1.26.2-cp311-cp311-win_amd64.whl", hash = "sha256:2b3fca8a5b00184828d12b073af4d0fc5fdd94b1632c2477526f6bd7842d700d"}, - {file = "numpy-1.26.2-cp312-cp312-macosx_10_9_x86_64.whl", hash = "sha256:a4cd6ed4a339c21f1d1b0fdf13426cb3b284555c27ac2f156dfdaaa7e16bfab0"}, - {file = "numpy-1.26.2-cp312-cp312-macosx_11_0_arm64.whl", hash = "sha256:5d5244aabd6ed7f312268b9247be47343a654ebea52a60f002dc70c769048e75"}, - {file = "numpy-1.26.2-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:6a3cdb4d9c70e6b8c0814239ead47da00934666f668426fc6e94cce869e13fd7"}, - {file = "numpy-1.26.2-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:aa317b2325f7aa0a9471663e6093c210cb2ae9c0ad824732b307d2c51983d5b6"}, - {file = "numpy-1.26.2-cp312-cp312-musllinux_1_1_aarch64.whl", hash = "sha256:174a8880739c16c925799c018f3f55b8130c1f7c8e75ab0a6fa9d41cab092fd6"}, - {file = "numpy-1.26.2-cp312-cp312-musllinux_1_1_x86_64.whl", hash = "sha256:f79b231bf5c16b1f39c7f4875e1ded36abee1591e98742b05d8a0fb55d8a3eec"}, - {file = "numpy-1.26.2-cp312-cp312-win32.whl", hash = "sha256:4a06263321dfd3598cacb252f51e521a8cb4b6df471bb12a7ee5cbab20ea9167"}, - {file = "numpy-1.26.2-cp312-cp312-win_amd64.whl", hash = "sha256:b04f5dc6b3efdaab541f7857351aac359e6ae3c126e2edb376929bd3b7f92d7e"}, - {file = "numpy-1.26.2-pp39-pypy39_pp73-macosx_10_9_x86_64.whl", hash = "sha256:1cc3d5029a30fb5f06704ad6b23b35e11309491c999838c31f124fee32107c79"}, - {file = "numpy-1.26.2-pp39-pypy39_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:94cc3c222bb9fb5a12e334d0479b97bb2df446fbe622b470928f5284ffca3f8d"}, - {file = "numpy-1.26.2-pp39-pypy39_pp73-win_amd64.whl", hash = "sha256:fe6b44fb8fcdf7eda4ef4461b97b3f63c466b27ab151bec2366db8b197387841"}, - {file = "numpy-1.26.2.tar.gz", hash = "sha256:f65738447676ab5777f11e6bbbdb8ce11b785e105f690bc45966574816b6d3ea"}, -] - -[[package]] -name = "opencv-python" -version = "4.8.1.78" -requires_python = ">=3.6" -summary = "Wrapper package for OpenCV python bindings." -dependencies = [ - "numpy>=1.17.0; python_version >= \"3.7\"", - "numpy>=1.17.3; python_version >= \"3.8\"", - "numpy>=1.19.3; python_version >= \"3.6\" and platform_system == \"Linux\" and platform_machine == \"aarch64\"", - "numpy>=1.19.3; python_version >= \"3.9\"", - "numpy>=1.21.2; python_version >= \"3.10\"", - "numpy>=1.21.4; python_version >= \"3.10\" and platform_system == \"Darwin\"", - "numpy>=1.23.5; python_version >= \"3.11\"", -] -files = [ - {file = "opencv-python-4.8.1.78.tar.gz", hash = "sha256:cc7adbbcd1112877a39274106cb2752e04984bc01a031162952e97450d6117f6"}, - {file = "opencv_python-4.8.1.78-cp37-abi3-macosx_10_16_x86_64.whl", hash = "sha256:91d5f6f5209dc2635d496f6b8ca6573ecdad051a09e6b5de4c399b8e673c60da"}, - {file = "opencv_python-4.8.1.78-cp37-abi3-macosx_11_0_arm64.whl", hash = "sha256:bc31f47e05447da8b3089faa0a07ffe80e114c91ce0b171e6424f9badbd1c5cd"}, - {file = "opencv_python-4.8.1.78-cp37-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:9814beca408d3a0eca1bae7e3e5be68b07c17ecceb392b94170881216e09b319"}, - {file = "opencv_python-4.8.1.78-cp37-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:c4c406bdb41eb21ea51b4e90dfbc989c002786c3f601c236a99c59a54670a394"}, - {file = "opencv_python-4.8.1.78-cp37-abi3-win32.whl", hash = "sha256:a7aac3900fbacf55b551e7b53626c3dad4c71ce85643645c43e91fcb19045e47"}, - {file = "opencv_python-4.8.1.78-cp37-abi3-win_amd64.whl", hash = "sha256:b983197f97cfa6fcb74e1da1802c7497a6f94ed561aba6980f1f33123f904956"}, -] diff --git a/tools/CropRoi/pyproject.toml b/tools/CropRoi/pyproject.toml deleted file mode 100644 index dd9172b..0000000 --- a/tools/CropRoi/pyproject.toml +++ /dev/null @@ -1,12 +0,0 @@ - -[project] -# PEP 621 project metadata -# See https://www.python.org/dev/peps/pep-0621/ -dependencies = [ - "opencv-python>=4.5.3", -] -requires-python = ">=3.11" - -[build-system] -requires = ["pdm-backend"] -build-backend = "pdm.backend" \ No newline at end of file diff --git a/tools/CropRoi/requirements.txt b/tools/CropRoi/requirements.txt deleted file mode 100644 index 00a91ec..0000000 --- a/tools/CropRoi/requirements.txt +++ /dev/null @@ -1,5 +0,0 @@ -# This file is @generated by PDM. -# Please do not edit it manually. - -numpy==1.26.2 -opencv-python==4.8.1.78 diff --git a/tools/CropRoi/src/.gitkeep b/tools/CropRoi/src/.gitkeep deleted file mode 100644 index e69de29..0000000 diff --git a/tools/CropRoi/start.bat b/tools/CropRoi/start.bat deleted file mode 100644 index 134732e..0000000 --- a/tools/CropRoi/start.bat +++ /dev/null @@ -1,2 +0,0 @@ -python main.py -pause \ No newline at end of file