Halcon C++混合編程學習之Qt 實現檢測焊接點
# include "HalconCpp.h"
# include "HDevThread.h"
# include <X11/Xlib.h>
# include <stdio.h>
using namespace HalconCpp;
// Main procedure
void action()
{
// Local iconic variables
HObject ho_Die, ho_Brightregion, ho_ROI, ho_DieROI;
HObject ho_RawSegmentation, ho_Wires, ho_BallRegion, ho_Balls;
HObject ho_FinalBalls;
// Local control variables
HTuple hv_WindowID,hv_WindowID2;
HTuple hv_Width,hv_Height;
ReadImage(&ho_Die, "/home/debug/Halcon_Test/Halcon_Qt_Test/DeteBondPoint/die_03.png");
GetImageSize(ho_Die,&hv_Width,&hv_Height);
SetWindowAttr("background_color","black");
OpenWindow(0,0,hv_Width,hv_Height,0,"","",&hv_WindowID);
HDevWindowStack::Push(hv_WindowID);
DispImage(ho_Die,hv_WindowID);
Threshold(ho_Die, &ho_Brightregion, 128, 255);
ShapeTrans(ho_Brightregion, &ho_ROI, "rectangle2");
ReduceDomain(ho_Die, ho_ROI, &ho_DieROI);
Threshold(ho_DieROI, &ho_RawSegmentation, 0, 50);
FillUpShape(ho_RawSegmentation, &ho_Wires, "area", 1, 100);
OpeningCircle(ho_Wires, &ho_BallRegion, 15.5);
Connection(ho_BallRegion, &ho_Balls);
SelectShape(ho_Balls, &ho_FinalBalls, "circularity", "and", 0.85, 1.0);
if (HDevWindowStack::IsOpen())
SetWindowAttr("background_color","black");
OpenWindow(0,0,hv_Width,hv_Height,0,"","",&hv_WindowID2);
HDevWindowStack::Push(hv_WindowID2);
DispObj(ho_FinalBalls, HDevWindowStack::GetActive());
WaitSeconds(100);
ClearWindow(hv_WindowID);
ClearWindow(hv_WindowID2);
}
int main(int argc, char *argv[])
{
// Default settings used in HDevelop (can be omitted)
int ret=0;
// SetSystem("width", 700);
// SetSystem("height", 600);
XInitThreads();
action();
return ret;
}
結果如下: