资源预览内容
第1页 / 共15页
第2页 / 共15页
第3页 / 共15页
第4页 / 共15页
第5页 / 共15页
第6页 / 共15页
第7页 / 共15页
第8页 / 共15页
第9页 / 共15页
第10页 / 共15页
亲,该文档总共15页,到这儿已超出免费预览范围,如果喜欢就下载吧!
资源描述
DIY 基于摄像头的激光测距仪作者: Rockets 文章来源: www.RoboticFan.com 更新时间:2008 年 05 月 11 日 打印此文 浏览数: 20296 软件我通过两个方式编写了这个软件,一个是 vc+,一个是 VB。你能发现 VB 版本的软件会比 VC的软件更容易一些,但是各有取舍。VC+版本能够自由的加入其他软件中?VB 版本需要第三方软件支持(在 Visual Studio 中)Visual Basicvb_laser_ranger.zip 这里可以下载到我的 VB 版本软件。要使用上面的程序,你必须要安装 VideoOCX ActiveX 控件主程序如下: Private Sub exit_Click() only if running. If (Timer1.Enabled) ThenTimer1.Enabled = False Stop TimerVideoOCX.StopVideoOCX.CloseEnd IfEndEnd SubPrivate Sub Start_Click() Init VideoOCX Control, allocate memory and start grabbingIf (Not Timer1.Enabled) ThenStart.Caption = Stop Disable internal error messages in VideoOCXVideoOCX.SetErrorMessages False Init controlIf (Not VideoOCX.Init) Then Init failed. Display error message and end subMsgBox VideoOCX.GetLastErrorString, vbOKOnly, VideoOCX ErrorEnd Else Allocate memory for global image handlecapture_image = VideoOCX.GetColorImageHandle result_image = VideoOCX_Processed.GetColorImageHandleTimer1.Enabled = True Start capture timer Start Capture modeIf (Not VideoOCX.Start) Then Start failed. Display error message and end subMsgBox VideoOCX.GetLastErrorString, vbOKOnly, VideoOCX ErrorEndEnd IfEnd IfElseStart.Caption = StartTimer1.Enabled = False Stop TimerVideoOCX.StopVideoOCX.CloseEnd IfEnd SubPrivate Sub Timer1_Timer() Timer for capturing - handles videoOCXToolsDim matrix As VariantDim height, width As IntegerDim r, c As IntegerDim max_r, max_c As IntegerDim max_red As IntegerDim gain, offset As VariantDim h_cm As VariantDim range As IntegerDim pixels_from_center As Integer Calibrated parameter for pixel to distance conversiongain = 0.0024259348offset = -0.056514344h_cm = 5.842max_red = 0 Capture an imageIf (VideoOCX.Capture(capture_image) Then VideoOCX.Show capture_image Matrix transformation initialization matrix = VideoOCX.GetMatrix(capture_image)height = VideoOCX.GetHeightwidth = VideoOCX.GetWidth Image processing code The laser dot should not be seen above the middle row (with a little pad)For r = height / 2 - 20 To height - 1 Our physical setup is roughly calibrated to make the laser dot in the middle columns.dont bother lookng too far awayFor c = width / 2 - 25 To width / 2 + 24 Look for the largest red pixel value in the scene (red laser)If (matrix(c, r, 2) max_red) Thenmax_red = matrix(c, r, 2)max_r = rmax_c = cEnd IfNext cNext r Calculate the distance for the laser dot from middle of framepixels_from_center = max_r - 120 Calculate range in cm based on calibrated parametersrange = h_cm / Tan(pixels_from_center * gain + offset) Print laser dot position row and column to screenrow_val.Caption = max_rcol_val.Caption = max_c Print range to laser illuminated object to screenrange_val.Caption = range Draw a red vertical line to intersect targetFor r = 0 To height - 1matrix(max_c, r, 2) = 255Next r Draw a red horizontal line to intersect targetFor c = 0 To width - 1matrix(c, max_r, 2) = 255Next cVideoOCX.ReleaseMatrixToImageHandle (capture_image) End IfVideoOCX.Show capture_imageEnd Sub截屏如下: 首页 上一页 1 2 3 4 5 6 下一页 尾页 跳转到 5 页 转载声明:凡文章出处为 www.RoboticFan.com 的,系本站的原创文章。其它媒体在注明出处为 RoboticFan.com 并给出原始链接后可以自由转载,否则将视为侵权 !上一篇: Wall E 真机演示 下一篇: ASIMO 上班咯!游客10-01-12 分数: 3第 1 楼需要一个可以自动聚焦的摄像头精彩一针见血观点独到说的很对你说的有道理乱七八糟说什么你说的没道理简直是胡说八道游客09-03-10 分数: 3第 2 楼这里用了激光总感到有点不足,激光有一个可见的光点会让人感到不舒服。既然用了透镜成像的原理,何不用二个摄像头来完成这项工作。设想是:物体经过二个透镜会产生不同的图像偏移,偏移量的大小代表了物体的远近。要找出相同图像的偏移量,我想应该有很多办法。当然,物体有远有近,产生的偏移量会不同,图像处理如何简单?我考虑可以加一个红外光,也找最亮的区域进行图像处理,越近越亮。当然,说说容易做做难,这只是我一个想法而已!精彩一针见血观点独到说的很对你说的有道理乱七八糟说什么你说的没道理简直是胡说八道12312308-10-22 分数: 1第 3 楼你 up 物?精彩一针见血观点独到说的很对你说的有道理乱七八糟说什么你说的没道理简直是胡说八道游客08-08-10 分数: 3第 4 楼看不懂.精彩一针见血观点独到说的很对你说的有道理乱七八糟说什么你说的没道理简直是胡说八道08-05-20 分数: 3第 5 楼最后部分是如何 将点改为线进行测距?博创的未来之星机器人上貌似也没找到呢精彩一针见血观点独到说的很对你说的有道理乱七八糟说什么你说的没道理简直是胡说八道08-05-19 分数: 5第 6 楼good精彩一针见血观点独到说的很对你说的有道理乱七八糟说什么你说的没道理简直是胡说八道08-05-14 分数: 3第 7 楼我完全是个外行,提个愚蠢的问题:碰到镜子有没有影响?精彩一针见血观点独到说的很对你说的有道理乱七八糟说什么你说的没道理简直是胡说八道08-05-12 分数: 3第 8 楼呵呵,最后这部分将点改为线进行测距的工作,博创的未来之星机器人上已经有这个实验教程了。
收藏 下载该资源
网站客服QQ:2055934822
金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号