I'm trying to create a WinForms program that shows the result of Halcon procedure. This procedure (for now) is a variation of detect_mura_defects_texture, which I have adapted to become a hdvp
.
The point is that I d'ont know how to show the defects
selected by the select_mask_obj
function. At the moment, my Halcon procedure is:
decompose3(Image, R, G, B)
get_image_size(B, Width, Height)
rft_generic(B, ImageFFT, 'to_freq', 'none', 'complex', Width)
gen_gauss_filter(ImageGauss, 50, 50, 0, 'n', 'rft', Width, Height)
convol_fft(ImageFFT, ImageGauss, ImageConvol)
rft_generic(ImageConvol, IlluminationImage, 'from_freq', 'none', 'byte', Width)
sub_image(B, IlluminationImage, ImageSub, 2, 100)
median_image(ImageSub, ImageMedian, 'circle', 9, 'mirrored')
watersheds_threshold(ImageMedian, Basins, 20)
cooc_feature_image(Basins, ImageMedian, 6, 0, Energy, Correlation, Homogeneity, Contrast)
Mask := Energy [<=] 0.05
select_mask_obj(Basins, Defects, Mask)
dev_open_window(0, 0, 640, 480, 'green', WindowHandle)
dev_display(Image)
dev_display(Defects)
return ()
In my WinForms application, I can execute the Halcon procedure and shows the result in a ´Halcon.DotNet.HWindowControl´ (I have tried it with other Halcon procedures that return an image), but I don't know how to get the "Defects" that this scripts calculates and display it in hWindowControl1
.
private void ImageJoinBtn_Click (object sender, EventArgs e) {
string procedureName = selectHalconProcedure.Text;
switch (procedureName.Split(' ')[0]) {
case "0":
JoinTwoImagesProcedure();
break;
case "1":
GetDefectsProcedure();
break;
}
}
private void GetDefectsProcedure () {
try {
ING_Halcon halconScript = new ING_Halcon(HALCON_SCRIPTS_LIST[SCRIPT_TWO]);
halconScript.SetInputImage("Image", img1HParam);
halconScript.Execute();
var defects = halconScript.GetParamTupleImage("Defects");
HWindow hWin = hWindowControl1.HalconWindow;
HImage result = img1HParam;
hWin.DispImage(result);
hWin.DispObj(defects); // TODO: this instruction do nothing.
}
catch (Exception exc) {
Console.WriteLine($"GetDefectsProcedure Exception:\n\t{exc}.");
}
}
Thanks for your help
Really, the solution is very simple. My HWindow
control "hwin
" was not programmed to zoom in or zoom out. I couldn't drag the image either, which looked zoomed in too much. To solve this, just change the tool window "HWindowControl
" by "HSmartWindowControl
". You also need to schedule the "´Load´" event as follows.
private void Form1_Load(object sender, EventArgs e) {
hWin = hSmartWindowControl1.HalconWindow; // "hWin" has a private variable now.
hSmartWindowControl1.MouseWheel += hSmartWindowControl1.HSmartWindowControl_MouseWheel;
}
Is possible that the elements obtained by function hWin.DispObj(...)
may appear white on agrayscale image, so they may not stand out much in your application. Is possible to change it adding:
hWin.SetColor("green");
hWin.SetLineWidth(5);
Reference: SetColor and SetLineWidth.