Skip to main content

A specialized utility for converting OpenCV-compatible HWC BGR 888 images to Base64-encoded data URIs. Can be used with the OpenAI Chat Completions API.

This project has been archived.

The maintainers of this project have marked this project as archived. No new releases are expected.

Project description

HWC BGR 888 Image to Base64 URI

A specialized utility for converting OpenCV-compatible HWC BGR 888 images to Base64-encoded data URIs. Can be used with the OpenAI Chat Completions API.

Usage with OpenAI Chat Completions API

from __future__ import print_function
import cv2

from hwc_bgr_888_image_to_base64_uri import hwc_bgr_888_image_to_base64_uri
from openai import OpenAI


# Initialize client
client = OpenAI(
    # For Ollama local endpoint
    base_url='http://localhost:11434/v1/',
    api_key='ollama', # Required parameter (ignored by Ollama)
)

# 1. Load image using OpenCV (native BGR format)
image = cv2.imread('input.jpg')

# 2. Convert to API-compliant URI (auto-resizes to 512px longest edge)
uri = hwc_bgr_888_image_to_base64_uri(
    image,
    max_long_edge=512, # Recommended for most vision models
    output_format_extension=u'.jpg' # Or u'.png' for quality
)

# 3. Structure chat completions request
response = client.chat.completions.create(
    model=u"llava",
    messages=[
        {
            u"role": u"user",
            u"content": [
                {u"type": u"text", u"text": u"What's in this image?"},
                {
                    u"type": u"image_url",
                    u"image_url": {
                        u"url": uri # Our generated URI
                    }
                }
            ]
        }
    ]
)

print(response.choices[0].message.content)

For more information:

Contributing

Contributions are welcome! Please submit pull requests or open issues on the GitHub repository.

License

This project is licensed under the MIT License.

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

hwc_bgr_888_image_to_base64_uri-0.1.0a0.tar.gz (3.7 kB view details)

Uploaded Source

Built Distribution

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

hwc_bgr_888_image_to_base64_uri-0.1.0a0-py2.py3-none-any.whl (4.3 kB view details)

Uploaded Python 2Python 3

File details

Details for the file hwc_bgr_888_image_to_base64_uri-0.1.0a0.tar.gz.

File metadata

File hashes

Hashes for hwc_bgr_888_image_to_base64_uri-0.1.0a0.tar.gz
Algorithm Hash digest
SHA256 f8aee3fccfd520958784f3a56ef613f65c2932689f086d195ee41573ca41fffc
MD5 6a40c129a078c49c2f0a976fe255e143
BLAKE2b-256 17b72a36ce612e520228c032e14fab176e3ef3882e17d42b79b264000545315d

See more details on using hashes here.

File details

Details for the file hwc_bgr_888_image_to_base64_uri-0.1.0a0-py2.py3-none-any.whl.

File metadata

File hashes

Hashes for hwc_bgr_888_image_to_base64_uri-0.1.0a0-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 1fa7047d9ce106c02e0748a2c86e6553f2a5cf82d41a8cd38fdb240cfd105119
MD5 b3ca7a8cfe8eb8c36c7c55825179587a
BLAKE2b-256 5f4737ef13a986f81d8bbd03ceabfec84a3fcea3163358efae8d30d4e747ec28

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