Code Monkey home page Code Monkey logo

stereo_calibration's Introduction

stereo_calibration - StereoCamera Calibration using Python-OpenCV

Features

  • Prints -or- Returns dict object containing Camera Matrices and R, T, E and F
  • Takes Stereo Camera Images path as an input

Requirements

  • cv2
  • numpy

Example

  • Run using the command line
python camera_calibration.py /path/to/stereo/camera/images/
  • Run using Python
>>> from camera_calibration import StereoCalibration
>>> cal = StereoCalibration('/path/to/stereo/camera/images')
>>> cal.camera_model

Results

$python camera_calibration.py /path/to/stereo/camera/images/
('Intrinsic_mtx_1', array([[  4.14602008e+03,   0.00000000e+00,   7.59295870e+02],
       [  0.00000000e+00,   4.21635719e+03,   4.42260382e+02],
       [  0.00000000e+00,   0.00000000e+00,   1.00000000e+00]]))
('dist_1', array([[ -2.73378180e+00,   1.41433393e+02,  -1.36677475e-02,
          1.01134046e-01,  -5.17885999e+03]]))
('Intrinsic_mtx_2', array([[  4.16808926e+03,   0.00000000e+00,   7.33997545e+02],
       [  0.00000000e+00,   4.20937958e+03,   7.02753997e+01],
       [  0.00000000e+00,   0.00000000e+00,   1.00000000e+00]]))
('dist_2', array([[ -7.91010976e-01,   4.49627502e+01,  -1.55972074e-02,
         -3.95037927e-03,  -1.24662356e+03]]))
('R', array([[ 0.99869078,  0.00100433,  0.05114416],
       [-0.00564778,  0.99585969,  0.09072808],
       [-0.05084128, -0.09089815,  0.99456156]]))
('T', array([[-9.87912629],
       [ 0.24163047],
       [ 1.61658844]]))
('E', array([[ -3.15467525e-03,  -1.63185902e+00,   9.36464101e-02],
       [  1.11220449e+00,  -8.96370670e-01,   9.90807829e+00],
       [ -1.85519033e-01,  -9.83846631e+00,  -9.08672125e-01]]))
('F', array([[  3.44154284e-09,   1.75055259e-06,  -1.20037917e-03],
       [ -1.20144000e-06,   9.52136218e-07,  -4.38838342e-02],
       [  9.25481179e-04,   4.26384886e-02,   1.00000000e+00]]))

Output Parameters

Intrinsic_mtx_1 – output first camera matrix

dist_1 – output vector of distortion coefficients (k_1, k_2, p_1, p_2[, k_3[, k_4, k_5, k_6]]) of 4, 5, or 8 elements. The output vector length depends on the flags.

Intrinsic_mtx_2 – output second camera matrix

dist_2 – output lens distortion coefficients for the second camera

R – Output rotation matrix between the 1st and the 2nd camera coordinate systems.

T – Output translation vector between the coordinate systems of the cameras.

E – Output essential matrix.

F – Output fundamental matrix.

More reference on R, T, E and F can be found here

Notes

  • Assumption here is that given image path contains two folders of checkerboard images named LEFT and RIGHT. User can change these relative folder paths.
  • User may also change flags as per calibration output requirements.

References

stereo_calibration's People

Contributors

bvnayak avatar mananmadan avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

stereo_calibration's Issues

cv2.error: /io/opencv/modules/calib3d/src/calibration.cpp:3083: error: (-215) nimages > 0 && nimages == (int)imagePoints1.total() && (!imgPtMat2 || nimages == (int)imagePoints2.total()) in function collectCalibrationData

When I run the code, I get the following error:

OpenCV Error: Assertion failed (nimages > 0 && nimages == (int)imagePoints1.total() && (!imgPtMat2 || nimages == (int)imagePoints2.total())) in collectCalibrationData, file /io/opencv/modules/calib3d/src/calibration.cpp, line 3083 Traceback (most recent call last): File "test.py", line 129, in <module> cal_data = StereoCalibration(args.filepath) File "test.py", line 25, in __init__ self.read_images(self.cal_path) File "test.py", line 71, in read_images self.objpoints, self.imgpoints_l, img_shape, None, None) cv2.error: /io/opencv/modules/calib3d/src/calibration.cpp:3083: error: (-215) nimages > 0 && nimages == (int)imagePoints1.total() && (!imgPtMat2 || nimages == (int)imagePoints2.total()) in function collectCalibrationData

Is there a solution?

File "E:\new stereo\camera_calibration.py", line 75, in read_images rt, self.M1, self.d1, self.r1, self.t1 = cv2.calibrateCamera( cv2.error: OpenCV(4.5.5) D:\a\opencv-python\opencv-python\opencv\modules\calib3d\src\calibration.cpp:3339: error: (-2:Unspecified error) in function 'void __cdecl cv::collectCalibrationData(const class cv::_InputArray &,const class cv::_InputArray &,const class cv::_InputArray &,int,class cv::Mat &,class cv::Mat &,class cv::Mat *,class cv::Mat &)' > (expected: 'nimages == (int)imagePoints1.total()'), where > 'nimages' is 7 > must be equal to > '(int)imagePoints1.total()' is 0

when I run the code, I got this error. and I have 7 pairs of the images.

File "E:\new stereo\camera_calibration.py", line 75, in read_images
rt, self.M1, self.d1, self.r1, self.t1 = cv2.calibrateCamera(
cv2.error: OpenCV(4.5.5) D:\a\opencv-python\opencv-python\opencv\modules\calib3d\src\calibration.cpp:3339: error: (-2:Unspecified error) in function 'void __cdecl cv::collectCalibrationData(const class cv::_InputArray &,const class cv::_InputArray &,const class cv::_InputArray &,int,class cv::Mat &,class cv::Mat &,class cv::Mat *,class cv::Mat &)'
(expected: 'nimages == (int)imagePoints1.total()'), where
'nimages' is 7
must be equal to
'(int)imagePoints1.total()' is 0

filepath

I keep on getting error when I try to put the file path at the end and I don't know why it is getting that it says " file path must start with character-"

UnboundLocalError: local variable 'img_shape' referenced before assignment

Hi,

I am trying to run the code using Visual Studio Code in Anaconda. I am getting an error.

Traceback (most recent call last):
File "c:/Users/William/hello/_runscript.py", line 5, in
cal = StereoCalibration(r'C:\Users\William\hello\images')
File "c:\Users\William\hello\camera_calibration.py", line 25, in init
self.read_images(self.cal_path)
File "c:\Users\William\hello\camera_calibration.py", line 71, in read_images
self.objpoints, self.imgpoints_l, img_shape, None, None)
UnboundLocalError: local variable 'img_shape' referenced before assignment

Anyone know what might be the cause of this error?

Best regards

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.