目前的立体摄像机价格昂贵,并不是每个人都承担得起。
Current stereo cameras are expensive which makes them less accessible.
我决定自己制作一个版本,而不是付钱买一个。
I decided to make my own version, rather than paying for one.
我买了两个相对便宜的摄像头(每个4美元)。
I did this by purchasing two relatively very cheap cameras ($4 each).
我用热胶枪把相机固定在一个脊状的记号笔上。
I attached the cameras onto a ridged marker using a hot glue gun.
结果就是你从照片中所看到的样子,而且它对于我的预算是合理的。
The result is what you can see, and it works reasonable well for what I spent on it.
您需要一个牢靠的结构来安装摄像头,一旦摄像头被校准(解释如下),它们就不应该被移动或触摸,否则,您需要通过拍摄图像再次校准它们。
You need a solid structure to mount the cameras onto, and once cameras are calibrated (explained as follows) they should not be moved or even touched, otherwise, you need to calibrate them again by taking images.
因此,为了使事情更简单,要确保它们被很好地校准。
So to make things easier make sure they are fixed well.
这个代码带领您通过立体摄像机校准和图像处理,获得一个深度图。
This code takes you through the stereo camera calibration and image processing to get essentially a depth map.
在代码中有一些注释可能会有所帮助,我试图在代码及本文中包含其中的一些提示。
There are a few tips that may help along the line, I tried to include some of these in the code and here in this description.
请使用“SFStereo.m” 文件。
Use the “SFStereo.m” file
校准:如果你想进行校准,请将“calibrationFlag”设置为1,否则为0。
Calibration: If you want to start with the calibration, set the “calibrationFlag” to 1, otherwise set it to 0.
校准开始于从每个摄像头采集10张图像,总共20张图像。
The calibration starts with taking 10 images from each camera, a total of 20 images.
这些图像用于校准摄像头。
These images are used to calibrate the cameras.
您需要制作几个文件夹,以便将这些图像保存到其中。
You need to make a couple of folders for these images to be saved into.
把文件夹放在电脑的某个位置,然后把对应的地址放在这行代码中。
Make the folders somewhere on your PC and put the address in this line of code.
例如,我将它们保存在我的C驱动器上的两个单独的文件夹中,“cam1”用于1号相机,“cam2”用于2号相机。
As an example I saved them on my C drive in 2 separate folders, “cam1” for camera number 1, and “cam2” for camera number 2.
摄像机编号并不重要。
The camera numbering does not matter just now.
cam1Address = ‘C:\cam1’;
cam2Address = ‘C:\cam2’;
根据您的摄像头使用的驱动程序类型,您可能需要修改代码的这一部分:从而获取适配器和附加文件,以便从MATLAB支持包和附加组件中识别您的相机。
Depending on what sort of drivers your cameras are using you may have to change this part of the code: get the adaptors and additional files to recognize your cameras from MATLAB support packages and for add-ons.
在MATLAB主页选项卡的界面部分,单击附加组件>获取硬件支持包。
On the MATLAB Home tab, in the Environment section, click Add-Ons > Get Hardware Support Packages. Check this link for further info https://uk.mathworks.com/help/imaq/image-acquisition-support-packages-for-hardware-adaptors.html
adaptorInfo = imaqhwinfo;
adaptorInfo.InstalledAdaptors
devices = imaqhwinfo(‘winvideo’)
完成后,设置摄像头的分辨率。
Once this is done, set the resolution of the cameras.
您的摄像头可能支持与我使用的不同的分辨率。
Your cameras may support different resolution than the one I have used.
“deviceInfo1.SupportedFormats”告诉你摄像头所支持的分辨率类型。
This line of code “deviceInfo1.SupportedFormats” shows you the supported resolutions.
开始时使用最高分辨率(处理速度较慢,但更准确)。
Use the highest resolution for the beginning (it will be slower to process but more accurate).
deviceInfo = imaqhwinfo(‘winvideo’,1);
deviceInfo.SupportedFormats
deviceInfo = imaqhwinfo(‘winvideo’,2);
deviceInfo.SupportedFormats
用合适的摄像头拍摄第一张照片是非常重要的。
It is quite important to take the first picture with the right camera.
试着找出哪一个是右侧摄像头,那应该是1号摄像头。
Try to figure out which one is the right-side camera and that should be the camera number 1.
如果第一张照片是由左侧摄像头拍摄的,则将“swapCameras”设置为1。
If first picture is taken by the left side camera then set the “swapCameras” to 1.
每次连接、断开摄像头与电脑的连接时,您可能都要检查这个问题。
You may have to check this each time you connect and disconnect cameras from the PC.
请在我链接的MATLAB文档中查看关于这个问题的更多详细信息以及这将如何影响结果。
Please see more detail about this and how that will impact the results in the MATLAB documentation that I linked here.
这是来自MATLAB文档的一个摘录,“如果用于获取I1的摄像头位于用于获取I2的摄像头的右侧,那么MinDisparity必须为负数”。更多信息请访问https://uk.mathworks.com/help/vision/ref/disparity.html
This is an excerpt from the MATLAB documentation “If the camera used to take I1 was to the right of the camera used to take I2, then MinDisparity must be negative”. Further info on https://uk.mathworks.com/help/vision/ref/disparity.html
最后,根据设置的基线距离和物体到相机的距离,必须调整“disparityRange = [-161 2561]”
Finally, depending on the baseline distance of your setup, and the distance of the objects to the camera, you have to tweak the “disparityRange = [-161 2561]”
更多精彩文章请关注公众号: