openFrameworks addon for computing homography matrices for perspective warps, projection mapping, and screen-coordinate transforms.
Branches ahead of master
These branches have commits not yet on master — could be unmerged fixes or work in progress worth a look.
README
ofxHomography

ofxHomography is a small openFrameworks addon for finding the homography matrix between two sets of four points. It is useful for perspective warps, projection mapping helpers, screen-to-surface coordinate transforms, and other quad-to-quad mapping tasks.The addon is header-only and has no external dependencies beyond openFrameworks' bundled math/GLM support.
Installation
Clone or copy this repository into your openFrameworks
addons/ folder:cd /path/to/openFrameworks/addons
git clone https://github.com/paulobarcelos/ofxHomography.gitAdd
ofxHomography to your project's addons.make, or include it through the openFrameworks Project Generator.The example also includes an
of.yml recipe for ofWorks/ofGen users.Quick Start
#include "ofxHomography.h"
std::array<glm::vec2, 4> source = {{
{ 0.0f, 0.0f },
{ 100.0f, 0.0f },
{ 100.0f, 100.0f },
{ 0.0f, 100.0f }
}};
std::array<glm::vec2, 4> destination = {{
{ 20.0f, 30.0f },
{ 420.0f, 10.0f },
{ 390.0f, 360.0f },
{ 30.0f, 410.0f }
}};
glm::mat4 homography = ofxHomography::findHomography(source, destination);
ofPushMatrix();
ofMultMatrix(homography);
ofDrawRectangle(0, 0, 100, 100);
ofPopMatrix();
glm::vec2 localPoint(80, 80);
glm::vec2 screenPoint = ofxHomography::toScreenCoordinates(localPoint, homography);API
ofxHomography::findHomography(src, dst, float homography[16])fills an OpenGL-style 4x4 float matrix.ofxHomography::findHomography(src, dst)returns aglm::mat4.ofxHomography::toScreenCoordinates(point, homography)transforms aglm::vec2orglm::vec3through a homography.
toScreenCoordinates(const ofPoint&, const ofMatrix4x4&) is also available for compatibility.Compatibility
Current
master is tested with:- openFrameworks 0.12.1 on macOS using the official addon Makefile workflow.
- ofWorks/ofGen 1.0.8 on macOS using the included
of.ymland Chalet template.
1.1.0 remains the last tagged release documented as tested with openFrameworks 0.11.2.Development
Official openFrameworks:
cd /path/to/openFrameworks/addons/ofxHomography/example
make Debug -j8
make RunDebugofWorks/ofGen:
cd /path/to/ofworks/addons/ofxHomography/example
/path/to/ofworks/ofGen/dist/ofgen buildLicense
MIT
Version History
Version 2.0.0
- Modernized the example from
testApptoofApp. - Moved the primary matrix/point API to
glm. - Added an ofWorks/ofGen
of.ymlrecipe. - Kept the official openFrameworks Makefile project files for the example.
- Verified builds with openFrameworks 0.12.1 and ofWorks/ofGen 1.0.8 on macOS.
Version 1.1.0 (2021.03.31)
- Adapted to the official addon template.
- Cleanup.
Get this addon
Latest release
What's Changed
- Modernizes the addon around current openFrameworks math conventions: primary APIs now return/use
glm::mat4andglm::vec2/glm::vec3. - Updates the example from the legacy
testAppnaming toofApp. - Adds an
of.ymlrecipe for ofWorks/ofGen while keeping the official openFrameworks Makefile files. - Improves the README with installation, quick-start, API, compatibility, and development notes.
- Keeps a legacy
toScreenCoordinates(const ofPoint&, const ofMatrix4x4&)overload for official openFrameworks builds that expose the old math classes.
Compatibility
Verified on macOS with:
- openFrameworks 0.12.1 using
make Debug -j8in the example. - ofWorks/ofGen 1.0.8 using
ofgen buildwith the includedof.yml.
Upgrade Note
This is a major release because the primary convenience API now returns
glm::mat4 instead of ofMatrix4x4. Code that uses ofMultMatrix should continue to work in current openFrameworks, but projects storing the return value as ofMatrix4x4 may need to switch to glm::mat4 or rely on openFrameworks' conversion support.
ofxAddons