Skip to main content

Convert scanned P&ID images to DXF/DWG

Project description

jpg-dwg

Convert scanned P&ID (Piping and Instrumentation) drawing images to DXF (lines only), and optionally to DWG via an external converter.

Install

From PyPI (recommended):

pip install jpg-dwg

From source:

git clone https://github.com/yourusername/jpg-dwg.git
cd jpg-dwg
pip install -e .

Or install dependencies only and run as module:

pip install -r requirements.txt
python -m jpg_dwg input.png -o output.dxf

Usage

# Basic: image → DXF (after pip install jpg-dwg)
jpg-dwg scan.png -o drawing.dxf

# Or as module
python -m jpg_dwg scan.png -o drawing.dxf

# With options (invert is on by default for black-on-white P&ID; use --no-invert if needed)
python -m jpg_dwg scan.png -o drawing.dxf --preview preprocessed.png --scale 0.1

# Enable P&ID symbol detection (contour-based heuristics)
python -m jpg_dwg scan.png -o drawing.dxf --symbols

# Also produce DWG (requires ODA File Converter)
python -m jpg_dwg scan.png -o drawing.dxf --dwg drawing.dwg

Options

Option Description
input Input image path (PNG, JPG, etc.)
-o, --output Output DXF path
--scale Drawing units per pixel (default 1.0)
--dpi DPI hint (default 300)
--no-deskew Disable automatic deskew
--invert Invert binary (default: on for black lines on white)
--no-invert Do not invert (for white lines on dark scan)
--adaptive Use adaptive threshold instead of Otsu
--no-denoise Disable morphology denoise
--thin Thinning/skeletonization (requires opencv-contrib)
--preview PATH Save preprocessed binary image
--symbols Run P&ID symbol detection and insert blocks
--dwg PATH Also convert DXF to DWG (see below)
-v, --verbose Verbose logging

DWG output

This tool writes DXF only. To get DWG:

  1. Install ODA File Converter.
  2. Set ODA_FILE_CONVERTER to the converter executable path, or ensure it is on PATH.
  3. Use --dwg output.dwg. The CLI will run the converter after writing the DXF.

Limitations

  • Quality depends on scan resolution and contrast. Preprocess with --invert or --preview to tune.
  • Vectorization extracts lines only (OpenCV Hough).
  • P&ID symbol detection is heuristic (contour-based). For production, consider a trained model (e.g. YOLO on P&ID symbols).

Publishing to PyPI (maintainers)

  1. Create an account and API token at pypi.org (use test.pypi.org for testing).
  2. From the repo root:
    pip install build twine
    python -m build
    twine upload dist/*
    
  3. When prompted: username __token__, password = your PyPI API token.
  4. To test first: twine upload --repository testpypi dist/*, then pip install -i https://test.pypi.org/simple/ jpg-dwg.

Update version in pyproject.toml and the [project.urls] Homepage/Source to your repo before publishing.

Project layout

jpg-dwg/
├── pyproject.toml
├── requirements.txt
├── README.md
├── src/jpg_dwg/
│   ├── cli.py
│   ├── preprocess.py
│   ├── vectorize.py
│   ├── export_dxf.py
│   ├── symbols.py
│   └── config.py
└── tests/

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

jpg_dwg-0.1.0.tar.gz (12.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

jpg_dwg-0.1.0-py3-none-any.whl (12.4 kB view details)

Uploaded Python 3

File details

Details for the file jpg_dwg-0.1.0.tar.gz.

File metadata

  • Download URL: jpg_dwg-0.1.0.tar.gz
  • Upload date:
  • Size: 12.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.9

File hashes

Hashes for jpg_dwg-0.1.0.tar.gz
Algorithm Hash digest
SHA256 fd6fcfc6fb640a040547dc9be4c1bf10524c1937d6ffc65212eeb7dd25332d00
MD5 f24028d8015d2a3cf983fa18aaf95105
BLAKE2b-256 d97daeb56b7cc89a0bb3ec95ed090f0a7bb84f33dda9dacd39943132942bc6f9

See more details on using hashes here.

File details

Details for the file jpg_dwg-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: jpg_dwg-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 12.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.9

File hashes

Hashes for jpg_dwg-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 e42c34f01058dc81ee7fd109530bf7032d74d8a88913961fd075891523867a20
MD5 f6f614e5700f014ff41a6c336f72f47d
BLAKE2b-256 ba99b20368639582064c1a6966c596413648929dc77a0467dcf7e02a6c655281

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page