Stereo Rectification Issue

1.Which seller did you purchase the product(s) from?
Amazon
2.The Model number of the product(s) you have purchased?
SKU B016601
3.Which Platform are you using the product(s) on?
Raspberry Pi 3B+
4.Which instruction are you following?
https://www.arducam.com/docs/cameras-for-raspberry-pi/multi-camera-adapter-board/stereo-camera-adapter-for-pi-zero/
5.Has your product ever worked properly?
Yes
6.What problems are you experiencing?
Hello Arducam team, I am having trouble calibrating with my stereo camera adapter, with my code being adapted from the code provided here: https://github.com/ArduCAM/RaspberryPi/tree/master/Multi_Camera_Adapter/Multi_Adapter_Board_2Channel_uc444

 

The cameras and the adapter work well, but I am unable to obtain good rectification results, which result in excessive rotation/skewing of the re-mapped images.

“StereoCameraCalibration” is used to calibrate the cameras (executed using these parameters: “./StereoCameraCalibration 20 640 480”), which generates a “camera.bin” file that should be transferred to the build directory of “StereoCameraCalibrationTest”, which then opens the file to extract the relevant undistortion and rectification matrices for remapping.

 

The zipped project is linked below:

https://drive.google.com/file/d/1ZUrLFSG-8FEH-ycYmz_MWZUjqwK0ln3-/view?usp=sharing

 

Ideally, I would like to see a working example demonstrating how to perform stereo matching using the uc444 module, but none are provided. I created my code by cross-referencing other codes provided by Arducam for stereo matching purposes, specifically from here: https://www.arducam.com/docs/cameras-for-raspberry-pi/synchronized-stereo-camera-hat/opencv-and-depth-map-on-arducam-stereo-camera-hat-tutorial/

 

Please advise.
7.What attempts at troubleshooting have you already made?

8.How would you like us to help you?

Additionally, here is the “main.cpp” of “StereoCameraCalibration” by itself hosted on Gist, so the calibration process can be visualized more easily. I have written it as verbosely as possible to make it easier to understand.

 

https://gist.github.com/Tannz0rz/6ead9f8ee555c06ef2991dd804a2bcb7

It is worth noting that “stereoCalibrate” yields an error of 14.3365, which is very high.

Perhaps I have identified the reason, when I capture the stereo images I get artifacts in my image. Please advise how to mend such errors. Board connections are good, the demo video stream works fine, but when I begin calibrating this happens:

Further experimentation has determined that the individual cameras (OV5642) are not the issue (I have multiple and have changed them); it seems to be a race condition of the uc444 multi camera adapter board itself. As you can see in the image in my previous post part of the right camera image has embedded itself within the left camera image.

I realize I failed to share the Gist of “StereoCamera.cpp”, so here it is as well: https://gist.github.com/Tannz0rz/3f32c4c12aafc6b5f0044bd8479e62b8

The issue has been wholly identified. Upon calling “findChessboardCorners” things break. I have tried cloning the data (deep copy) to separate matrices but the issue is still present.

 

The main.cpp demonstrating this is shown below:

https://gist.github.com/Tannz0rz/0c7cfd4996acb7663fc001b633236016

 

Without “findChessboardCorners”:

 

With “findChessboardCorners”:

It appears that introducing any substantial amount of computation induces errors in imaging, for example adding a simple for loop that spins for a significant amount of cycles:

for (int i = 0; i < 1000000; ++i);
At this point artifacts begin to accumulate in the image for unknown reasons; they occupy separate memory addresses yet interfere with one-another.

How can I reliably extract data from the uc444 to be used without this happening?