├── README.md ├── generationIntelligent.aardio ├── halcon2aardio.aardio └── halconVideoCapture.aardio /README.md: -------------------------------------------------------------------------------- 1 | # aardio-halcon 2 | 3 | halcon是世界知名的视觉处理软件, halcon13和之前的版本是支持com调用的, 这里提供halcon在aardio中的智能提示库的自动生成和使用的一些示例 4 | 5 | 这里的目录: 6 | 1, 智能提示库的自动生成源码 7 | 2, halcon代码自动转换到aardio代码 8 | 3, halcon在aardio中的一些使用示例 9 | 10 | 本文首发: https://chegnxu.xyz/search/halcon 11 | aardio编程软件官网: www.aardio.com 12 | -------------------------------------------------------------------------------- /generationIntelligent.aardio: -------------------------------------------------------------------------------- 1 | import win.ui; 2 | /*DSG{{*/ 3 | var winform = win.form(text="Halcon之COM组件函数自动生成器";right=1101;bottom=612;border="dialog frame") 4 | winform.add( 5 | Halconclassname={cls="edit";text="HOperatorSetX";left=684;top=562;right=942;bottom=613;align="center";autohscroll=false;autovscroll=false;bgcolor=0;color=65280;edge=1;font=LOGFONT(h=-32);z=4}; 6 | button={cls="button";text="开始生成";left=951;top=559;right=1098;bottom=613;font=LOGFONT(h=-24);z=3}; 7 | comEdit={cls="edit";text="{6ebd90e2-d219-11d2-ade5-0000c00f4ef9}";left=133;top=562;right=471;bottom=613;align="center";autohscroll=false;autovscroll=false;bgcolor=0;color=65280;edge=1;font=LOGFONT(h=-32);z=2}; 8 | funcEdit={cls="edit";left=0;top=0;right=1102;bottom=554;bgcolor=0;color=65280;font=LOGFONT(h=-14;name='微软雅黑');hscroll=1;multiline=1;readonly=1;vscroll=1;z=1}; 9 | static={cls="static";text="控件GUID:";left=4;top=553;right=129;bottom=613;center=1;font=LOGFONT(h=-24);transparent=1;z=5}; 10 | static2={cls="static";text="控件对象名:";left=541;top=553;right=682;bottom=613;center=1;font=LOGFONT(h=-24);transparent=1;z=6} 11 | ) 12 | /*}}*/ 13 | 14 | var loadFunc = function( comMsg ){ 15 | var path = io.exist("/"++winform.Halconclassname.text++".aardio") 16 | if(path){ 17 | io.remove("/"++winform.Halconclassname.text++".aardio"); 18 | } 19 | import com; 20 | //调用COM组件 21 | obj = com.CreateObject( comMsg ); 22 | //获取COM组件类型库信息 23 | var typeinfo = com.GetTypeInfo(obj) 24 | 25 | //准备存储获取到的类型库信息 26 | var funcTab = {}; 27 | //下面直接调用函数总数目不准确,因为有写com组件里有空函数 28 | //winform.funcEdit.log("共有函数: "++typeinfo.GetTypeAttr().Funcs ++ " 个!",'\r\n'); 29 | for(i=8;typeinfo.GetTypeAttr().Funcs;1){ 30 | table.push(funcTab,table.clone(typeinfo.GetFuncDesc(i) )); 31 | } 32 | //添加注释头部 33 | string.save("/"++winform.Halconclassname.text++".aardio","//"++winform.Halconclassname.text++"图像库"++'\r\n',true); 34 | string.save("/"++winform.Halconclassname.text++".aardio","namespace "++winform.Halconclassname.text++";"++'\r\n',true); 35 | string.save("/"++winform.Halconclassname.text++".aardio",'\r\n',true); 36 | string.save("/"++winform.Halconclassname.text++".aardio","/*intellisense("++winform.Halconclassname.text++")*/"++'\r\n',true); 37 | 38 | for(i=1;#funcTab;1){ 39 | var funcPara = "";//参数合成 40 | var headTab = ""; 41 | if(funcTab[i].Params != null){ 42 | //总共几个变量参数 43 | for(j=1;funcTab[i].Params;1){ 44 | var parametersTab = funcTab[i].parameters[j]; 45 | if( parametersTab != null ){ 46 | if(j==1){ 47 | if( string.indexOf(parametersTab.type,"&") ){ 48 | headTab = string.concat(headTab,parametersTab.name); 49 | }else { 50 | funcPara = string.concat(funcPara,parametersTab.name); 51 | } 52 | }else { 53 | if( string.indexOf(parametersTab.type,"&") ){ 54 | if(headTab != ""){ 55 | headTab = string.concat(headTab," , ",parametersTab.name); 56 | }else { 57 | headTab = string.concat(headTab,parametersTab.name); 58 | } 59 | }else { 60 | if(funcPara != ""){ 61 | funcPara = string.concat(funcPara," , ",parametersTab.name); 62 | }else { 63 | funcPara = string.concat(funcPara,parametersTab.name); 64 | } 65 | } 66 | 67 | } 68 | 69 | } 70 | 71 | } 72 | //输出 73 | if(headTab != ""){ 74 | var retdata = string.concat(funcTab[i].name," = @","var " ,headTab," = ",winform.Halconclassname.text,".",funcTab[i].name ,"( ",funcPara , " );",'\r\n'); 75 | //winform.funcEdit.log(retdata); 76 | string.save("/"++winform.Halconclassname.text++".aardio", retdata ,true); 77 | }else { 78 | var retdata = string.concat(funcTab[i].name," = @",winform.Halconclassname.text,".",funcTab[i].name ,"( ",funcPara , " );",'\r\n'); 79 | //winform.funcEdit.log(retdata); 80 | string.save("/"++winform.Halconclassname.text++".aardio", retdata ,true) 81 | } 82 | } 83 | } 84 | //添加注释尾部 85 | string.save("/"++winform.Halconclassname.text++".aardio","/*end intellisense*/",true); 86 | 87 | } 88 | 89 | 90 | winform.button.oncommand = function(id,event){ 91 | 92 | winform.funcEdit.clear(); 93 | loadFunc(winform.comEdit.text); 94 | winform.msgbox("生成完成!") 95 | 96 | } 97 | 98 | 99 | 100 | winform.show() 101 | win.loopMessage(); 102 | -------------------------------------------------------------------------------- /halcon2aardio.aardio: -------------------------------------------------------------------------------- 1 | import win.ui; 2 | import fsys.ini; 3 | import win.clip; 4 | /*DSG{{*/ 5 | mainForm = win.form(text="Halcon2AAR转换工具";right=959;bottom=505) 6 | mainForm.add( 7 | Halconclassname={cls="edit";text="HOperatorSetX";left=506;top=9;right=764;bottom=50;align="center";autohscroll=false;autovscroll=false;bgcolor=0;color=65280;dr=1;dt=1;edge=1;font=LOGFONT(h=-21);multiline=1;z=3}; 8 | ["aar代码"]={cls="richedit";left=0;top=331;right=960;bottom=506;db=1;dl=1;dr=1;edge=1;hscroll=1;multiline=1;vscroll=1;z=8}; 9 | button={cls="button";text="生成匹配文件";left=778;top=4;right=953;bottom=50;dr=1;dt=1;font=LOGFONT(h=-24);z=2}; 10 | button2={cls="button";text='\u2193\u2193\u2193Halcon代码转换到Aardio代码\u2193\u2193\u2193';left=0;top=249;right=960;bottom=292;db=1;dl=1;dr=1;font=LOGFONT(h=-20);z=6}; 11 | button3={cls="button";text='\u2193清空';left=146;top=62;right=263;bottom=94;z=11}; 12 | button4={cls="button";text='\u2193清空';left=144;top=295;right=261;bottom=327;z=12}; 13 | button5={cls="button";text='\u2193黏贴剪切板内文本';left=292;top=62;right=433;bottom=94;z=13}; 14 | button6={cls="button";text='\u2193复制文本到剪切板';left=286;top=295;right=427;bottom=327;z=14}; 15 | comEdit={cls="edit";text="{6ebd90e2-d219-11d2-ade5-0000c00f4ef9}";left=129;top=9;right=350;bottom=48;align="center";autohscroll=false;autovscroll=false;bgcolor=0;color=65280;dl=1;dt=1;edge=1;font=LOGFONT(h=-21);z=1}; 16 | ["halcon代码"]={cls="richedit";left=0;top=99;right=960;bottom=249;dl=1;dr=1;dt=1;edge=1;hscroll=1;multiline=1;vscroll=1;z=7}; 17 | static={cls="static";text="控件GUID:";left=0;top=0;right=125;bottom=60;center=1;dl=1;dt=1;font=LOGFONT(h=-24);transparent=1;z=4}; 18 | static2={cls="static";text="控件对象名:";left=363;top=0;right=504;bottom=60;center=1;dl=1;dr=1;dt=1;font=LOGFONT(h=-24);transparent=1;z=5}; 19 | static3={cls="static";text='Halcon代码\u2193';left=7;top=65;right=228;bottom=99;dl=1;dt=1;font=LOGFONT(h=-20);transparent=1;z=9}; 20 | static4={cls="static";text='Aardio代码\u2193';left=0;top=300;right=221;bottom=334;db=1;dl=1;font=LOGFONT(h=-20);transparent=1;z=10} 21 | ) 22 | /*}}*/ 23 | 24 | var path; 25 | 26 | var loadFunc = function( comMsg ){ 27 | path = io.exist("/"++mainForm.Halconclassname.text++".ini") 28 | if(path){ 29 | io.remove("/"++mainForm.Halconclassname.text++".ini"); 30 | } 31 | import com; 32 | //调用COM组件 33 | obj = com.CreateObject( comMsg ); 34 | //获取COM组件类型库信息 35 | var typeinfo = com.GetTypeInfo(obj) 36 | //准备存储获取到的类型库信息 37 | var funcTab = {}; 38 | //下面直接调用函数总数目不准确,因为有写com组件里有空函数 39 | //winform.funcEdit.log("共有函数: "++typeinfo.GetTypeAttr().Funcs ++ " 个!",'\r\n'); 40 | for(i=8;typeinfo.GetTypeAttr().Funcs;1){ 41 | table.push(funcTab,table.clone(typeinfo.GetFuncDesc(i) )); 42 | } 43 | //添加注释头部 44 | string.save("/"++mainForm.Halconclassname.text++".ini","["++mainForm.Halconclassname.text++"]"++'\r\n',true); 45 | for(i=1;#funcTab;1){ 46 | var funcPara = "";//参数合成 47 | var headTab = ""; 48 | if(funcTab[i].Params != null){ 49 | //console.dump(funcTab[i]); 50 | //总共几个变量参数 51 | for(j=1;funcTab[i].Params;1){ 52 | var parametersTab = (funcTab[i].parameters)[j]; 53 | if( parametersTab != null ){ 54 | //console.dump(parametersTab); 55 | if(j==1){ 56 | //funcPara = string.concat(funcPara,parametersTab._com_type," ",parametersTab.name); 57 | if( string.indexOf(parametersTab.type,"&") ){ 58 | headTab = string.concat(headTab,"1"); 59 | funcPara = string.concat(funcPara,"0"); 60 | }else { 61 | funcPara = string.concat(funcPara,"1"); 62 | } 63 | 64 | 65 | 66 | }else { 67 | //funcPara = string.concat(funcPara,',',parametersTab._com_type," ",parametersTab.name); 68 | if( string.indexOf(parametersTab.type,"&") ){ 69 | if(headTab != ""){ 70 | headTab = string.concat(headTab,",","1"); 71 | 72 | }else { 73 | headTab = string.concat(headTab,"1"); 74 | } 75 | 76 | if(funcPara != ""){ 77 | funcPara = string.concat(funcPara,",","0"); 78 | }else { 79 | funcPara = string.concat(funcPara,"0"); 80 | } 81 | 82 | 83 | }else { 84 | if(funcPara != ""){ 85 | funcPara = string.concat(funcPara,",","1"); 86 | }else { 87 | funcPara = string.concat(funcPara,"1"); 88 | } 89 | 90 | 91 | } 92 | 93 | } 94 | 95 | } 96 | 97 | } 98 | 99 | if(funcPara != ""){ 100 | string.save("/"++mainForm.Halconclassname.text++".ini",string.concat(funcTab[i].name ,"=",funcPara ,'\r\n') ,true); 101 | } 102 | 103 | } 104 | } 105 | 106 | } 107 | 108 | 109 | mainForm.button.oncommand = function(id,event){ 110 | loadFunc(mainForm.comEdit.text); 111 | mainForm.msgbox("生成完成!") 112 | 113 | } 114 | 115 | 116 | 117 | var halcon2AAR = function( str ){ 118 | var FuncList = fsys.ini(path) 119 | var ListFun = FuncList.getSection("HOperatorSetX"); 120 | 121 | var replaceStr = function(s){ 122 | 123 | var ret = string.split(s,","); 124 | var retStr; 125 | if(#ret>1){ 126 | for(i=1;#ret;1){ 127 | ret[i] = string.replace(ret[i],"@[","{"); 128 | ret[i] = string.replace(ret[i],"@]","}"); 129 | if(retStr == null){ 130 | retStr = string.concat(retStr,ret[i]); 131 | }else { 132 | retStr = string.concat(retStr,";",ret[i]); 133 | } 134 | } 135 | }else { 136 | var retss = string.replace(ret[1]," ",""); 137 | if(retss=="[]"){ 138 | return "{}"; 139 | }else { 140 | return s; 141 | } 142 | } 143 | return retStr; 144 | } 145 | 146 | 147 | 148 | //替换规则 149 | var replaceFun = function(strr){ 150 | strr = string.replace(strr,"@:=","="); 151 | 152 | for s in string.gmatch( strr, "%\[\]" ){ 153 | var ret = replaceStr(s); 154 | strr = string.replace(strr,"@"++s,ret); 155 | } 156 | 157 | strr = string.replace(strr,"()mean(%())","HOperatorSetX.TupleMean\2"); 158 | strr = string.replace(strr,"()rad(%())","math.rad\2"); 159 | strr = string.replace(strr,"()sin(%())","math.sin\2"); 160 | strr = string.replace(strr,"()cos(%())","math.cos\2"); 161 | strr = string.replace(strr,"()tan(%())","math.tan\2"); 162 | strr = string.replace(strr,"()asin(%())","math.asin\2"); 163 | strr = string.replace(strr,"()acos(%())","math.acos\2"); 164 | strr = string.replace(strr,"()atan(%())","math.atan\2"); 165 | strr = string.replace(strr,"()atan2(%())","math.atan2\2"); 166 | strr = string.replace(strr,"()sinh(%())","math.sinh\2"); 167 | strr = string.replace(strr,"()cosh(%())","math.cosh\2"); 168 | strr = string.replace(strr,"()tanh(%())","math.tanh\2"); 169 | strr = string.replace(strr,"()exp(%())","math.exp\2"); 170 | strr = string.replace(strr,"()log(%())","math.log\2"); 171 | strr = string.replace(strr,"()pow(%())","HOperatorSetX.TuplePow\2"); 172 | strr = string.replace(strr,"()subset(%())","HOperatorSetX.TupleSelect\2"); 173 | strr = string.replace(strr,"()firstn(%())","HOperatorSetX.TupleFirstN\2"); 174 | strr = string.replace(strr,"()lastn(%())","HOperatorSetX.TupleLastN\2"); 175 | strr = string.replace(strr,"()select_mask(%())","HOperatorSetX.TupleSelectMask\2"); 176 | strr = string.replace(strr,"()remove(%())","HOperatorSetX.TupleRemove\2"); 177 | strr = string.replace(strr,"()find(%())","HOperatorSetX.TupleFind\2"); 178 | strr = string.replace(strr,"()replace(%())","HOperatorSetX.TupleReplace\2"); 179 | strr = string.replace(strr,"()find_first(%())","HOperatorSetX.TupleFindFirst\2"); 180 | strr = string.replace(strr,"()find_last(%())","HOperatorSetX.TupleFindLast\2"); 181 | strr = string.replace(strr,"()uniq(%())","HOperatorSetX.TupleUniq\2"); 182 | strr = string.replace(strr,"()gen_tuple_const(%())","HOperatorSetX.TupleGenTupleConst\2"); 183 | strr = string.replace(strr,"()lsh(%())","HOperatorSetX.TupleLsh\2"); 184 | strr = string.replace(strr,"()rsh(%())","HOperatorSetX.TupleRsh\2"); 185 | strr = string.replace(strr,"()strchr(%())","HOperatorSetX.TupleStrchr\2"); 186 | strr = string.replace(strr,"()strrchr(%())","HOperatorSetX.TupleStrrchr\2"); 187 | strr = string.replace(strr,"()strstr(%())","HOperatorSetX.TupleStrstr\2"); 188 | strr = string.replace(strr,"()strrstr(%())","HOperatorSetX.TupleStrrstr\2"); 189 | strr = string.replace(strr,"()strlen(%())","HOperatorSetX.TupleStrlen\2"); 190 | strr = string.replace(strr,"()split(%())","HOperatorSetX.TupleSplit\2"); 191 | strr = string.replace(strr,"()difference(%())","HOperatorSetX.TupleDifference\2"); 192 | strr = string.replace(strr,"()intersection(%())","HOperatorSetX.TupleIntersection\2"); 193 | strr = string.replace(strr,"()symmdiff(%())","HOperatorSetX.TupleSymmdiff\2"); 194 | strr = string.replace(strr,"()union(%())","HOperatorSetX.TupleUnion\2"); 195 | strr = string.replace(strr,"()sum(%())","HOperatorSetX.TupleSum\2"); 196 | 197 | strr = string.replace(strr,"^\s*dev_display\s*\((.*)\)","HOperatorSetX.DispObj(\1 , WindowHandle );",1); 198 | strr = string.replace(strr,"^\s*dev_set_color\s*\((.*)\)","HOperatorSetX.SetColor( WindowHandle , \1 );",1); 199 | strr = string.replace(strr,"^\s*dev_set_colored\s*\((.*)\)","HOperatorSetX.SetColored( WindowHandle , \1 );",1); 200 | strr = string.replace(strr,"^\s*dev_set_draw\s*\((.*)\)","HOperatorSetX.SetDraw( WindowHandle , \1 );",1); 201 | strr = string.replace(strr,"^\s*dev_set_line_width\s*\((.*)\)","HOperatorSetX.SetLineWidth( WindowHandle , \1 );",1); 202 | strr = string.replace(strr,"^\s*dev_clear_obj\s*\((.*)\)","HOperatorSetX.ClearObj( \1 );",1); 203 | strr = string.replace(strr,"^\s*dev_set_shape\s*\((.*)\)","HOperatorSetX.SetShape( WindowHandle ,\1 );",1); 204 | strr = string.replace(strr,"^\s*dev_disp_text\s*\((.*)\)","HOperatorSetX.DispText( WindowHandle ,\1);"); 205 | 206 | strr = string.replace(strr,"^\s*dev_.*?%()","//\1",1); 207 | 208 | strr = string.replace(strr,"()set_display_font\s*(%())","//set_display_font\2"); 209 | 210 | strr = string.replace(strr,"^\s*disp_message\s*\((.*),(.*),(.*),(.*),(.*),(.*),(.*)\)","HOperatorSetX.DispText(\1,\2,\3,\4,\5,\6,'shadow',\7);",1); 211 | strr = string.replace(strr,"()disp_continue_message\s*(%())","//disp_continue_message\2"); 212 | strr = string.replace(strr,"()stop\s*(%())","//stop\2"); 213 | 214 | strr = string.replace(strr,"^\s*\*\s*","//"); 215 | 216 | strr = string.replace(strr,"()(%\|\|)","HOperatorSetX.TupleLength(\2)"); 217 | strr = string.replace(strr,"@(|","("); 218 | strr = string.replace(strr,"@|)",")"); 219 | 220 | strr = string.replace(strr,"^\s*for(.*)<=>(.*)to(.*)by\s*(\d+)","for\(\1=\2;\3;\4\)\{",1); 221 | strr = string.replace(strr,"endfor","}"); 222 | 223 | strr = string.replace(strr,"^\s*if\s*%()","\1\{"); 224 | strr = string.replace(strr,"^\s*elseif\s*%()","\1\{"); 225 | strr = string.replace(strr,"^\s*else\s+","\1\{"); 226 | strr = string.replace(strr,"endif","}"); 227 | 228 | 229 | return strr; 230 | } 231 | 232 | //匹配括号 233 | var ss = string.match(str,"%()"); 234 | if(!ss){ 235 | //不是设定的函数 236 | str = replaceFun(str); 237 | return str; 238 | } 239 | //取函数名称 240 | var funcName = string.trim(string.replace(str,"@"++ss,"")); 241 | //转换函数名 242 | var strP = string.split(funcName,"_"); 243 | var retName; 244 | for(i=1;#strP;1){ 245 | var sstr = string.split(strP[i]) 246 | for(i=1;#sstr;1){ 247 | if(i==1){ 248 | retName = string.concat(retName,string.upper(sstr[1])); 249 | }else { 250 | retName = string.concat(retName,sstr[i]); 251 | } 252 | } 253 | } 254 | retName = string.trim(retName); 255 | //取出参数部分 256 | var leftss = string.left(ss,#ss-1,true ); 257 | var retSS = string.right(leftss,#leftss-1,true) 258 | 259 | 260 | var returnPlace={}; 261 | var i =1; 262 | for s in string.gmatch( retSS, "%\[\]" ){ 263 | returnPlace[i] = replaceStr(s); 264 | retSS = string.replace(retSS,"@"++s,"SSSSYYSSSS"); 265 | i++; 266 | } 267 | 268 | 269 | var ssP = string.split(retSS,","); 270 | for(i=1;#ssP;1){ 271 | ssP[i] = replaceFun(ssP[i]); 272 | } 273 | 274 | //匹配转换规则 275 | var guize = ListFun[retName]; 276 | if(guize){ 277 | var guizeP = string.split(guize,","); 278 | var retStr = ""; 279 | var header = ""; 280 | var tailer = ""; 281 | for(i=1;#guizeP;1){ 282 | if(guizeP[i] == 0){ 283 | if(header == ""){ 284 | header = string.concat(header,ssP[i]) 285 | }else { 286 | header = string.concat(header,",",ssP[i]) 287 | } 288 | }else { 289 | if(tailer == ""){ 290 | tailer = string.concat(tailer,ssP[i]) 291 | }else { 292 | tailer = string.concat(tailer,",",ssP[i]) 293 | } 294 | 295 | 296 | 297 | 298 | } 299 | } 300 | if(header == ""){ 301 | retStr = string.concat(retStr,"HOperatorSetX.",retName,"( ",tailer," );"); 302 | }else { 303 | retStr = string.concat(retStr,"var ",header," = HOperatorSetX.",retName,"( ",tailer," );"); 304 | } 305 | 306 | if(#returnPlace){ 307 | var j=1; 308 | for m in string.gmatch(retStr ,"SSSSYYSSSS") { 309 | retStr = string.replace(retStr,"SSSSYYSSSS",returnPlace[j],1); 310 | j++; 311 | } 312 | } 313 | return retStr; 314 | }else { 315 | //不是设定的函数 316 | str = replaceFun(str); 317 | return str; 318 | } 319 | } 320 | //示例代码 321 | mainForm.halcon代码.text=/**** 322 | read_image (Image, 'progres') 323 | get_image_size (Image, Width, Height) 324 | dev_close_window () 325 | dev_open_window (0, 0, Width, Height, 'white', WindowID) 326 | dev_set_color ('red') 327 | gen_rectangle1 (Rectangle, 260, 90, 360, 350) 328 | reduce_domain (Image, Rectangle, ImageReduced) 329 | threshold (ImageReduced, Dark, 0, 150) 330 | connection (Dark, ConnectedRegions) 331 | select_shape (ConnectedRegions, SelectedRegions, 'area', 'and', 10, 100) 332 | elliptic_axis (SelectedRegions, Ra, Rb, Phi) 333 | area_center (SelectedRegions, Area, Row, Column) 334 | dev_set_draw ('margin') 335 | dev_display (Image) 336 | * dev_set_colored (12) 337 | dev_set_color ('green') 338 | dev_display (SelectedRegions) 339 | MeanRadius := sum(Ra) / |Ra| 340 | VarianceRadius := sum(Ra * Ra - MeanRadius * MeanRadius) / (|Ra| - 1) 341 | ****/ 342 | 343 | mainForm.halcon代码.enablePopMenu(); 344 | mainForm.aar代码.enablePopMenu(); 345 | 346 | mainForm.button2.oncommand = function(id,event){ 347 | path = io.exist("/"++mainForm.Halconclassname.text++".ini") 348 | if(!path){ 349 | mainForm.msgboxErr("匹配库文件不存在 , 请先点击头部按钮 , 生成匹配库文件!"); 350 | return; 351 | } 352 | 353 | for line in mainForm.halcon代码.lines(true){ 354 | var str = halcon2AAR( line ); 355 | mainForm.aar代码.log(str ,'\r\n' ) 356 | } 357 | } 358 | 359 | mainForm.button3.oncommand = function(id,event){ 360 | mainForm.halcon代码.text = ""; 361 | } 362 | 363 | mainForm.button4.oncommand = function(id,event){ 364 | mainForm.aar代码.text = ""; 365 | } 366 | 367 | mainForm.button5.oncommand = function(id,event){ 368 | mainForm.halcon代码.text = win.clip.read(); 369 | } 370 | 371 | mainForm.button6.oncommand = function(id,event){ 372 | win.clip.write( mainForm.aar代码.text ) 373 | } 374 | 375 | mainForm.show(); 376 | return win.loopMessage(); 377 | -------------------------------------------------------------------------------- /halconVideoCapture.aardio: -------------------------------------------------------------------------------- 1 | import win.ui; 2 | /*DSG{{*/ 3 | var winform = win.form(text="aardio form";right=969;bottom=646;parent=...) 4 | winform.add( 5 | button={cls="button";text="开启";left=31;top=549;right=193;bottom=635;z=1}; 6 | button2={cls="button";text="关闭";left=208;top=549;right=370;bottom=635;z=2}; 7 | picturebox={cls="picturebox";left=0;top=0;right=970;bottom=535;z=3} 8 | ) 9 | /*}}*/ 10 | 11 | import com; 12 | var HOperatorSetX = com.CreateObject("{6ebd90e2-d219-11d2-ade5-0000c00f4ef9}") 13 | 14 | import console 15 | console.open() 16 | 17 | var AcqHandle = HOperatorSetX.OpenFramegrabber( 'DirectShow', 1, 1, 0, 0, 0, 0, 'default', 8, 'rgb', -1, 'false', 'default', '', 0, -1 ); 18 | HOperatorSetX.GrabImageStart( AcqHandle , -1 ); 19 | var Image = HOperatorSetX.GrabImageAsync( AcqHandle , -1 ); 20 | //获取图像宽和高 21 | var Width , Height = HOperatorSetX.GetImageSize( Image ); 22 | console.log(Width , Height) 23 | //调整画面大小和图像一致 24 | var WindowHandle = HOperatorSetX.OpenWindow( 0 , 0 , Width , Height , winform.picturebox.hwnd , "transparent","" ); 25 | 26 | var videoShow = true; 27 | winform.button.oncommand = function(id,event){ 28 | 29 | while(win.delay(30)&&videoShow){ 30 | Image = HOperatorSetX.GrabImageAsync( AcqHandle , -1 ); 31 | //镜像图像 32 | var ImageMirror = HOperatorSetX.MirrorImage( Image , "row" ); 33 | HOperatorSetX.DispObj( ImageMirror , WindowHandle ); 34 | //释放内存 35 | HOperatorSetX.ClearObj( ImageMirror ); 36 | HOperatorSetX.ClearObj( Image ); 37 | 38 | } 39 | 40 | } 41 | winform.button2.oncommand = function(id,event){ 42 | 43 | videoShow = false; 44 | win.delay(500) 45 | HOperatorSetX.CloseFramegrabber( AcqHandle ); 46 | 47 | 48 | 49 | } 50 | 51 | winform.wndproc = function(hwnd,message,wParam,lParam){ 52 | select( message ) { 53 | case 0x10/*_WM_CLOSE*/{ 54 | if(videoShow){ 55 | videoShow = false; 56 | win.delay(500) 57 | HOperatorSetX.CloseFramegrabber( AcqHandle ); 58 | } 59 | 60 | } 61 | else{ 62 | 63 | } 64 | } 65 | //无返回值则继续调用默认回调函数 66 | } 67 | 68 | winform.enableDpiScaling(); 69 | winform.show(); 70 | 71 | win.loopMessage(); 72 | return winform; 73 | --------------------------------------------------------------------------------