A console/terminal demo of cropping an image with numpy slicing, supporting Windows 11 and Ubuntu Linux 24.04. The crop is written as crop = img[y:y+h, x:x+w], where the slice takes y (the rows) before x (the columns). By default the crop is half the image size, starting at a quarter of the image. Two example images ship under data/ (Lena and sample), and the result is saved to model/crop/. No GPU is involved.
[Folder Structure]
- CLAUDE.md / AGENT.md: program specification (identical content).
- CHANGELOG.md: change log.
- copyright.txt: copyright notice.
- data/: the example images Lena.png and sample.png.
- model/crop/: the result crop.png; the Lena example is included.
- tool/tools.py: shared helpers.
- src/: the demo, the launcher scripts and this document.
- venv/: Python virtual environment, created by step 01.
[Prerequisites]
- Operating system: Windows 11 or Ubuntu Linux 24.04.
- Python 3 and pip.
- No GPU required; an ordinary CPU is enough.
[Instructions]
Step 1: Create the virtual environment
Delete the old venv/, create a fresh one and install the packages listed in src/requirements.txt. The script aborts loudly if pip fails.
Windows: src\01_venv_create.bat
Linux: bash src/01_venv_create.sh
Step 2: Activate the virtual environment
Activate the venv. On Linux, source the script.
Windows: src\02_venv_activate.bat
Linux: source src/02_venv_activate.sh
Step 3: Crop the image
Run the crop demo. Any extra arguments are forwarded to the program.
Windows: src\03_crop.bat
Linux: bash src/03_crop.sh
To use your own image and rectangle, for example:
bash src/03_crop.sh --source data/sample.png --x 10 --y 20 --width 200 --height 150
Step 4: Remove the virtual environment
Delete the venv/ folder.
Windows: src\99_venv_clear.bat
Linux: bash src/99_venv_clear.sh
[Python Entry Point]
- src/crop.py: [--source IMG] [--x] [--y] [--width] [--height] [--output-dir DIR] [--show]. By default the crop width and height are half the image, and x and y start at a quarter of the image. It saves crop.png to model/crop/ and prints the crop rectangle; --show also opens the result in a window. An out-of-bounds crop is rejected with a clear error.
[References]
- OpenCV basic operations tutorial, which covers taking a region of interest by slicing: https://docs.opencv.org/4.x/d3/df2/tutorial_py_basic_ops.html
This SDK is built in AppForAI - AI Dev Tools.
Purchase license separately: USD 600, permanent authorization, single APP authorization, single machine authorization, one-year activation, one-year download, one-year update, one-year email technical support.