Ask Your Question

lc7229469's profile - activity

2015-12-22 03:37:23 -0500 asked a question Unknow exception when using fisheye::calibrate function

hei, guys. I am now working for a fisheye camera calibration and i have stuck for a long time. When my code run to fisheye::calibrate function, there aways has a "unhandled excption". here is my code:

#include <string>                                                                                   
#include <opencv2/opencv.hpp>                                                                       

using namespace cv;
using namespace std;

int main(int argc, char** argv) {
VideoCapture camera(1);
if (!camera.isOpened()) {
    cout << "Failed to open camera." << std::endl;
    return -1;

const char* window_name = "output";

Mat frame;
Size boardSize;
boardSize.width = 9;
boardSize.height = 6;

int remaining_frames = 5;
Matx33d K;
Vec4d D;
Mat identity = Mat::eye(3, 3, CV_64F);

vector<vector<Point2d> > img_points;
vector<vector<Point3d> > obj_points;
vector<Point3d> obj_temp;

int width = 9;
int height = 6;
int sq_sz = 30;

for (int i = 0; i < width; i++) {
    for (int j = 0; j < height; j++) {
        obj_temp.push_back(Point3d(double(j * sq_sz), double(i * sq_sz), 0));
for (int i = 0; i < remaining_frames; i++)

while (1) {
    if (! {
        cout << "Failed to read frame" << std::endl;

    if (remaining_frames > 0) {
        vector<Point2f> corners;
        bool found = findChessboardCorners(frame, boardSize, corners,
        drawChessboardCorners(frame, boardSize, corners, found);
        if (found && waitKey(30)==32)  {
            vector<Point2d> img_temp;
            for (int i = 0; i < width*height; i++)
                Point2d temp = corners[i];
            cout << remaining_frames << " frames to calibration." << endl;

            if (remaining_frames == 0) {
                cout << "Computing distortion" << endl;

                int flags = 0;
                flags |= cv::fisheye::CALIB_RECOMPUTE_EXTRINSIC;
                flags |= cv::fisheye::CALIB_CHECK_COND;
                flags |= cv::fisheye::CALIB_FIX_SKEW;
                // here is someting wrong
                fisheye::calibrate(obj_points, img_points, Size(640, 480), K, D,
                    noArray(), noArray(), flags, TermCriteria(3, 20, 1e-6));
                cout << "Finished computing distortion" << endl;

        imshow(window_name, frame);
    else {
        Mat output;
        fisheye::undistortImage(frame, output, K, D, identity);
        imshow(window_name, output);

    //if (waitKey(30) > 0) {
    //  break;

return 0;

i have tried many ways to solve this problem, include change the different version of opencv, install different version of Visual Studio, tried many data types and flags used in fisheye::calibration function. all these ways are failed. is there any one can help me? Thank you for advance!

2015-03-12 21:45:19 -0500 commented question There is something wrong when I read 2+ cameras.

Thank you for you suggestion! I will try to use the C++ code. I installed my VS2010 with Chinese language package, so the message box has some Chinese characters. I will try to reinstall my software.

2015-03-12 21:31:39 -0500 answered a question Using multiple external cameras

Hello, I don't know how to solve this problem just because I have a same situation as you discribed. I read 5 USB cameras but only first two of CvCapture returned with other camerals return NULL. So, I try to read the camera dynamically. However, I am facing a new weird problem. You can see my problem at:

2015-03-12 10:07:48 -0500 asked a question There is something wrong when I read 2+ cameras.

I have a project recently that I need to read more than 2 cameras using OpenCV. But I am facing a weird problem that I can't solve. When I execute my code step by step, it just OK, but when I run my project automatically, there is something wrong. Here is my code:

while (1)
//When I execute the following part step by step, it is just OK
//But when I run the project automatically, there is someting wrong
    for (i=0; i<3; i++){
        cap = cvCaptureFromCAM(i);
        cam = cvRetrieveFrame(cap);
        cvCopy(cam, ImageBuffer[i]);
    cvGetCols(pairs, &part, 0, 640);                    
    cvCopy(ImageBuffer[0], &part);
    cvGetCols(pairs, &part, 640, 640*2);
    cvCopy(ImageBuffer[1], &part);
    cvGetCols(pairs, &part, 640*2, 640*3);
    cvCopy(ImageBuffer[2], &part);
    cvShowImage("Pairs", pairs);


When I run the project, the error is like that: image description

So, what is wrong with my code? Can anyone could solve the problem? Thanks In Advance!