Stereo_Camera Calibration error

OpenCV, Python and other image processing questions
vram
Posts: 4
Joined: Mon Jul 27, 2020 1:52 pm

Re: Stereo_Camera Calibration error

Post by vram »

Hello Realizator,

Great. Thanks for the confirmation and sharing the relevant thread.

BTW, I have captured my own checkerboard images using V2 camera and could successfully calibrate using your calibration code with the fix.

stereomaton
Posts: 215
Joined: Tue May 21, 2019 12:33 pm
Location: France

Re: Stereo_Camera Calibration error

Post by stereomaton »

On the PC I have opencv4 which might have fixed the "close to edges" bug compared to the version in the stereopi.
Stereophotographer and hacker
Despite my quite active participation in the forum, I am not in the StereoPi team
StereoPi (v1) Standard Edition + CM3Lite module + a few cameras

User avatar
Realizator
Site Admin
Posts: 900
Joined: Tue Apr 16, 2019 9:23 am
Contact:

Re: Stereo_Camera Calibration error

Post by Realizator »

Stereomaton, for me this issue still exists in OpenCV 4. Here is my version on a desktop computer:

Code: Select all

>>> import cv2
>>> cv2.__version__
'4.1.2'
>>> 
Eugene a.k.a. Realizator

stereomaton
Posts: 215
Joined: Tue May 21, 2019 12:33 pm
Location: France

Re: Stereo_Camera Calibration error

Post by stereomaton »

Mine is 4.4.0
Cloning the repo and executing 3_* & 4_* worked with it without error message before the correction as I said before.
Stereophotographer and hacker
Despite my quite active participation in the forum, I am not in the StereoPi team
StereoPi (v1) Standard Edition + CM3Lite module + a few cameras

User avatar
Realizator
Site Admin
Posts: 900
Joined: Tue Apr 16, 2019 9:23 am
Contact:

Re: Stereo_Camera Calibration error

Post by Realizator »

Stereomaton, the key issue here is that 4.1.0 was the only stable release can be installed on the Raspberry Pi, all other releases are buggy. I will take a look at the newer stablwe releases.
Eugene a.k.a. Realizator

stereomaton
Posts: 215
Joined: Tue May 21, 2019 12:33 pm
Location: France

Re: Stereo_Camera Calibration error

Post by stereomaton »

I just noted that I did not have problems executing it on my station, on which I tested because I did not have access to my stereopi at this time and a part of the question was answerable that way.
You corrected it in the context, so there is no absolute need to upgrade the library. Furthermore it may use mechanisms (e.g. gpgpu) on my station where the bug does not occur but still would on the pi, although in this case it is quite unlikely.
Of course if you judge that you can have a more up-to-date version, it is often better, but it is up to you.
Stereophotographer and hacker
Despite my quite active participation in the forum, I am not in the StereoPi team
StereoPi (v1) Standard Edition + CM3Lite module + a few cameras

latif
Posts: 6
Joined: Thu Oct 08, 2020 3:48 pm

Re: Stereo_Camera Calibration error

Post by latif »

Hello
I am new to camera calibration. I was using this code for stereo calibration to calibrate a single (left) camera only. I have comment out all the code lines for stereo and right camera calibration. It works to recognize corners of chessboard but it gives this error when proceed to left camera calibration. I am applying this code for one camera only at this stage because I have to use it further in my project to calibrate 2 cameras. I wonder if this code can work for single camera or not? can anyone guide me please. if it cannot be used for single camera then I will go directly for 2 cameras calibration.
thanks in advance
Attachments
error picture
error picture
error.JPG (53.86 KiB) Viewed 16833 times

stereomaton
Posts: 215
Joined: Tue May 21, 2019 12:33 pm
Location: France

Re: Stereo_Camera Calibration error

Post by stereomaton »

latif wrote:
Thu Oct 08, 2020 3:58 pm
I wonder if this code can work for single camera or not?
If I read it right, the original code first calibrate the two cameras independently (camera matrix + distortion) and then calibrates the system of two cameras (relative translation and rotation). Thus you can use the calibrated data for one side only if you want even if you do the whole procedure. You can probably calibrate only one camera by commenting the right parts, but I would advise to read the OpenCV documentation so that you understand a bit more what is done.

I did not played seriously with the calibration part, but several problems reported on the forum were due to bad input data. In particular, you can set drawCorners to True to check if all detected chessboards are at the right position and in the same orientation in each image. If I am right, the chessboard also needs to be tilted (one side closer to the camera, with different angles) so that the perspective is detectable by the algorithm.
Stereophotographer and hacker
Despite my quite active participation in the forum, I am not in the StereoPi team
StereoPi (v1) Standard Edition + CM3Lite module + a few cameras

latif
Posts: 6
Joined: Thu Oct 08, 2020 3:48 pm

Re: Stereo_Camera Calibration error

Post by latif »

Thankyou Stereomaton,

I have successfully done the stereo calibration. I have set two same cameras 14 cm apart and prepare a stereo setup. I have followed this code up to 4_fisheye_calibration.py. I have calibrated and obtain RMS of 1.5. Now I just want to find the 3D world coordinates of any specific point in image. I am using projection matrices obtain from this calibration and use them in cv2.triangulatepoints().it gives me a 4x1 matrix. In this matrix the first three values are to be divided by fourth value in matrix. and this will give me world coordinates of the specific points according to my knowledge as far as I have gone through this cv2.triangulatepoints() function. but the problem is that it gives me X & Y coordinates almost correct but there is a huge error in Z coordinate(distance from camera to object in real world). I don't know if I am in right direction or not. I just want to find 3D world coordinates from given pixel coordinates in the image. can anyone please guide me? I don't want to go in 3D reconstruction and disparity map etc. I just need 3D world coordinates corresponding to pixel coordinate of any point in a given image. please guide me what I am doing wrong.

P.S: I have taken input images for calibration with different distances from camera and at different tilts and angles.. and also reduced the RMS error to 0.7. but still not succeeded in getting accurate X,Y, and Z location in world coordinates. I am getting a difference of 10 to 15 cm for X & Y coordinates.. but for Z coordinate the difference is meters i.e. for original distance of 3 meters it is only showing 1.5 meters in result.

stereomaton
Posts: 215
Joined: Tue May 21, 2019 12:33 pm
Location: France

Re: Stereo_Camera Calibration error

Post by stereomaton »

Your new question might lead to a long discussion not related to the original topic, you should probably open a new post.
Stereophotographer and hacker
Despite my quite active participation in the forum, I am not in the StereoPi team
StereoPi (v1) Standard Edition + CM3Lite module + a few cameras

User avatar
Realizator
Site Admin
Posts: 900
Joined: Tue Apr 16, 2019 9:23 am
Contact:

Re: Stereo_Camera Calibration error

Post by Realizator »

Hi Latif and Stereomaton,
Latif, the real world distance (and related "pointcloud" term) has been discussed here.
To say briefly, your poor Z coordinates are caused by absence of /16.0.
Eugene a.k.a. Realizator

latif
Posts: 6
Joined: Thu Oct 08, 2020 3:48 pm

Re: Stereo_Camera Calibration error

Post by latif »

Thankyou stereomaton and realizator for your quick response.

Realizator: I have seen the zip file you have shared in that thread which you mentioned here.. and I have created the point cloud but I have not get what exactly I want. I just need exact 3D coordinates of one specific point in image using camera projection matrices (cv2.triangulatepoints()). If you say I will start new thread for my query and write everything in detail. that might be helpful for you to understand my situation.

User avatar
Realizator
Site Admin
Posts: 900
Joined: Tue Apr 16, 2019 9:23 am
Contact:

Re: Stereo_Camera Calibration error

Post by Realizator »

Latif, yes, it's a good idea to start a new topic!
Eugene a.k.a. Realizator

Post Reply