Skip to main content

A lightweight palm region-of-interest (ROI) extraction tool using hand landmarks and OpenCV.

Project description

palm_roi - A region-of-interest extraction tool 🖐️

A lightweight palm region-of-interest (ROI) extraction Python library, originally built for use in a palm-vein biometric imaging device. It makes use of OpenCV and hand landmarks (using tools like MediaPipe) to compute an ROI of a palm in an image, calculate a rotation matrix to straighten it out, and process coordinates.

The original Raspberry Pi example with a live camera feed has been moved to the examples/ directory. Check out the example's README.md for details on how to set it up!

Installation

You can install palm_roi easily via pip:

pip install palm_roi

Note: Depending on your setup (e.g., using MediaPipe to get the hand landmarks), your Python version compatibility will be constrained. The palm_roi library currently works with Python 3.8+, but MediaPipe currently requires Python <3.13.

Usage

Here's an example using Mediapipe hands with palm_roi to extract hand landmarks and perform ROI computation:

import palm_roi
import cv2
import mediapipe as mp

# 1. Provide an image and get hand landmarks from MediaPipe (or another tool)
image = # - your image data - #
hands = mp.solutions.hands.Hands(static_image_mode=True, max_num_hands=1)
results = hands.process(cv2.cvtColor(image, cv2.COLOR_GRAY2RGB))

if results.multi_hand_landmarks:
    INDEX_FINGER_MCP = results.multi_hand_landmarks[0].landmark[5]
    PINKY_MCP = results.multi_hand_landmarks[0].landmark[17]
    WRIST = results.multi_hand_landmarks[0].landmark[0]

    # 2. Apply padding, rotation, and cropping to your image automatically.
    output, error = palm_roi.extract(image, INDEX_FINGER_MCP, PINKY_MCP, WRIST)

    # Note: If you do not have or prefer not to provide a wrist landmark, pass `upside_down=True` or `False` directly:
    # output, error = palm_roi.extract(image, INDEX_FINGER_MCP, PINKY_MCP, upside_down=False)

    if not error:
        cv2.imwrite(f"output.png", output) # Save your processed ROI!

    # Alternatively, get the ROI boundaries, rotation matrix, and orientation for manual application.
    R, roi_height, l1, l2, upside_down = palm_roi.get_coords(image, INDEX_FINGER_MCP, PINKY_MCP, WRIST)
    # R, roi_height, l1, l2, upside_down = palm_roi.get_coords(image, INDEX_FINGER_MCP, PINKY_MCP, upside_down=False)

The landmark parameters (INDEX_FINGER_MCP, PINKY_MCP, and WRIST) accept standard (x, y) coordinate tuples, lists, as well as direct landmark objects from tools like MediaPipe.

See examples/main.py for a full implementation demonstrating real-time camera processing and Mediapipe.

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

palm_roi-0.1.1.tar.gz (484.0 kB view details)

Uploaded Source

Built Distribution

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

palm_roi-0.1.1-py3-none-any.whl (5.9 kB view details)

Uploaded Python 3

File details

Details for the file palm_roi-0.1.1.tar.gz.

File metadata

  • Download URL: palm_roi-0.1.1.tar.gz
  • Upload date:
  • Size: 484.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.0

File hashes

Hashes for palm_roi-0.1.1.tar.gz
Algorithm Hash digest
SHA256 5b07795839494ad48fb2d8123ea4e787917ec54e7c6674aa70b7152936d2dd9a
MD5 a5a0853e1230a99f8be3ab3d5d07e0b7
BLAKE2b-256 1c80ff508add11121ee524c968442923f75c4f6d98da9132b8fcae844b6e735a

See more details on using hashes here.

File details

Details for the file palm_roi-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: palm_roi-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 5.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.0

File hashes

Hashes for palm_roi-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 f39794e557512b8f29dbcb534466806994a15d4d8624491354c3a885cfb406b1
MD5 d93e246016ed78c26d23f60f3ec89f0c
BLAKE2b-256 a0a0b3a20666a8445f1f8d7e0674e46cd6159fbd765602ef918ad155e3a4853a

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