Creating a height map from an image
In this recipe, we will learn how to create a point cloud based on an image selected by the user. We will create a grid of points where each point will correspond to a pixel. The x and y coordinates of each point will be equal to the pixel's position on the image, and the z coordinate will be calculated based on its color.
Getting ready
Include the necessary files to work with OpenGL, image surfaces, VBO meshes, and loading images.
Add the following code to the top of the source file:
#include "cinder/gl/gl.h" #include "cinder/Surface.h" #include "cinder/gl/Vbo.h" #include "cinder/MayaCamUI.h" #include "cinder/ImageIo.h"
Also, add the following using
statements:
using namespace ci; using namespace ci::app; using namespace std;
How to do it…
We will learn how to read pixel values from an image and create a point cloud.
Declare
ci::Surface32f
to store the image pixels,ci::gl::VboMesh
that we will use as the point cloud, andci::MayaCamUI
for easy rotation of our...