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

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

heydinge gravatar image

updated 2020-10-20 04:54:40 -0600

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!
}

There are similar threads on this topic that have not received any answer as yet. Viz3d::setCamera crashes the second time it is called. It appears not to be possible to work on the parameters of the virtual camera at run time. Is there anyone that have found a workaround for this?

Thanks

cv::viz::Viz3d myWindow("myWindow");
myWindow.setCamera(myWindow.getCamera());

Thank you very much.

edit retag flag offensive close merge delete

Comments

Having the same problem. Any ideas?

kopetri gravatar imagekopetri ( 2017-04-18 02:15:51 -0600 )edit

@kopetri , please do not post answers here, if you have acomment or question, thank you.

berak gravatar imageberak ( 2017-04-18 02:24:53 -0600 )edit

I have the same problem! Any ideas?

fab_cut gravatar imagefab_cut ( 2018-05-29 07:21:33 -0600 )edit
berak gravatar imageberak ( 2018-12-13 02:11:43 -0600 )edit
1

3 question merged into one

sturkmen gravatar imagesturkmen ( 2020-10-20 04:56:07 -0600 )edit