Advertisement
Guest User

Untitled

a guest
Mar 21st, 2018
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.37 KB | None | 0 0
  1. //#include <stdio.h>
  2. //#include <sstream>
  3. //#include <iostream>
  4. #include <opencv2/opencv.hpp>
  5.  
  6. using namespace std;
  7. using namespace cv;
  8.  
  9. const float SquareDimention = 1.0f;
  10. const Size ChessboardSize = Size(7,7);
  11. const int NumOfImages = 14;
  12. const string Images[NumOfImages] = {
  13. "gals/1.jpg", "gals/2.jpg", "gals/3.jpg", "gals/4.jpg", "gals/5.jpg",
  14. "gals/6.jpg", "gals/7.jpg", "gals/8.jpg", "gals/9.jpg", "gals/10.jpg",
  15. "gals/11.jpg", "gals/12.jpg", "gals/13.jpg", "gals/14.jpg"
  16. };
  17.  
  18. int main(int argc, char** argv)
  19. {
  20. vector<Mat> openedImages;
  21.  
  22. for (int i=0; i<NumOfImages; i++)
  23. {
  24. openedImages.push_back(imread(Images[i], CV_LOAD_IMAGE_COLOR));
  25. }
  26.  
  27. vector<vector<Point2f> > imageSpacePoints;
  28.  
  29. for (vector<Mat>::iterator i = openedImages.begin(); i != openedImages.end(); i++)
  30. {
  31. vector<Point2f> spacePointBuffer;
  32.  
  33. bool found = findChessboardCorners(*i, ChessboardSize, spacePointBuffer,
  34. CV_CALIB_CB_ADAPTIVE_THRESH | CV_CALIB_CB_NORMALIZE_IMAGE);
  35.  
  36. if (found)
  37. {
  38. imageSpacePoints.push_back(spacePointBuffer);
  39. }
  40. }
  41.  
  42. vector<vector<Point3f> > worldSpacePoints(1);
  43. for (int i=0; i<ChessboardSize.height; i++)
  44. for (int j=0; j<ChessboardSize.width; j++)
  45. worldSpacePoints[0].push_back(Point3f(float(j*SquareDimention),
  46. float(i*SquareDimention), 0.0f));
  47.  
  48. worldSpacePoints.resize(imageSpacePoints.size(), worldSpacePoints[0]);
  49.  
  50. Mat cameraMatrix = Mat::eye(3, 3, CV_64F);
  51. Mat distanceCoefficients = Mat::zeros(8, 1, CV_64F);
  52. vector<Mat> rVectors, tVectors;
  53.  
  54. calibrateCamera(worldSpacePoints, imageSpacePoints, ChessboardSize, cameraMatrix,
  55. distanceCoefficients, rVectors, tVectors);
  56.  
  57. cout << "Camera Matrix: " << endl << cameraMatrix << endl;
  58. cout << "Cooef Matrix: " << endl << distanceCoefficients << endl;
  59.  
  60. /*
  61. // Just a helper
  62. int ctr = 0;
  63. for (vector<vector<Point2f> >::iterator i = imageSpacePoints.begin(); i != imageSpacePoints.end(); i++)
  64. {
  65. vector<Point2f> pointBuffer = *i;
  66. for (vector<Point2f>::iterator j = pointBuffer.begin(); j != pointBuffer.end(); j++)
  67. {
  68. cout << *j << endl;
  69. }
  70. ++ctr;
  71. cout << "--------------------[ " << ctr << " ]-----------------------" << endl;
  72. }
  73.  
  74. for (int i=0; i<rVectors.size(); i++)
  75. {
  76. cout << "RVect: " << rVectors[i] << endl;
  77. }
  78. */
  79.  
  80. return 0;
  81. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement