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:
- https://platform.openai.com/docs/api-reference/chat/create
- https://github.com/ollama/ollama/blob/main/docs/openai.md#curl
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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file hwc_bgr_888_image_to_base64_uri-0.1.0a0.tar.gz.
File metadata
- Download URL: hwc_bgr_888_image_to_base64_uri-0.1.0a0.tar.gz
- Upload date:
- Size: 3.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f8aee3fccfd520958784f3a56ef613f65c2932689f086d195ee41573ca41fffc
|
|
| MD5 |
6a40c129a078c49c2f0a976fe255e143
|
|
| BLAKE2b-256 |
17b72a36ce612e520228c032e14fab176e3ef3882e17d42b79b264000545315d
|
File details
Details for the file hwc_bgr_888_image_to_base64_uri-0.1.0a0-py2.py3-none-any.whl.
File metadata
- Download URL: hwc_bgr_888_image_to_base64_uri-0.1.0a0-py2.py3-none-any.whl
- Upload date:
- Size: 4.3 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1fa7047d9ce106c02e0748a2c86e6553f2a5cf82d41a8cd38fdb240cfd105119
|
|
| MD5 |
b3ca7a8cfe8eb8c36c7c55825179587a
|
|
| BLAKE2b-256 |
5f4737ef13a986f81d8bbd03ceabfec84a3fcea3163358efae8d30d4e747ec28
|