Ask Your Question

Revision history [back]

Setting pose of Viz3d changes camera parameters

When I call Viz3d::setViewerPose, the camera parameters of the Viz3d window changes. In particular, it seems to zoom out significantly, even when the pose that I set is unchanged, i.e., when I set the one I can obtain with Viz3d::getViewerPose. The following code illustrates the issue:

#include <iostream>
#include <opencv2/viz.hpp>

using namespace std;
using namespace cv;
using namespace cv::viz;

int main()
{
  Viz3d visualization("Test");
  visualization.showWidget("Test object", WCone(1, 0.5, 100));
  /*const auto pose = visualization.getViewerPose();
  visualization.setViewerPose(pose);*/ //Uncomment this line and the one above it to see the described effect
  //cout << visualization.getCamera().getClip() << endl; //Debugging (uncomment this for an even stranger effect)

  visualization.spinOnce(1, true);
  while (!visualization.wasStopped())
    visualization.spinOnce(1, true);
  return 0;
}

When the two lines of code above are commented, the window looks like this: Code commented (no effect)

When the two lines of code above are uncommented, the window looks like this: Code uncommented (effect visible)

To pinpoint the issue, I added a line that outputs the changing camera parameter (which I found after some debugging). Printing this camera parameter gives different results, depending on whether the pose is set, i.e., whether the two lines above it are commented. The strange thing, however, is, that just printing this parameter makes the effect I described above disappear.

I don't know how to make this effect go away. In a more complex example, I tried to adjust the pose, but I could not do so because the camera kept "zooming" when I just read some parameters, making it impossible to set or change values in a meaningful way. Is this a bug, perhaps?

Setting pose of Viz3d changes camera parameters

When I call Viz3d::setViewerPose, the camera parameters of the Viz3d window changes. change. In particular, it seems to zoom out significantly, even when the pose that I set is unchanged, i.e., when I set the one I can obtain with Viz3d::getViewerPose. The following code illustrates the issue:

#include <iostream>
#include <opencv2/viz.hpp>

using namespace std;
using namespace cv;
using namespace cv::viz;

int main()
{
  Viz3d visualization("Test");
  visualization.showWidget("Test object", WCone(1, 0.5, 100));
  /*const auto pose = visualization.getViewerPose();
  visualization.setViewerPose(pose);*/ //Uncomment this line and the one above it to see the described effect
   //cout << visualization.getCamera().getClip() << endl; //Debugging (uncomment this for an even stranger effect)

  visualization.spinOnce(1, true);
  while (!visualization.wasStopped())
    visualization.spinOnce(1, true);
  return 0;
}

When the two lines of code above are commented, the window looks like this: Code commented (no effect)

When the two lines of code above are uncommented, the window looks like this: Code uncommented (effect visible)

To pinpoint the issue, I added a line that outputs the changing camera parameter (which I found after some debugging). Printing this camera parameter gives different results, depending on whether the pose setViewerPose is set, called, i.e., whether the two lines above it are commented. The strange thing, however, is, that just printing this parameter calling Viz3d::getCamera() (here, for printing) makes the "zoom" effect I described above disappear.

I don't know whether either of the two effects are identended and I don't know how to make this effect them go away. In a more complex example, I tried to adjust the pose, pose in the same way, but I could not do so because the camera kept "zooming" when I just read some parameters, making it impossible to set or change values in a meaningful way. Is this a bug, perhaps?