|
楼主 |
发表于 2018-3-29 22:00:30
|
显示全部楼层
昨天说tuple可以利用dll里面的函数进行赋值和操作了.
今天直接拿来放到了上次分享的那个画边界圆的示例里,
发现还是不能正确使用.╮(╯▽╰)╭
这次应该不是tuple参数错误了,估计应该是api调用错误, 试了好几种想法,都不行,吐血..
希望有研究这方面的朋友帮忙给看下, 我也会继续各种测试 , 如果解决了会第一时间更新帖子
- import win.ui;
- /*DSG{{*/
- mainForm = win.form(text="Halcon函数circle测试";right=833;bottom=525)
- mainForm.add(
- button={cls="button";text="button";left=9;top=9;right=170;bottom=59;z=2};
- picturebox={cls="picturebox";left=182;top=0;right=834;bottom=526;bgcolor=8421376;z=1};
- snumber={cls="static";text="0";left=18;top=397;right=150;bottom=433;font=LOGFONT(h=-21);transparent=1;z=3}
- )
- /*}}*/
- import console;
- var dll = ..raw.loadDll("\res\halconc.dll","halconlib","cdecl");
- open_window= dll.api("open_window","int(int Row, int Column, int Width, int Height, int FatherWindow, string Mode, string Machine, int& WindowHandle)");
- read_image= dll.api("read_image","int(ADDR& Image, string FileName)");
- get_image_size= dll.api("get_image_size","int(ADDR Image, int& Width, int& Height)");
- disp_obj= dll.api("disp_obj","int(ADDR Object, int WindowHandle)");
- fast_threshold= dll.api("fast_threshold","int(ADDR Image, ADDR& Region, double MinGray, double MaxGray, int MinSize)");
- disp_region= dll.api("disp_region","int(ADDR DispRegions, int WindowHandle)");
- set_colored= dll.api("set_colored","int(int WindowHandle, int NumberOfColors)");
- set_color= dll.api("set_color","int(int WindowHandle, string Color)");
- boundary= dll.api("boundary","int(ADDR Region, ADDR& RegionBorder, string BoundaryType)");
- clip_region_rel= dll.api("clip_region_rel","int(ADDR Region, ADDR& RegionClipped, int Top, int Bottom, int Left, int Right)");
- dilation_circle= dll.api("dilation_circle","int(ADDR Region, ADDR& RegionDilation, double Radius)");
- reduce_domain= dll.api("reduce_domain","int(ADDR Image, ADDR Region, ADDR& ImageReduced)");
- edges_sub_pix= dll.api("edges_sub_pix","int(ADDR Image, ADDR& Edges, string Filter, double Alpha, int Low, int High)");
- segment_contours_xld= dll.api("segment_contours_xld","int(ADDR Contours, ADDR& ContoursSplit, string Mode, int SmoothCont, double MaxLineDist1, double MaxLineDist2)");
- count_obj= dll.api("count_obj","int(ADDR Objects, int& Number)");
- set_draw= dll.api("set_draw","int(int WindowHandle, string Mode)");
- select_obj= dll.api("select_obj","int(ADDR Objects, ADDR& ObjectSelected, int Index)");
- //主要是下面这个函数
- T_get_contour_global_attrib_xld= dll.api("T_get_contour_global_attrib_xld","int(ADDR Contour, pointer Name, pointer Attrib)");
- fit_circle_contour_xld= dll.api("fit_circle_contour_xld","int(ADDR Contours, string Algorithm, int MaxNumPoints, double MaxClosureDist, int ClippingEndPoints, int Iterations, double ClippingFactor, double& Row, double& Column, double& Radius, double& StartPhi, double& EndPhi, string& PointOrder)");
- gen_circle_contour_xld= dll.api("gen_circle_contour_xld","int(ADDR& ContCircle, double Row, double Column, double Radius, double StartPhi, double EndPhi, string PointOrder, double Resolution)");
- set_line_width= dll.api("set_line_width","int(int WindowHandle, double Width)");
- //下面是对tuple的一些操作
- F_create_tuple= dll.api("F_create_tuple","void(pointer T, int length)");
- F_create_tuple_i= dll.api("F_create_tuple_i","void(pointer T, int val)");
- F_create_tuple_s=dll.api("F_create_tuple_s","void(pointer T, string val)");
- F_get_s=dll.api("F_get_s","string(pointer T, int index)");
- F_set_s=dll.api("F_set_s","void(pointer T, string val,int index)");
- F_get_i=dll.api("F_get_i","int(pointer T, int index)");
- F_create_tuple_d=dll.api("F_create_tuple_d","void(pointer T, double val)");
- F_create_tuple_type=dll.api("F_create_tuple_type","void(pointer T, int length, int type)");
- F_destroy_tuple=dll.api("F_destroy_tuple","void(pointer T)");
- console.open();
- mainForm.button.oncommand = function(id,event){
-
- var ret,Image = read_image(0,"res/double_circle");
- var ret,width,height = get_image_size(Image,0,0);
- var ret,Hwindow = open_window(0,0,width,height,mainForm.picturebox.hwnd,"visible", "",0);
- var ret = disp_obj(Image,Hwindow);
- //win.delay(1000)
- var ret,Region = fast_threshold(Image,0,0,120,7);
- set_colored(Hwindow,6);
- disp_region(Region,Hwindow)
- //win.delay(1000)
- var ret,RegionBorder = boundary(Region,0,"inner");
- var ret,RegionClipped = clip_region_rel(RegionBorder,0,5,5,5,5);
- var ret,RegionDilation = dilation_circle(RegionClipped,0,2.5);
- var ret,ImageReduced = reduce_domain(Image,RegionDilation,0);
- var ret = disp_obj(ImageReduced,Hwindow);
- //win.delay(1000)
- var ret,Edges = edges_sub_pix(ImageReduced,0,"canny",2,20,60);
- var ret = disp_obj(Edges,Hwindow);
- //win.delay(1000)
- var ret,ContoursSplit = segment_contours_xld(Edges,0,"lines_circles",5,4,3);
- //var ret = disp_obj(ContoursSplit,Hwindow);
- var ret = disp_obj(Image,Hwindow);
- var ret,Number = count_obj(ContoursSplit,0);
- //mainForm.snumber.text = Number;
- set_draw(Hwindow,"margin");
- set_color(Hwindow,"orange red");
- set_line_width(Hwindow,4.0);
- console.log("开始循环")
- win.delay(1000)
- for(i=1;Number;1){
- var ret,ObjectSelected = select_obj(ContoursSplit,0,i);
- //这里定义了需要使用的tuple元组
- var nametuple = raw.buffer(100);
- F_create_tuple_s(nametuple,"cont_approx");
- var Attribtuple = raw.buffer(100);
- F_create_tuple(Attribtuple,0);
- F_destroy_tuple(Attribtuple);
- //var Patt = raw.toPointer(Attribtuple)
-
- console.log("第"++i++"次循环开始")
- win.delay(1000)
- //下面这个引用函数老是报错: raw callback 内存错误
- var ret,Attrib = T_get_contour_global_attrib_xld(ObjectSelected,nametuple,Attribtuple);
- //if(Attrib > 0){
- console.log("第"++i++"次循环结束")
- win.delay(1000)
- //}
- }
- }
-
- mainForm.enableDpiScaling();
- mainForm.show();
-
- return win.loopMessage();
复制代码
工程下载地址: https://pan.baidu.com/s/19PlTCUTAfCrGUl_1IjNjxA |
|