Hexagon Cell  v.1.1.1
Demo Code

In this demo, we show a very simple example of using our library: a test image will be pixelized with hexagonical patches. First, an image is opened and class instanses HexagonCells::CCell and HexagonCells::CMarker are created and initialized. Then, after the number of cells in image is known, we draw hexagons upon the image and show it. After a keypress, the application exits.

#include "hCell.h"
using namespace HexagonCells;
int main ()
{
// CCell class is resposible for calcilating average color values
// within each hexagon, mapped on the input image
CCell cell;
// CMarker class is responsible for drawing solid and wireframe
// hexagons on given images
CMarker marker;
// We chose the hexagon area S to be equal to 25 pixels,
// thus the hexagon radius R is calculated as R = 0.6204 * sqrt(S)
const double R = 3.102;
cell.setRadius(R);
// Load and set the test image
Mat img = imread("test_image.jpg", 1);
cell.setImage(img);
// Achieving the number of hexagons, corresponding to the input image
cell_params params = cell.getInfo();
// Drawing solid hexagons on the same input image
for (register int n = 0; n < params.N; n++)
marker.markHexagon(img, R, n, cell.getVal(n));
// Optinally mark the drawn hexagons with a grid of custom color
marker.markGrid(img, R, CV_RGB(0, 128, 64));
// Show the result
imshow("Demo", img);
cvWaitKey();
return 0;
}

Additionally, if you use the version of the library with pre-build binaries, you can drag-and-drop an image to the Demo.exe application. The pixellized with hexagons version of the image will be created in the same directory with suffix "_hex" in the file name.