halcon程序输出成c++程序

halcon语法程序:

dev_open_window (0, 300, -1, -1, 'black', WindowID)
read_image (Die4, 'C:/Users/Public/Documents/MVTec/HALCON-12.0/examples/images/die/die_03.png')
draw_rectangle1 (WindowID, Row1, Column1, Row2, Column2)
gen_rectangle1 (ROI, Row1, Column1, Row2, Column2)
reduce_domain (Die4, ROI, ImageReduced)
create_template (ImageReduced, 5, 4, 'sort', 'original', TemplateID)
TemplRow := (Row1+Row2)/2
TemplCol  := (Column1+Column2)/2
fast_match (Die4, Matches, TemplateID, 20)
connection (Matches, BallROI)
count_obj (BallROI, NumBall)
add_channels (BallROI, Die4, BallImage)
best_match (BallImage, TemplateID, 20, 'true', Row, Column, Error)
* disp_rectangle1 (WindowID, Row+Row1-TemplRow, Column+Column1-TemplCol, Row+Row2-TemplRow, Column+Column2-TemplCol)
RealNumBalls := 0
for i:=1 to NumBall by 1
    if (Error[i-1]<255)
        disp_rectangle1(WindowID,Row[i-1]+Row1-TemplRow,Column[i-1]+Column1-TemplCol,Row[i-1]+Row2-TemplRow,Column[i-1]+Column2-TemplCol)
        RealNumBalls := RealNumBalls + 1
    endif
endfor
set_spy ('mode', 'on')

 生成的C++代码:

///////////////////////////////////////////////////////////////////////////////
//  File generated by HDevelop for HALCON/C++ Version 12.0
///////////////////////////////////////////////////////////////////////////////



#ifndef __APPLE__
#  include "HalconCpp.h"
#  include "HDevThread.h"
#  if defined(__linux__) && !defined(NO_EXPORT_APP_MAIN)
#    include <X11/Xlib.h>
#  endif
#else
#  ifndef HC_LARGE_IMAGES
#    include <HALCONCpp/HalconCpp.h>
#    include <HALCONCpp/HDevThread.h>
#  else
#    include <HALCONCppxl/HalconCpp.h>
#    include <HALCONCppxl/HDevThread.h>
#  endif
#  include <stdio.h>
#  include <HALCON/HpThread.h>
#  include <CoreFoundation/CFRunLoop.h>
#endif



using namespace HalconCpp;


#ifndef NO_EXPORT_MAIN
// Main procedure 
void action()
{

  // Local iconic variables
  HObject  ho_Die4, ho_ROI, ho_ImageReduced, ho_Matches;
  HObject  ho_BallROI, ho_BallImage;

  // Local control variables
  HTuple  hv_WindowID, hv_Row1, hv_Column1, hv_Row2;
  HTuple  hv_Column2, hv_TemplateID, hv_TemplRow, hv_TemplCol;
  HTuple  hv_NumBall, hv_Row, hv_Column, hv_Error, hv_RealNumBalls;
  HTuple  hv_i;

  SetWindowAttr("background_color","black");
  OpenWindow(0,300,-1,-1,0,"","",&hv_WindowID);
  HDevWindowStack::Push(hv_WindowID);
  ReadImage(&ho_Die4, "C:/Users/Public/Documents/MVTec/HALCON-12.0/examples/images/die/die_03.png");
  DrawRectangle1(hv_WindowID, &hv_Row1, &hv_Column1, &hv_Row2, &hv_Column2);
  GenRectangle1(&ho_ROI, hv_Row1, hv_Column1, hv_Row2, hv_Column2);
  ReduceDomain(ho_Die4, ho_ROI, &ho_ImageReduced);
  CreateTemplate(ho_ImageReduced, 5, 4, "sort", "original", &hv_TemplateID);
  hv_TemplRow = (hv_Row1+hv_Row2)/2;
  hv_TemplCol = (hv_Column1+hv_Column2)/2;
  FastMatch(ho_Die4, &ho_Matches, hv_TemplateID, 20);
  Connection(ho_Matches, &ho_BallROI);
  CountObj(ho_BallROI, &hv_NumBall);
  AddChannels(ho_BallROI, ho_Die4, &ho_BallImage);
  BestMatch(ho_BallImage, hv_TemplateID, 20, "true", &hv_Row, &hv_Column, &hv_Error);
  //disp_rectangle1 (WindowID, Row+Row1-TemplRow, Column+Column1-TemplCol, Row+Row2-TemplRow, Column+Column2-TemplCol)
  hv_RealNumBalls = 0;
  {
  HTuple end_val15 = hv_NumBall;
  HTuple step_val15 = 1;
  for (hv_i=1; hv_i.Continue(end_val15, step_val15); hv_i += step_val15)
  {
    if (0 != (HTuple(hv_Error[hv_i-1])<255))
    {
      DispRectangle1(hv_WindowID, (HTuple(hv_Row[hv_i-1])+hv_Row1)-hv_TemplRow, (HTuple(hv_Column[hv_i-1])+hv_Column1)-hv_TemplCol, 
          (HTuple(hv_Row[hv_i-1])+hv_Row2)-hv_TemplRow, (HTuple(hv_Column[hv_i-1])+hv_Column2)-hv_TemplCol);
      hv_RealNumBalls += 1;
    }
  }
  }
  SetSpy("mode", "on");
}


#ifndef NO_EXPORT_APP_MAIN

#ifdef __APPLE__
// On OS X systems, we must have a CFRunLoop running on the main thread in
// order for the HALCON graphics operators to work correctly, and run the
// action function in a separate thread. A CFRunLoopTimer is used to make sure
// the action function is not called before the CFRunLoop is running.
HTuple      gStartMutex;
H_pthread_t gActionThread;

static void timer_callback(CFRunLoopTimerRef timer, void *info)
{
  UnlockMutex(gStartMutex);
}

static Herror apple_action(void **parameters)
{
  LockMutex(gStartMutex);
  action();
  CFRunLoopStop(CFRunLoopGetMain());
  return H_MSG_OK;
}

static int apple_main(int argc, char *argv[])
{
  Herror                error;
  CFRunLoopTimerRef     Timer;
  CFRunLoopTimerContext TimerContext = { 0, 0, 0, 0, 0 };

  CreateMutex("type","sleep",&gStartMutex);
  LockMutex(gStartMutex);

  error = HpThreadHandleAlloc(&gActionThread);
  if (H_MSG_OK != error)
  {
    fprintf(stderr,"HpThreadHandleAlloc failed: %d\n", error);
    exit(1);
  }

  error = HpThreadCreate(gActionThread,0,apple_action);
  if (H_MSG_OK != error)
  {
    fprintf(stderr,"HpThreadCreate failed: %d\n", error);
    exit(1);
  }

  Timer = CFRunLoopTimerCreate(kCFAllocatorDefault,
                               CFAbsoluteTimeGetCurrent(),0,0,0,
                               timer_callback,&TimerContext);
  if (!Timer)
  {
    fprintf(stderr,"CFRunLoopTimerCreate failed\n");
    exit(1);
  }
  CFRunLoopAddTimer(CFRunLoopGetCurrent(),Timer,kCFRunLoopCommonModes);
  CFRunLoopRun();
  CFRunLoopRemoveTimer(CFRunLoopGetCurrent(),Timer,kCFRunLoopCommonModes);
  CFRelease(Timer);

  error = HpThreadHandleFree(gActionThread);
  if (H_MSG_OK != error)
  {
    fprintf(stderr,"HpThreadHandleFree failed: %d\n", error);
    exit(1);
  }

  ClearMutex(gStartMutex);
  return 0;
}
#endif

int main(int argc, char *argv[])
{
  // Default settings used in HDevelop (can be omitted) 
  int ret=0;
  SetSystem("width", 512);
  SetSystem("height", 512);

#if defined(_WIN32)
  SetSystem("use_window_thread", "true");
#elif defined(__linux__)
  XInitThreads();
#endif

#ifndef __APPLE__
  action();
#else
  ret = apple_main(argc,argv);
#endif
  return ret;
}

#endif


#endif

  

 

原文链接: https://www.cnblogs.com/acm-jing/p/9836291.html

欢迎关注

微信关注下方公众号,第一时间获取干货硬货;公众号内回复【pdf】免费获取数百本计算机经典书籍

    halcon程序输出成c++程序

原创文章受到原创版权保护。转载请注明出处:https://www.ccppcoding.com/archives/283649

非原创文章文中已经注明原地址,如有侵权,联系删除

关注公众号【高性能架构探索】,第一时间获取最新文章

转载文章受原作者版权保护。转载请注明原作者出处!

(0)
上一篇 2023年2月15日 上午7:16
下一篇 2023年2月15日 上午7:17

相关推荐