Halcon C++混合编程学习之Qt 实现检测焊接点
1 # include "HalconCpp.h" 2 # include "HDevThread.h" 3 # include <X11/Xlib.h> 4 # include <stdio.h> 5 6 using namespace HalconCpp; 7 8 9 10 // Main procedure 11 void action() 12 { 13 14 // Local iconic variables 15 HObject ho_Die, ho_Brightregion, ho_ROI, ho_DieROI; 16 HObject ho_RawSegmentation, ho_Wires, ho_BallRegion, ho_Balls; 17 HObject ho_FinalBalls; 18 19 // Local control variables 20 HTuple hv_WindowID,hv_WindowID2; 21 HTuple hv_Width,hv_Height; 22 23 ReadImage(&ho_Die, "/home/debug/Halcon_Test/Halcon_Qt_Test/DeteBondPoint/die_03.png"); 24 GetImageSize(ho_Die,&hv_Width,&hv_Height); 25 SetWindowAttr("background_color","black"); 26 OpenWindow(0,0,hv_Width,hv_Height,0,"","",&hv_WindowID); 27 HDevWindowStack::Push(hv_WindowID); 28 DispImage(ho_Die,hv_WindowID); 29 30 31 Threshold(ho_Die, &ho_Brightregion, 128, 255); 32 ShapeTrans(ho_Brightregion, &ho_ROI, "rectangle2"); 33 ReduceDomain(ho_Die, ho_ROI, &ho_DieROI); 34 Threshold(ho_DieROI, &ho_RawSegmentation, 0, 50); 35 FillUpShape(ho_RawSegmentation, &ho_Wires, "area", 1, 100); 36 OpeningCircle(ho_Wires, &ho_BallRegion, 15.5); 37 Connection(ho_BallRegion, &ho_Balls); 38 SelectShape(ho_Balls, &ho_FinalBalls, "circularity", "and", 0.85, 1.0); 39 40 if (HDevWindowStack::IsOpen()) 41 SetWindowAttr("background_color","black"); 42 OpenWindow(0,0,hv_Width,hv_Height,0,"","",&hv_WindowID2); 43 HDevWindowStack::Push(hv_WindowID2); 44 DispObj(ho_FinalBalls, HDevWindowStack::GetActive()); 45 46 WaitSeconds(100); 47 ClearWindow(hv_WindowID); 48 ClearWindow(hv_WindowID2); 49 50 } 51 52 int main(int argc, char *argv[]) 53 { 54 // Default settings used in HDevelop (can be omitted) 55 int ret=0; 56 // SetSystem("width", 700); 57 // SetSystem("height", 600); 58 XInitThreads(); 59 action(); 60 return ret; 61 } 结果如下: