Laex / Delphi-OpenCV

Project Delphi-OpenCV. Translation of OpenCV library header files in Delphi
499 stars 225 forks source link

cameracalibrate error message #4

Closed CFTechno closed 11 years ago

CFTechno commented 11 years ago

First of all a big thank you for this project!

I tried the camera calibrate project. The call cvCalibrateCamera2 will generate a "InvalidOp : Invlaid floating point operation"

replaceing the CV_CALIB_USE_INTRINSIC_GUESS flag with 0 wll generate the error "for non-planar calibration rigs the initial intrinisc matrix must be specified"

Laex commented 11 years ago

According to the documentation (http://opencv.willowgarage.com/documentation/camera_calibration_and_3d_reconstruction.html#calibratecamera2) using CV_CALIB_USE_INTRINSIC_GUESS - cameraMatrix must contain valid initial values ​​of Fx, Fy, CX, CY, from which cvCalibrateCamera2 picks optimized values​​. Otherwise (CX, CY) are the coordinates of the image center (ImageSize), and the focal length is calculated as the least squares some modes. If the internal parameters are known, there is no need to use this function only if the verification parameters. Therefore, the program uses fixed values ​​cameraMatrix (defined in intrinsic_matrix) (https://github.com/Laex/Delphi-OpenCV/blob/master/samples/MultiDemo/CameraCalibrate/CameraCalibrate.dpr#L258)

These values ​​are chosen for the image obtained with my camera. In your case, these coefficients must be chosen samotoyatelno.

Error "InvalidOp: Invlaid floating point operation" appears when the preliminary stage (first cycle) is not able to obtain all the parameters to calibrate the camera.

Of course, the example requires further development to inform the user about found (or not found) parameters

CFTechno commented 11 years ago

Thank you for the reply. I found the following to get it working

1- Removed a bug in line 150

      step := successes * board_n;
      i := step;
      j := 0;
      while i < board_n do   <<<<<<<<<<<<<<<<< error
      begin

changed it into :

     while J < board_n do   

2- removed the intrinsic_matrix values set by the lines

pSingle(CV_MAT_ELEM(intrinsic_matrix^, SizeOf(Single), 0, 0))^ := 520.0;
pSingle(CV_MAT_ELEM(intrinsic_matrix^, SizeOf(Single), 1, 1))^ := 520.0;
pSingle(CV_MAT_ELEM(intrinsic_matrix^, SizeOf(Single), 2, 2))^ := 1;
pSingle(CV_MAT_ELEM(intrinsic_matrix^, SizeOf(Single), 0, 2))^ := 70.0;
pSingle(CV_MAT_ELEM(intrinsic_matrix^, SizeOf(Single), 1, 2))^ := 70.0;

and replaced them by

 pSingle(CV_MAT_ELEM(intrinsic_matrix^, sizeof(single), 0, 0))^ := 1.0;
 pSingle(CV_MAT_ELEM(intrinsic_matrix^, sizeof(single), 1, 1))^ := 1.0;

Before I did the above I first used the original

 pSingle(CV_MAT_ELEM(intrinsic_matrix^, CV_32FC1, 0, 0))^ := 1;
 pSingle(CV_MAT_ELEM(intrinsic_matrix^, CV_32FC1, 1, 1))^ := 1;

but that would generate the "floating point divide by zero. Seems that using cv_32FC1 will not fill the 1,1 value???

3- Changed the flag CV_CALIB_USE_INTRINSIC_GUESS into CV_CALIB_FIX_ASPECT_RATIO ,

These changes will make it working. Tested it with a sony eye3 cam

Hope this helps for this project which I really like.

CFTechno commented 11 years ago

I also propose the following changes to the demo

change the check on the sample counter (around line 128)

  if ((frame div board_dt) = 0) then
  begin
    Writeln('Successes: ', successes);

into

  if ((frame mod board_dt) = 0) then
  begin
    Writeln('Successes: ', successes);

and around line 198

    Halt;
  end;
  image := cvQueryFrame(capture); // Ïîëó÷àåì cëåäóþùåå èçîáðàæåíèå
end; // ÊÎÍÅÖ ÊÎËËÅÊÖÈÎÍÈÐÎÂÀÍÈÅ ÖÈÊËÎÌ WHILE.

adding the increase of the frame (sample) counter

    Halt;
  end;
  image := cvQueryFrame(capture); // Ïîëó÷àåì cëåäóþùåå èçîáðàæåíèå
  inc(frame);
end; // ÊÎÍÅÖ ÊÎËËÅÊÖÈÎÍÈÐÎÂÀÍÈÅ ÖÈÊËÎÌ WHILE.
Laex commented 11 years ago

Error using cv_32FC1 associated with an inaccurate translation definitions CV_MAT_ELEM, CV_ELEM_SIZE and CV_MAT_ELEM_PTR_FAST. cv_32FC1 means cv_32F - single and one channel. If it is used cv_32FC2 - a single and two channels. In this case, CV_MAT_ELEM likely will not work correctly. The exact translation of definitions will be doing in the near future.

Thanks for the bugs. Fixed.

CFTechno commented 11 years ago

Thanks!

CFTechno commented 11 years ago

Laentir,

I found this guy doing also opencv but for delphi 7.

http://www.developpez.net/forums/d1325349/environnements-developpement/delphi/contribuez/opencv-delphi/

I've asked him if he could contact you to see if you two could merge work. That could help this project even more forward.

I will try to implement his cvPositObject definition and also convert the opencv cpp posit demo. If I can get it to work will let you know.

Kind regards,

Frans van Daalen

2013/5/12 Laex notifications@github.com

Error using cv_32FC1 associated with an inaccurate translation definitions CV_MAT_ELEM, CV_ELEM_SIZE and CV_MAT_ELEM_PTR_FAST. cv_32FC1 means cv_32F - single and one channel. If it is used cv_32FC2 - a single and two channels. In this case, CV_MAT_ELEM likely will not work correctly. The exact translation of definitions will be doing in the near future.

Thanks for the bugs. Fixed.

— Reply to this email directly or view it on GitHubhttps://github.com/Laex/Delphi-OpenCV/issues/4#issuecomment-17768862 .

Laex commented 11 years ago

I know about this project. Most of the examples in it is taken from my project. However, I use XE3 and some of its features that are not found in Delphi 7. Of interest is the source code OpenCV_Class.dll, which is a wrapper around the C++ classes in OpenCV. Most likely there is still some project in C++ that compiles to OpenCV_Class.dll. However, the source code I have found. It is very interesting to take a look. I tried to translate the C++ classes for Object Pascal (on GiHub have pas files with partial translation), but this is tantamount to rewriting the whole of the library OpenCV (C++). I am currently working on writing such a wrapper classes OpenCV. There are examples of such writing wrappers for C++ Builder, but OpenCV is not fully compatible with it, and use patches - not the best idea.

However, I am glad to any cooperation and assistance in the project. This includes examples of using the functions of the C-library OpenCV.