Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Camera parameters? #33

Open
biggzlar opened this issue Mar 18, 2019 · 11 comments
Open

Camera parameters? #33

biggzlar opened this issue Mar 18, 2019 · 11 comments
Assignees
Labels
enhancement New feature or request

Comments

@biggzlar
Copy link
Contributor

Any chance we could get the results of a camera calibration with the ingame 3rd-person camera. Specifically the camera matrix (focal lengths and optical center) would be of interest for some approaches seen in robotics.

@kwea123
Copy link
Contributor

kwea123 commented Mar 18, 2019

You can do it with the floor... it's a grid!
And by further supposing the camera is perfectly centered... you can get the intrinsics. That's what I did.

@biggzlar
Copy link
Contributor Author

biggzlar commented Mar 18, 2019

@kwea123 thanks for your reply and the tip! Won't it be a problem that the tiles seen in the texture of the floor are uneven, though?

@kwea123
Copy link
Contributor

kwea123 commented Mar 18, 2019

I labelled the corners (by finding the floor lines and computing the intersections) by myself, there is no problem.
a

@biggzlar
Copy link
Contributor Author

biggzlar commented Mar 18, 2019

Gotcha, now I get it! Thanks a lot!

@biggzlar
Copy link
Contributor Author

@kwea123 one more question. Have you been using opencv for the calibration or a custom implementation? Because it doesn't seem to work with less than 3x3 image points.

@kwea123
Copy link
Contributor

kwea123 commented Mar 18, 2019

I use opencv, and it worked with only 6 points. After that you need to guess a little about the parameters because 6 points are too few to get precise parameters.

Basically it's just cv2.calibrateCamera(objpoints, imgpoints, ... and replace the objpoints and imgpoints that you found.

@biggzlar
Copy link
Contributor Author

Alright, that's good to know. I get a weird error that I can't find any docs on and was wondering if the number of points was an issue (because it is if you were to try and detect e.g. (2,3) points with cv2.findChessboardCorners).

Feel free to ignore this though, since it goes past the original issue. Just for completeness' sake here is the code and error:

ret, mtx, dist, rvecs, tvecs = cv.calibrateCamera(objp.reshape(-1,1,3
     ...: ).astype(np.float32), imgp.reshape(-1,1,2).astype(np.float32), gray.
     ...: shape[::-1],None,None)
---------------------------------------------------------------------------
error                                     Traceback (most recent call last)
<ipython-input-147-30b0df05894d> in <module>
----> 1 ret, mtx, dist, rvecs, tvecs = cv.calibrateCamera(obj.reshape(-1,1,3).astype(np.float32), crns.reshape(-1,1,2).astype(np.float32), gray.shape[::-1],None,None)

error: OpenCV(4.0.0) /Users/travis/build/skvark/opencv-python/opencv/modules/calib3d/src/calibration.cpp:1475: 
error: (-211:One of arguments' values is out of range) The number 
of points in the view #0 is < 4 in function 'cvCalibrateCamera2Internal'

with

objp.reshape(-1, 1, 3).shape
(6, 1, 3)

imgp.reshape(-1, 1, 2).shape
(6, 1, 2)

Thank you, again.

@kwea123
Copy link
Contributor

kwea123 commented Mar 18, 2019

Try to use list and pay attention to the shapes. I use cv2.calibrateCamera([objpoints], [imgpoints],...) with objpoints with shape (6, 3) and imgpoints with shape (6, 1, 2).

By the way, you need to set flags=cv2.CALIB_FIX_ASPECT_RATIO+cv2.CALIB_FIX_PRINCIPLE_POINT to make it converge to good parameters. I tried many flags and these work best.

@biggzlar
Copy link
Contributor Author

biggzlar commented Mar 18, 2019

Awesome, thanks for the generous support. I'm sure I'll figure it out eventually.

Edit:
Got it!

@awjuliani
Copy link
Contributor

Hi @biggzlar

With the open source release this summer, we will make sure that this is possible natively from Unity. I am glad to hear though that @kwea123 has provided a solution which works in the mean time 😃

@awjuliani awjuliani added the enhancement New feature or request label Mar 18, 2019
@awjuliani awjuliani self-assigned this Mar 18, 2019
@biggzlar
Copy link
Contributor Author

Hey @awjuliani

Great to hear!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants