Skip to content

jbartolozzi/DrawPrompt

Repository files navigation

DrawPrompt

drawing

DrawPrompt is a desktop application for creating physical drawing datasets. It generates printable pages with ArUco marker-tagged squares for prompts, then extracts hand-drawn artwork from scanned pages back into digital form. Perfect for training AI models on hand-drawn artwork or creating physical drawing datasets.

Overview

The workflow is simple:

  1. Generate printable template pages from a list of text prompts
  2. Print the pages and draw in each square
  3. Scan the completed pages
  4. Extract individual drawings as labeled images with metadata

Each prompt square is marked with ArUco markers at the corners, enabling automatic detection and extraction of drawings even from imperfect scans.

Installation

# Clone the repository
git clone git@github.com:jbartolozzi/DrawPrompt.git
cd DrawPrompt

# Initialize the submodule
git submodule update --init

# Run Setup
source setup.sh

User Interface

Generate Templates Tab

Generate Templates Interface

The Generate Templates tab allows you to create printable pages:

  • Prompts List (left panel): Add, edit, and reorder your text prompts

    • Double-click "(Double-click to add prompt)" to add new prompts
    • Double-click any prompt to edit it
    • Drag prompts to reorder them
    • Press Delete/Backspace to remove prompts
    • Import/Export buttons: Load prompts from or save to .txt, .csv, or .jsonl files
  • Page Settings:

    • Squares per page: Number of prompt squares per page (1-20)
    • Padding: Space between squares in pixels (10-300)
    • Title: Custom title text for your pages
  • Action Buttons:

    • Generate Preview: Manually refresh the preview
    • Print Pages: Send pages directly to your printer
    • Save as PNG: Export pages as PNG image files
  • Preview Panel (right): Live preview of your generated pages

    • Automatically updates when you change prompts or settings
    • Page Navigation: Browse through multiple pages with Previous/Next buttons

Scan & Extract Tab

Scan & Extract Interface

The Scan & Extract tab processes scanned pages to extract individual drawings:

  • Input File:

    • Browse button: Select a scanned image file
    • Drag and drop a scanned image directly onto the preview area
    • Supports PNG, JPG, JPEG formats
  • Prompts File:

    • Load Prompts button: Load the original prompts file used to generate the pages
    • This associates each extracted image with its corresponding prompt text
  • Extraction Settings:

    • Output size: Resolution of extracted images in pixels (128-2048)
    • Select Output Folder: Where to save extracted images and metadata
    • Use fallback mode: If ArUco marker detection fails, use fixed grid positions (for 600 DPI scans)
  • Extract Images button: Start the extraction process (threaded operation)

  • Progress bar: Shows extraction progress

  • Log panel: Displays status messages and any errors

  • Preview Panel (right): Shows the loaded scanned image before processing

Example Workflow

Scanned Pages

Example Scans

Here are two example scanned pages showing hand-drawn artwork in each prompt square. The ArUco markers at each corner enable precise extraction.

Results: Scan 1

Input Drawings

Scan 1 Input

LoRA-Generated Output

Scan 1 LoRA Output

The extracted drawings from the first scan (left) were used to train a LoRA model, which then generated new artwork in the same style (right).

Results: Scan 2

Input Drawings

Scan 2 Input

LoRA-Generated Output

Scan 2 LoRA Output

The second scan demonstrates different artistic styles. The trained model successfully learned and replicated the unique characteristics of each drawing style.

Output Format

Extracted images are saved with the following structure:

output_folder/
├── image_0.png
├── image_1.png
├── image_2.png
├── ...
└── metadata.jsonl

The metadata.jsonl file contains prompt associations:

{"file_name": "image_0.png", "prompt": "a cat wearing a hat"}
{"file_name": "image_1.png", "prompt": "a house with a garden"}

Command-Line Usage

Both generation and scanning can be done via command-line:

Generate Pages

python3 core/create_image.py \
  -p prompts.txt \
  -o output/ \
  -s 12 \
  -a 100 \
  -t "My Drawing Prompts" \
  -f

Scan and Extract

# With ArUco marker detection
python3 core/scan_image.py \
  -i scan.jpg \
  -p prompts.txt \
  -o output/ \
  --scale 512

# Fallback mode (fixed positions)
python3 core/scan_image.py \
  -i scan.jpg \
  -p prompts.txt \
  -o output/ \
  --scale 512 \
  --dumb

Building the Application

Build a standalone macOS application bundle:

pyinstaller DrawPrompt.spec

The built app will be in dist/DrawPrompt.app/

Technical Details

  • ArUco Markers: Uses OpenCV's DICT_4X4_250 dictionary with 4 markers per square
  • Print Resolution: Pages are generated at 300 DPI (2550×3300 px) for high-quality printing
  • Scan Resolution: Works best with 300-600 DPI scans
  • Detection: Automatically optimizes ArUco detection parameters for each scan
  • Fallback Mode: If marker detection fails, uses fixed grid positions calibrated for 600 DPI scans

Credits

Built with:

  • PySide6 - Qt for Python GUI framework
  • OpenCV - ArUco marker detection and image processing

About

Small GUI app for creating hand drawn datasets to train image generation loras

Resources

License

Stars

Watchers

Forks

Packages

No packages published