Skip to content

Commit

Permalink
Adds LibHand/OGRE integration test
Browse files Browse the repository at this point in the history
This commit adds a simple test (based on the bend_one_finger example), which
simple renders a hand, counts the number of non-black pixels. If the number is
greater than some arbitrary constant (10 was chosen), the test is considered a
success, showing that OGRE was able to load and configure its plugins and
render an image -- a basic behaviour that is surprisingly unreliable between
different configurations and platforms.

If rendered images were bit-for-bit identical, it would have been more robust
to do a file comparison as an integration test. This is unlikely between
platforms.

This patch also integrates it into Travis CI, and AppVeyor.
  • Loading branch information
shasheene committed Nov 13, 2016
1 parent 11aaf5b commit dce92e4
Show file tree
Hide file tree
Showing 4 changed files with 86 additions and 1 deletion.
6 changes: 6 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -107,3 +107,9 @@ script:
- make
- popd
- popd
# Setup runtime link paths (see BUILD.DEBIAN.md)
- export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:${OGRE_HOME}
- sudo ldconfig
# Run LibHand integration test
- ./examples/build/ogre_rendering_test .

2 changes: 2 additions & 0 deletions appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,5 +42,7 @@ build_script:
# from Chocolatey, and also dependencies that must be compiled from source). After the dependencies
# it compiles LibHand.
- cmd: bash -x -c ./docs/build_instructions/windows/download_and_build.sh
- cmd: examples\build\Release\ogre_rendering_test.exe .
- cmd: bash -x -c ./docs/build_instructions/windows/download_and_build.sh --build-ogre-mode
- cmd: examples\build\Release\ogre_rendering_test.exe .

5 changes: 4 additions & 1 deletion examples/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,7 @@ ADD_EXECUTABLE(render_hog_descriptor render_hog_descriptor.cc)
TARGET_LINK_LIBRARIES(render_hog_descriptor ${LibHand_LIBRARIES} ${OpenCV_LIBS})

ADD_EXECUTABLE(file_dialog_test file_dialog_test.cc)
TARGET_LINK_LIBRARIES(file_dialog_test hand_utils)
TARGET_LINK_LIBRARIES(file_dialog_test hand_utils)

ADD_EXECUTABLE(ogre_rendering_test ogre_rendering_test.cc)
TARGET_LINK_LIBRARIES(ogre_rendering_test ${LibHand_LIBRARIES})
74 changes: 74 additions & 0 deletions examples/ogre_rendering_test.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
# include <string>
# include "opencv2/opencv.hpp"
# include "file_dialog.h"
# include "hand_pose.h"
# include "hand_renderer.h"
# include "scene_spec.h"
// Success/failure macro
# include <cstdlib>

/* This file adds a simple test (based on the bend_one_finger example), which
simple renders a hand, counts the number of non-black pixels. If the number is
greater than some arbitrary constant (10 was chosen), the test is considered a
success, showing the backend render (OGRE) was able to load and configure its
plugins and render an image -- a basic behaviour that is surprisingly unreliable
between different configurations and platforms.
If rendered image produced by OGRE were bit-for-bit identical on every
system, it will have been a more robust integration test to do a
comparison of each pixel in the image with a test image file bundled with
LibHand. However, given OGRE supports different graphics cards and
software renderers using different rendering APIs (OpenGL vs DirectX) on
different operating systems, it's unlikely to be perfectly deterministic,
but this assertion has not been verified.
*/

// Arbitrary success metric. Needs at least:
const int kNumNonBlackPixels = 10;

int main(int argc, char **argv) {
try {
if (argc <= 1 ) {
std::cout << "Usage: " << argv[0] << " [path to resource directory]"<< std::endl;
exit(0);
}
std::string resource_dir = argv[1];

libhand::HandRenderer hand_renderer;
hand_renderer.Setup(hand_renderer.kDefaultWidth, hand_renderer.kDefaultHeight);

libhand::SceneSpec scene_spec(resource_dir + "/hand_model/scene_spec.yml");

// Tell the renderer to load the scene
hand_renderer.LoadScene(scene_spec);
// Now we render a hand using a default pose
hand_renderer.RenderHand();

// We can get an OpenCV matrix from the rendered hand image
cv::Mat pic = hand_renderer.pixel_buffer_cv();

double num_non_black_pixels=0;
for (int i=0; i< pic.rows;i++) {
for (int j=0; j< pic.cols*pic.channels();j=j+pic.channels()) {
if ((pic.ptr<uchar>(i)[j]==0) && (pic.ptr<uchar>(i)[j+1]==0) && (pic.ptr<uchar>(i)[j+2]==0)) {
num_non_black_pixels++;
}
}
}

// We need more non-black pixels than the threshold to succeed
if (num_non_black_pixels > kNumNonBlackPixels) {
std::cout << "Image appeared to render correctly, with " << num_non_black_pixels << " non-black pixels in the rendered image" << std::endl;
exit(EXIT_SUCCESS);
} else {
std::cerr << "Image failed to render correctly, with " << num_non_black_pixels << " non-black pixels in the rendered image" << std::endl;
exit(EXIT_FAILURE);
}

} catch (const std::exception &e) {
std::cerr << "Exception: " << e.what() << std::endl;
exit(EXIT_FAILURE);
}

return 0;
}

0 comments on commit dce92e4

Please sign in to comment.