Viz3d setCamera() only works the first time it is called

asked 2015-07-10 14:34:48 -0500

heydinge gravatar image

updated 2015-07-10 19:30:36 -0500

The viz3d API allows us to make a cv::viz::Camera with desired intrinsic parameters, and to use the camera by calling setCamera. Two of the intrinsic parameters include fy and fx. These values appear to only "stick" the first time setCamera() is called.

In the code below I create my own camera myCam1 with focal lengths fx = fy = 950. Calling getCamera(myCam1) shows these correct values. Setting this camera, followed by getCamera() shows the same correct focal lengths, 950.

Next I crate another camera, this time myCam2 with focal lengths 475. The focal lengths of the camera appear correct. After calling setCamera() and getCamera() the focal lengths are 597.128, incorrect, whereas they should be 475. The myCam2 values do not appear to take effect the second time around.

I expect that if I create a camera with a given fx and fy, then call setCamera for this camera and then getCamera, then the camera returned by getCamera should have the focal lengths fx and fy. This appears to happen the first time setCamera is called but not the second. (Try swapping the myCam1 and myCam2 sections. The pattern holds - it works the first time, not the second).

Anyone know why the specified fx and fy don't take effect???

#include <opencv2\opencv.hpp>
#include <opencv2\viz.hpp>

int main()
{
    cv::viz::Viz3d myWindow("setCamera() TEST");

    // Original Camera
    // ===============
    std::cout << "original camera ACTUAL: " << myWindow.getCamera().getFocalLength() << std::endl; 
    // 802.391, 802.391


    // cam1
    // ====
    cv::viz::Camera myCam1(950.0, 950.0, 240.0, 320.0, cv::Size(480, 640));
    std::cout << "cam1: "        << myCam1.getFocalLength()               << std::endl; 
    // 950, 950 = CORRECT

    myWindow.setCamera(myCam1);
    std::cout << "cam1 ACTUAL: " << myWindow.getCamera().getFocalLength() << std::endl; 
    // 950, 950 = CORRECT



    // cam2
    // ====
    cv::viz::Camera myCam2(475.0, 475.0, 240.0, 320.0, cv::Size(480, 640));
    std::cout << "cam2: " << myCam2.getFocalLength() << std::endl; // 475, 475 = CORRECT

    myWindow.setCamera(myCam2);
    std::cout << "cam2 ACTUAL: " << myWindow.getCamera().getFocalLength() << std::endl; 
    // 597.128, 597.128 = INCORRECT.  Should be 475, 475!
}
edit retag flag offensive close merge delete