<div dir="ltr"><div><div>HI <span class="gmail-im">Rômulo,<br><br></span></div><span class="gmail-im">I can't spot anything specific in your code that might cause a problem loading images.  It could be the paths to the files, personally I'd not hard-wire the filenames even for early code. The other thing is perhaps there is something odd about you are building/linking the OSG.<br><br>The best I can recommend is to create a small example code that you can test just the image loading code, once this is works compare it to the rest of your application.  The OSG examples might be something to use as a base.<br><br></span></div><span class="gmail-im">Robert.<br></span></div><div class="gmail_extra"><br><div class="gmail_quote">On 16 August 2017 at 02:58, Rômulo Cerqueira <span dir="ltr"><<a href="mailto:romulogcerqueira@gmail.com" target="_blank">romulogcerqueira@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hi Robert,<br>
<br>
thanks for your reply. Follows my code:<br>
<br>
Code:<br>
<br>
#define BOOST_TEST_MODULE "NormalMapping_test"<br>
#include <boost/test/unit_test.hpp><br>
<br>
// OpenSceneGraph includes<br>
#include <osg/Geode><br>
#include <osg/Group><br>
#include <osg/Image><br>
#include <osg/ShapeDrawable><br>
#include <osg/StateSet><br>
#include <osg/Texture2D><br>
#include <osgDB/ReadFile><br>
#include <osgViewer/Viewer><br>
<br>
// Rock includes<br>
#include <normal_depth_map/<wbr>NormalDepthMap.hpp><br>
#include <normal_depth_map/<wbr>ImageViewerCaptureTool.hpp><br>
<br>
// OpenCV includes<br>
#include <opencv2/core/core.hpp><br>
#include <opencv2/highgui/highgui.hpp><br>
#include <opencv2/imgproc/imgproc.hpp><br>
#include <opencv2/contrib/contrib.hpp><br>
<br>
// C++ includes<br>
#include <iostream><br>
<br>
using namespace normal_depth_map;<br>
<br>
BOOST_AUTO_TEST_SUITE(<wbr>NormalMapping)<br>
<br>
<br>
// add one object to scene (sphere)<br>
void addSimpleObject(osg::ref_ptr<<wbr>osg::Group> root) {<br>
    osg::ref_ptr<osg::Geode> geode = new osg::Geode();<br>
    geode->addDrawable(new osg::ShapeDrawable(new osg::Sphere(osg::Vec3(0,0,-14)<wbr>, 5)));<br>
    root->addChild(geode);<br>
    root->getChild(0)->asGeode()-><wbr>addDrawable(geode-><wbr>getDrawable(0));<br>
}<br>
<br>
// define texture attributes<br>
osg::ref_ptr<osg::StateSet> insertNormalMapTexture(osg::<wbr>ref_ptr<osg::Image> diffuseImage, osg::ref_ptr<osg::Image> normalImage) {<br>
    osg::ref_ptr<osg::Texture2D> diffuse = new osg::Texture2D();<br>
    osg::ref_ptr<osg::Texture2D> normal = new osg::Texture2D();<br>
<br>
    diffuse->setImage(<wbr>diffuseImage);<br>
    diffuse->setDataVariance(osg::<wbr>Object::DYNAMIC);<br>
    diffuse->setFilter(osg::<wbr>Texture::MIN_FILTER, osg::Texture::LINEAR_MIPMAP_<wbr>LINEAR);<br>
    diffuse->setFilter(osg::<wbr>Texture::MAG_FILTER, osg::Texture::LINEAR);<br>
    diffuse->setWrap(osg::Texture:<wbr>:WRAP_S, osg::Texture::REPEAT);<br>
    diffuse->setWrap(osg::Texture:<wbr>:WRAP_T, osg::Texture::REPEAT);<br>
    diffuse-><wbr>setResizeNonPowerOfTwoHint(<wbr>false);<br>
    diffuse->setMaxAnisotropy(8.<wbr>0f);<br>
<br>
    normal->setImage(normalImage);<br>
    normal->setDataVariance(osg::<wbr>Object::DYNAMIC);<br>
    normal->setFilter(osg::<wbr>Texture::MIN_FILTER, osg::Texture::LINEAR_MIPMAP_<wbr>LINEAR);<br>
    normal->setFilter(osg::<wbr>Texture::MAG_FILTER, osg::Texture::LINEAR);<br>
    normal->setWrap(osg::Texture::<wbr>WRAP_S, osg::Texture::REPEAT);<br>
    normal->setWrap(osg::Texture::<wbr>WRAP_T, osg::Texture::REPEAT);<br>
    normal-><wbr>setResizeNonPowerOfTwoHint(<wbr>false);<br>
    normal->setMaxAnisotropy(8.0f)<wbr>;<br>
<br>
    osg::ref_ptr<osg::StateSet> normalState = new osg::StateSet();<br>
    normalState-><wbr>setTextureAttributeAndModes(<wbr>TEXTURE_UNIT_DIFFUSE, diffuse, osg::StateAttribute::ON);<br>
    normalState-><wbr>setTextureAttributeAndModes(<wbr>TEXTURE_UNIT_NORMAL, normal, osg::StateAttribute::ON);<br>
    return normalState;<br>
}<br>
<br>
// get texture files<br>
void loadTextures(osg::ref_ptr<osg:<wbr>:Group> root, TextureImages textureId) {<br>
    osg::ref_ptr<osg::Image> diffuseImage = osgDB::readImageFile("/home/<wbr>romulo/dev.bir.master/<wbr>simulation/normal_depth_map/<wbr>textures/gray_texture_d.jpg");<br>
    osg::ref_ptr<osg::Image> normalImage = osgDB::readImageFile("/home/<wbr>romulo/dev.bir.master/<wbr>simulation/normal_depth_map/<wbr>textures/gray_texture_n.jpg");<br>
<br>
    // texture properties<br>
    osg::ref_ptr<osg::Geode> geode = new osg::Geode();<br>
    geode->setStateSet(<wbr>insertNormalMapTexture(<wbr>diffuseImage, normalImage));<br>
    root->addChild(geode);<br>
}<br>
<br>
// create scene with normal mapping and one object<br>
osg::ref_ptr<osg::Group> createNormalMapSimpleScene() {<br>
    osg::ref_ptr<osg::Group> root = new osg::Group();<br>
    osg::ref_ptr<osg::StateSet> stateset = new osg::StateSet();<br>
    stateset->addUniform(new osg::Uniform("diffuseTexture", TEXTURE_UNIT_DIFFUSE));<br>
    stateset->addUniform(new osg::Uniform("normalTexture", TEXTURE_UNIT_NORMAL));<br>
    stateset->setDataVariance(osg:<wbr>:Object::STATIC);<br>
    root->setStateSet(stateset);<br>
<br>
    loadTextures(root, TEXTURE_GRAY);<br>
    addSimpleObject(root);<br>
    return root;<br>
}<br>
<br>
// compute the normal depth map for a osg scene<br>
cv::Mat computeNormalDepthMap(osg::<wbr>ref_ptr<osg::Group> root, float maxRange, float fovX, float fovY) {<br>
    uint height = 500;<br>
<br>
    // normal depth map<br>
    NormalDepthMap normalDepthMap(maxRange, fovX * 0.5, fovY * 0.5);<br>
    ImageViewerCaptureTool capture(fovY, fovX, height);<br>
    capture.setBackgroundColor(<wbr>osg::Vec4d(0, 0, 0, 0));<br>
    normalDepthMap.addNodeChild(<wbr>root);<br>
<br>
    // grab scene<br>
    osg::ref_ptr<osg::Image> osgImage = capture.grabImage(<wbr>normalDepthMap.<wbr>getNormalDepthMapNode());<br>
    osg::ref_ptr<osg::Image> osgDepth = capture.getDepthBuffer();<br>
    cv::Mat cvImage = cv::Mat(osgImage->t(), osgImage->s(), CV_32FC3, osgImage->data());<br>
    cv::Mat cvDepth = cv::Mat(osgDepth->t(), osgDepth->s(), CV_32FC1, osgDepth->data());<br>
    cvDepth = cvDepth.mul( cv::Mat1f(cvDepth < 1) / 255);<br>
<br>
    std::vector<cv::Mat> channels;<br>
    cv::split(cvImage, channels);<br>
    channels[1] = cvDepth;<br>
    cv::merge(channels, cvImage);<br>
    cv::cvtColor(cvImage, cvImage, cv::COLOR_RGB2BGR);<br>
    cv::flip(cvImage, cvImage, 0);<br>
<br>
    return cvImage.clone();<br>
}<br>
<br>
BOOST_AUTO_TEST_CASE(<wbr>differentNormalMaps_TestCase) {<br>
    float maxRange = 20.0f;<br>
    float fovX = M_PI / 3;  // 60 degrees<br>
    float fovY = M_PI / 3;  // 60 degrees<br>
<br>
    osg::ref_ptr<osg::Group> normalRoot = createNormalMapSimpleScene();<br>
<br>
    cv::Mat cvNormal = computeNormalDepthMap(<wbr>normalRoot, maxRange, fovX, fovY);<br>
<br>
    plotSonarTest(cvNormal, maxRange, fovX * 0.5);<br>
}<br>
<br>
BOOST_AUTO_TEST_SUITE_END()<br>
<span class=""><br>
<br>
<br>
<br>
<br>
...<br>
<br>
Thank you!<br>
<br>
Cheers,<br>
Rômulo<br>
<br>
</span><span class="">------------------<br>
Read this topic online here:<br>
</span><a href="http://forum.openscenegraph.org/viewtopic.php?p=71422#71422" rel="noreferrer" target="_blank">http://forum.openscenegraph.<wbr>org/viewtopic.php?p=71422#<wbr>71422</a><br>
<div class="HOEnZb"><div class="h5"><br>
<br>
<br>
<br>
<br>
______________________________<wbr>_________________<br>
osg-users mailing list<br>
<a href="mailto:osg-users@lists.openscenegraph.org">osg-users@lists.<wbr>openscenegraph.org</a><br>
<a href="http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org" rel="noreferrer" target="_blank">http://lists.openscenegraph.<wbr>org/listinfo.cgi/osg-users-<wbr>openscenegraph.org</a><br>
</div></div></blockquote></div><br></div>