0

I am trying to switch to Linux with my OpenCV projects (using Ubuntu 14.04LTS, Eclipse CDT Indigo, OpenCV 2.4.9). I try to run some of my applications on Linux that worked on Windows, but I faced one weird issue.

I provide you with SIMPLIFIED code (removed some parts for clarity).

#include <iostream>
#include "opencv2/opencv.hpp"
#include "PointGrayCap.h"
#include "CameraCalibrator.h"

#define CALIB_FRAMES 5

using namespace std;
using namespace cv;

int main() {

VideoCapture cam(1);
CameraCalibrator* calib = new CameraCalibrator(Size(9, 6), 0, true);
Mat image, grayFrame, cornerFrame;
bool stop = false; int counter = 0;
bool calibDone = false;

while (!stop) {
    if (!cam.read(image)) {
        break;
    }
    imshow("Color", image);
    cvtColor(image, grayFrame, CV_BGR2GRAY);

    calib->calibrate(grayFrame.size()); // <<<<<<< issue is here with this parameter.

    //calibrate function is defined as:
    /*
    double calibrate(Size &imageSize)
    {
    //Output rotations and translations
    vector<Mat> rotVecs, transVecs;
    // start calibration
    return calibrateCamera(objectPoints, // the 3D points
                           imagePoints, // the image points
                           imageSize, // image size
                           cameraMatrix, // output camera matrix
                           distCoeffs, // output distortion matrix
                           rotVecs, // Rs
                           transVecs, // Ts
                           flag); // set options
    }
    */
    //

    cout << "Calibration done." << endl;
    calib->outputCameraMatrix();

    if (waitKey(10) == 27) {stop = true;}
}

return 0;
}

Here, I should pass the size of

grayFrame 

image to calibrate() function and the parameter in function is declared as

Size &imageSize

You can see definition in the code, commented section reveals definition of calibrate function (in real life it is separate *.h file).

Problem is that eclipse throws an error that there is no matching function with such parameters, that is of Size. It is weird, because in Windows it does work fine. BUT, but when I try to rewrite the call to the function like this:

Size mySize(grayFrame.cols, grayFrame.rows);
calib->calibrate(mySize);

Then it DOES work. Why is that? Moreover, I noticed, when looked through Mat properties, that size() property is treated as MSize instead of regular cv::Size. But I cannot understand why and that might be the reason.

Thanks for help.

rofl
  • 343
  • 3
  • 18

1 Answers1

1

I tried this on Linux and I get

error: invalid initialization of non-const reference of type 'cv::Size& {aka cv::Size_&}' from an rvalue of type 'cv::Size'

That pretty much says @Arelius link to the duplicate is correct.

To fix the issue change

double calibrate(Size &imageSize)

to

double calibrate(const Size &imageSize)
Bull
  • 11,771
  • 9
  • 42
  • 53
  • yep, now it is clear. That worked. Thanks a lot m8. I will vote up, when I have enough of rep. – rofl Jul 02 '14 at 09:30