How to Install OpenImageIO on Windows and Linux#
OpenImageIO (OIIO) is an open-source library for reading, writing, and manipulating image files. It is widely used in the visual effects and animation industries. Here's a step-by-step guide to installing OIIO on both Windows and Linux systems using vcpkg
, a popular C++ library manager.
Prerequisites#
- Python 3.11.8
- Git
- VCPKG
- VSCode or Cursor
Step 1: Install vcpkg#
vcpkg is a free, open-source package manager for C and C++ libraries. It was developed by Microsoft to simplify the process of managing and building third-party libraries in C++ projects. vcpkg helps developers easily find, install, and manage libraries across multiple platforms, including Windows, Linux, and macOS.
Prerequisites for Linux#
If you're on Linux, make sure to install the following dependencies:
sudo apt-get install git cmake build-essential curl tar gzip unzip zip pkg-config autoconf automake libtool autoconf-archive
Prerequisites for Windows:#
Install Visual Studio https://visualstudio.microsoft.com/vs/community/ and the C++ components
Git Clone VCPKG#
Run git clone on the vcpkg repository from Microsoft:
"git clone https://github.com/microsoft/vcpkg.git"
Step 2: Setup VCPKG#
Navigate to the directory where you cloned vcpkg
and run the following commands:
For Windows:#
.\bootstrap-vcpkg.bat
For Linux:#
./bootstrap-vcpkg.sh
Step 3: Install OpenImageIO with Python Bindings#
To install OpenImageIO, run the following command from within the vcpkg
directory:
vcpkg install openimageio[tools,opencolorio,pybind11]
When building with vcpkg, the python bindings are an optional but in most cases necessary extension.
Other options can be seen by looking at the openmageio port file for vcpkg:
1vcpkg_check_features(OUT_FEATURE_OPTIONS FEATURE_OPTIONS
2 FEATURES
3 libraw USE_LIBRAW
4 opencolorio USE_OPENCOLORIO
5 ffmpeg USE_FFMPEG
6 freetype USE_FREETYPE
7 gif USE_GIF
8 opencv USE_OPENCV
9 openjpeg USE_OPENJPEG
10 webp USE_WEBP
11 libheif USE_LIBHEIF
12 pybind11 USE_PYTHON
13 tools OIIO_BUILD_TOOLS
14 viewer ENABLE_IV
15)
Step 4: Configure OpenImageIO for Python#
Windows#
- After installation, copy the file
vcpkg\installed\x64-windows\lib\python3.10\site-packages\OpenImageIO.cp310-win_amd64.pyd
to the desiredoiio
folder. - Copy the necessary DLLs from
vcpkg\installed\x64-windows\bin
to the sameoiio
folder. - Rename the
.pyd
file toOpenImageIO.pyd
.
Linux#
Create an environment with the required Python version (3.11.8) and set up dependencies using the following script:
To complete the installation, create a symbolic link:
1ln -s /vcpkg/installed/x64-linux/lib/python3.11/site-packages/OpenImageIO/OpenImageIO.cpython-311-x86_64-linux-gnu.so
2/usr/local/lib/python3.11/site-packages/OpenImageIO.so
Step 5: Generate Python Bindings#
Generate Python stubs for code completion and add them to the VSCode python search path.python3 -m pip install mypy
stubgen -m OpenImageIO -o ./
.vscode/settings.json
1{
2 "python.pythonPath": "${workspaceFolder}/.venv/bin/python",
3 "python.analysis.extraPaths": [
4 "${workspaceFolder}/oiio"
5 ]
6}
Conclusion#
By following these steps, you can successfully install OpenImageIO on both Windows and Linux, allowing you to leverage its powerful image processing capabilities in your projects.
Here is an example of OIIO in action that converts exr to png
1import os,sys
2sys.path.insert(1, os.path.join(os.getcwd() , '..', 'oiio'))
3
4import OpenImageIO as oiio
5from OpenImageIO import ImageInput, ImageOutput
6from OpenImageIO import ImageBuf, ImageSpec, ImageBufAlgo
7
8folder = "/show/seq/elements/plate"
9
10# Function to convert EXR to PNG
11def convert_exr_to_png(input_path, output_path):
12
13 source_image = ImageBuf(input_path)
14 # Apply color transformation
15 destination_image = ImageBufAlgo.colorconvert(source_image, "acescg","sRGB", True)
16 destination_image.set_write_format(oiio.UINT8)
17 destination_image.write(output_path)
18
19
20 print(f"Converted {input_path} to {output_path}")
21
22# Iterate through all files in the folder
23for filename in os.listdir(folder):
24 if filename.lower().endswith('.exr'):
25 input_path = os.path.join(folder, filename)
26 output_path = os.path.join(folder, os.path.splitext(filename)[0] + '.png')
27 convert_exr_to_png(input_path, output_path)
28
29print("Conversion complete.")
Dockerfile#
1# Use the official Debian slim image with Python 3.11.8
2FROM python:3.11.8-slim
3
4# Install required packages
5RUN apt-get update && \
6 apt-get install -y \
7 git \
8 cmake \
9 build-essential \
10 curl \
11 tar \
12 gzip \
13 unzip \
14 zip \
15 pkg-config \
16 autoconf \
17 automake \
18 libtool \
19 pkg-config \
20 autoconf-archive && \
21 rm -rf /var/lib/apt/lists/*
22
23# Clone vcpkg repository
24RUN git clone https://github.com/microsoft/vcpkg.git /vcpkg
25
26# Set working directory
27WORKDIR /vcpkg
28
29# Bootstrap vcpkg
30RUN ./bootstrap-vcpkg.sh
31
32# Install OpenImageIO and dependencies via vcpkg
33RUN ./vcpkg install openimageio[tools,opencolorio,pybind11]
34
35# Create symlink to make OpenImageIO available in Python's site-packages
36RUN ln -s /vcpkg/installed/x64-linux/lib/python3.11/site-packages/OpenImageIO/OpenImageIO.cpython-311-x86_64-linux-gnu.so /usr/local/lib/python3.11/site-packages/OpenImageIO.so
37
38# Default command
39CMD [ "python3" ]
Resources#
https://www.studyplan.dev/pro-cpp/vcpkg-windows
https://tomasroggero.com/notes/how-to-install-openimageio-in-mac-os-x-el-capitan