其他分享
首页 > 其他分享> > halcon-orientation_region返回区域的方向

halcon-orientation_region返回区域的方向

作者:互联网

7.png

 

在HDevelop中

dev_update_off()
dev_close_window ()
read_image (Clip, 'D:/bb/tu/7.png')
get_image_size (Clip, Width, Height)
dev_open_window (0, 0, Width, Height, 'black', WindowID)
dev_display (Clip)

*设置窗口字体显示,字体大小,字体样式,粗体,斜体
set_display_font (WindowID, 14, 'mono', 'true', 'false')

disp_continue_message (WindowID, 'black', 'true')
*在屏幕的右下角显示“Press Run  (F5) to  continue”
*注意:程序不会停止,一般下一句就是stop()
*参数1:窗口句柄
*参数3:如果设置为'true',则文本将写在白框内,这在不规则背景下很有用
*参数2:定义文本颜色
*      可选值: ‘black’, ‘blue’, ‘yellow’, ‘red’, ‘green’, ‘cyan’, ‘magenta’, 
*              ‘forest green’, ‘lime green’, ‘coral’, ‘slate blue’

stop()
*暂停

*二值化操作
binary_threshold (Clip, Dark, 'max_separability', 'dark', UsedThreshold)

*将区域进行连通处理
connection (Dark, Single)

*过滤出面积大小在【5000, 10000】范围里的区域
select_shape (Single, Selected, 'area', 'and', 1600, 20000)

dev_open_window (50, 50, Width, Height, 'black', WindowID1)
dev_display (Selected)


orientation_region (Selected, Phi)
*返回区域的方向
*参数1:区域
*参数2:与x轴的夹角,其实就是elliptic_axis算子中的Phi

*获取过滤后区域的面积,中心的行坐标,列坐标
area_center (Selected, Area, Row, Column)

*设置输出对象的线宽为3
dev_set_line_width (3)

*设置区域的填充方式
dev_set_draw ('margin')
Length := 80

*设置输出对象的颜色为蓝色
dev_set_color ('blue')


disp_arrow (WindowID1, Row, Column, Row - Length * sin(Phi), Column + Length * cos(Phi), 2)
*在窗口显示箭头
*参数1:窗口句柄
*参数2和参数3:起始行坐标, 起始列坐标
*参数4和参数5:终止行坐标, 终止列坐标
*参数6:箭头宽度

 

 

在Qt Creator中

  HObject  ho_Clip, ho_Dark, ho_Single, ho_Selected;
  HTuple  hv_Width, hv_Height, hv_WindowID, hv_UsedThreshold;
  HTuple  hv_WindowID1, hv_Phi, hv_Area, hv_Row, hv_Column;
  HTuple  hv_Length;
  ReadImage(&ho_Clip, "D:/bb/tu/7.png");
  GetImageSize(ho_Clip, &hv_Width, &hv_Height);
  SetWindowAttr("background_color","black");
  OpenWindow(0,0,hv_Width,hv_Height,0,"visible","",&hv_WindowID);
  HDevWindowStack::Push(hv_WindowID);
  if (HDevWindowStack::IsOpen())
    DispObj(ho_Clip, HDevWindowStack::GetActive());

  //设置窗口字体显示,字体大小,字体样式,粗体,斜体
  set_display_font(hv_WindowID, 14, "mono", "true", "false");

  disp_continue_message(hv_WindowID, "black", "true");
  //在屏幕的右下角显示“Press Run  (F5) to  continue”
  //注意:程序不会停止,一般下一句就是stop()
  //参数1:窗口句柄
  //参数3:如果设置为'true',则文本将写在白框内,这在不规则背景下很有用
  //参数2:定义文本颜色
  //     可选值: ‘black’, ‘blue’, ‘yellow’, ‘red’, ‘green’, ‘cyan’, ‘magenta’,
  //             ‘forest green’, ‘lime green’, ‘coral’, ‘slate blue’

  // stop(...); only in hdevelop
  //暂停

  //二值化操作
  BinaryThreshold(ho_Clip, &ho_Dark, "max_separability", "dark", &hv_UsedThreshold);

  //将区域进行连通处理
  Connection(ho_Dark, &ho_Single);

  //过滤出面积大小在【5000, 10000】范围里的区域
  SelectShape(ho_Single, &ho_Selected, "area", "and", 1600, 20000);

  SetWindowAttr("background_color","black");
  OpenWindow(50,50,hv_Width,hv_Height,0,"visible","",&hv_WindowID1);
  HDevWindowStack::Push(hv_WindowID1);
  if (HDevWindowStack::IsOpen())
    DispObj(ho_Selected, HDevWindowStack::GetActive());


  OrientationRegion(ho_Selected, &hv_Phi);
  //返回区域的方向
  //参数1:区域
  //参数2:与x轴的夹角,其实就是elliptic_axis算子中的Phi

  //获取过滤后区域的面积,中心的行坐标,列坐标
  AreaCenter(ho_Selected, &hv_Area, &hv_Row, &hv_Column);

  //设置输出对象的线宽为3
  if (HDevWindowStack::IsOpen())
    SetLineWidth(HDevWindowStack::GetActive(),3);

  //设置区域的填充方式
  if (HDevWindowStack::IsOpen())
    SetDraw(HDevWindowStack::GetActive(),"margin");
  hv_Length = 80;

  //设置输出对象的颜色为蓝色
  if (HDevWindowStack::IsOpen())
    SetColor(HDevWindowStack::GetActive(),"blue");


  DispArrow(hv_WindowID1, hv_Row, hv_Column, hv_Row-(hv_Length*(hv_Phi.TupleSin())), 
      hv_Column+(hv_Length*(hv_Phi.TupleCos())), 2);
  //在窗口显示箭头
  //参数1:窗口句柄
  //参数2和参数3:起始行坐标, 起始列坐标
  //参数4和参数5:终止行坐标, 终止列坐标
  //参数6:箭头宽度

 

 

 

 

 

 

 

 

标签:HDevWindowStack,orientation,Clip,region,Selected,hv,halcon,参数,ho
来源: https://www.cnblogs.com/liming19680104/p/16198625.html