Skip to main content

image2layout_computer_vision

An image processing module for some computer vision tasks (public module for image2layout)

Package Page: pypi

Features:

  1. Text Detection and Recognition (OCR)
  2. Color extraction (background and main foreground)

Installations

Install with python/conda [Linux]

  1. (Optional) Conda
curl https://repo.anaconda.com/archive/Anaconda3-2023.03-1-Linux-x86_64.sh -o ~/conda.sh
bash ~/conda.sh -b -f -p /opt/conda
rm ~/conda.sh
conda init --all --dry-run --verbose

conda create -n cv python=3.10 -y
conda activate cv
  1. Python libraries (python>=3.8)

CPU

python -m pip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cpu
python -m pip install paddleocr paddlepaddle

python -m pip install datasets transformers scikit-learn Pillow numpy pandas chardet
python -m pip install --upgrade image2layout-computer-vision

GPU

# python -m pip install 'torch>=2.0' torchvision torchaudio
conda install pytorch torchvision torchaudio pytorch-cuda=11.8 -c pytorch -c nvidia -y
python -m pip install paddleocr paddlepaddle-gpu

python -m pip install datasets transformers scikit-learn Pillow numpy pandas chardet
python -m pip install --upgrade image2layout-computer-vision

Install with docker

For running with CPU on Ubuntu

sudo docker build --tag cv -f Dockerfile_cpu .

sudo docker run -it -p 0.0.0.0:8000:8000 -p 0.0.0.0:8001:8001 -v $(pwd):/app cv bash

From inside container

cd deployment
conda activate cv
python api_serve.py -n CV -p 8000

from git

python -m pip install git+https://github.com/felix-do-wizardry/image2layout-computer-vision.git

Usage

Note: Input image/images expects a filepath, an Image.Image object, or a numpy array

  1. Run this python code to pre-download model weights
from image2layout_computer_vision import OCR
OCR._load()
  1. Recognize texts
from image2layout_computer_vision.ocr as OCR

# [A] no text, box only, 2 lists of dicts with keys [text (empty), box, score (empty)]
data_merged, data_raw = OCR.detect_text_data('path/to/image.png', recognition=False)

# [B] text + box from multiple images -> list of list of dicts with keys [text, box, score]
data_raw_multi = OCR.detect_text_elements(['path/to/image.png', 'path/to/image2.png'])
  1. Extract colors
import image2layout_computer_vision as icv

# [A] list [ tuples [ 2 rgb-color tuples ] ] for background and foreground
# sample output: [((2, 2, 2), (4, 4, 4)), ((6, 6, 6), (8, 8, 8))]
colors_all = icv.extract_colors(['path/to/image.png', 'path/to/image2.png'])

# [B] 2 rgb-color tuples for background and foreground
# sample output: ((9, 9, 9), (6, 6, 6))
color_bg, color_fg = icv.extract_colors('path/to/image.png')
  1. Detect elements [work-in-progress]
import image2layout_computer_vision.yolov6 as Detection

# pd.DataFrame with columns [box, score, class_index, class_name]
df_element = Detection.detect_element('path/to/image.png')

Build

(for building and uploading this package)

python -m pip install --upgrade pip
python -m pip install --upgrade build twine "keyring<19.0"

rm -rf dist
python -m build
python -m twine upload dist/* --verbose

Release files for image2layout-computer-vision 0.1.10

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for image2layout-computer-vision 0.1.10
File Size Uploaded
image2layout_computer_vision-0.1.10.tar.gz 13.8 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for image2layout-computer-vision 0.1.10
File Interpreter ABI Platform
image2layout_computer_vision-0.1.10-py3-none-any.whl Python 3 none any Details

Total release size: 33.6 kB

Release files / image2layout_computer_vision-0.1.10.tar.gz

Download URL image2layout_computer_vision-0.1.10.tar.gz
Size 13.8 kB
Tags Source
SHA-256 checksum
How to use checksums
0c2cbcf5ae1cd852472f919d009329263131fd8277c84b0ffb7399b6d44632d0
BLAKE2b-256 checksum
How to use checksums
5cb04100411dc2288e83518679bacb684565180eadd57af7f67ebbceef2c7744
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.10.12

Release files / image2layout_computer_vision-0.1.10-py3-none-any.whl

Download URL image2layout_computer_vision-0.1.10-py3-none-any.whl
Size 19.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
de5daa1c53057daa6360ea539bcd0b79c6c0915c74ecbde526a3e3befff08fa2
BLAKE2b-256 checksum
How to use checksums
8a352f765b2a3b3d160645e276731317ecaa86e51ded28dc32e895beaaf76af1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.10.12

Release history Release notifications | RSS feed

This release

0.1.10 This release

2 release files

0.1.9

2 release files

0.1.8

2 release files

0.1.7

2 release files

0.1.6

2 release files

0.1.5

2 release files

0.1.4

2 release files

0.1.3

2 release files

0.1.2

2 release files

0.1.1

2 release files

0.1.0

2 release files

0.0.9

2 release files

0.0.8

2 release files

0.0.7

2 release files

0.0.6

2 release files

0.0.5

2 release files

0.0.3

2 release files

0.0.2

2 release files

0.0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page