Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

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

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!

}

click to hide/show revision 2
No.2 Revision

updated 2015-07-10 14:40:16 -0600

berak gravatar image

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

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>

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

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

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

}

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

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!
}
click to hide/show revision 4
retagged

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

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

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

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 question. Viz3d::setCamera crashes the second time it is called. It appears not to be possible to work on the paramenters of the virtual camera at run time. Is there anyone that have found a workaround for this?

Thanks

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

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 question. answer as yet. Viz3d::setCamera crashes the second time it is called. It appears not to be possible to work on the paramenters of the virtual camera at run time. Is there anyone that have found a workaround for this?

Thanks Thanks

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

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 paramenters parameters of the virtual camera at run time. Is there anyone that have found a workaround for this?

Thanks

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

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.