aardio调用halcon采集摄像头
By
admin
at 2018-05-08 • 0人收藏 • 2404人看过
import win.ui; /*DSG{{*/ var winform = win.form(text="aardio form";right=969;bottom=646;parent=...) winform.add( button={cls="button";text="开启";left=31;top=549;right=193;bottom=635;z=1}; button2={cls="button";text="关闭";left=208;top=549;right=370;bottom=635;z=2}; picturebox={cls="picturebox";left=0;top=0;right=970;bottom=535;z=3} ) /*}}*/ import com; var HOperatorSetX = com.CreateObject("{6ebd90e2-d219-11d2-ade5-0000c00f4ef9}") import console console.open() var AcqHandle = HOperatorSetX.OpenFramegrabber( 'DirectShow', 1, 1, 0, 0, 0, 0, 'default', 8, 'rgb', -1, 'false', 'default', '', 0, -1 ); HOperatorSetX.GrabImageStart( AcqHandle , -1 ); var Image = HOperatorSetX.GrabImageAsync( AcqHandle , -1 ); //获取图像宽和高 var Width , Height = HOperatorSetX.GetImageSize( Image ); console.log(Width , Height) //调整画面大小和图像一致 var WindowHandle = HOperatorSetX.OpenWindow( 0 , 0 , Width , Height , winform.picturebox.hwnd , "transparent","" ); var videoShow = true; winform.button.oncommand = function(id,event){ while(win.delay(30)&&videoShow){ Image = HOperatorSetX.GrabImageAsync( AcqHandle , -1 ); //镜像图像 var ImageMirror = HOperatorSetX.MirrorImage( Image , "row" ); HOperatorSetX.DispObj( ImageMirror , WindowHandle ); //释放内存 HOperatorSetX.ClearObj( ImageMirror ); HOperatorSetX.ClearObj( Image ); } } winform.button2.oncommand = function(id,event){ videoShow = false; win.delay(500) HOperatorSetX.CloseFramegrabber( AcqHandle ); } winform.wndproc = function(hwnd,message,wParam,lParam){ select( message ) { case 0x10/*_WM_CLOSE*/{ if(videoShow){ videoShow = false; win.delay(500) HOperatorSetX.CloseFramegrabber( AcqHandle ); } } else{ } } //无返回值则继续调用默认回调函数 } winform.enableDpiScaling(); winform.show(); win.loopMessage(); return winform;
调用halcon的摄像头进行连续处理,记得要释放掉Obj内存,要不然内存会慢慢增加到溢出为止。。。。。。。。
注意:
经过多次测试,发现个问题,开启halcon摄像头必须按照一定的顺序初始化,要不然得出的效果就不是正常的。
开启摄像头显示必须按照下面的格式顺序:
var AcqHandle = HOperatorSetX.OpenFramegrabber( 'DirectShow', 1, 1, 0, 0, 0, 0, 'default', 8, 'rgb', -1, 'false', 'default', '', 0, -1 ); HOperatorSetX.GrabImageStart( AcqHandle , -1 ); var Image = HOperatorSetX.GrabImageAsync( AcqHandle , -1 ); //调整画面大小和图像一致 var WindowHandle = HOperatorSetX.OpenWindow( 0 , 0 , winform.picturebox.width, winform.picturebox.height , winform.picturebox.hwnd , "transparent","" );
先初始化摄像头,然后开启摄像头,然后获取一帧图像舍弃,再初始化界面中的图像控件。。。
其他的任何顺序都会得不到想要的效果。
1 个回复 | 最后更新于 2018-05-10
登录后方可回帖
如果调用多个摄像头,必须开线程: