当前位置:网站首页>视觉系统设计实例(halcon-winform)-9.文字显示
视觉系统设计实例(halcon-winform)-9.文字显示
2022-07-27 13:35:00 【11eleven】
我们在检测完图像后需要对结果做文字输出标记,标记OK或者NG以及其他注释。C#中调用halcon的HOperatorSet.DispText 一直报错。
代码如下:
public static void Disp_message(HTuple hv_WindowHandle, HTuple hv_String, HTuple hv_CoordSystem,
HTuple hv_Row, HTuple hv_Column, HTuple hv_Color, HTuple hv_Box)
{
// Local iconic variables
// Local control variables
HTuple hv_GenParamName = new HTuple(), hv_GenParamValue = new HTuple();
HTuple hv_Color_COPY_INP_TMP = new HTuple(hv_Color);
HTuple hv_Column_COPY_INP_TMP = new HTuple(hv_Column);
HTuple hv_CoordSystem_COPY_INP_TMP = new HTuple(hv_CoordSystem);
HTuple hv_Row_COPY_INP_TMP = new HTuple(hv_Row);
// Initialize local and output iconic variables
try
{
//This procedure displays text in a graphics window.
//
//Input parameters:
//WindowHandle: The WindowHandle of the graphics window, where
// the message should be displayed.
//String: A tuple of strings containing the text messages to be displayed.
//CoordSystem: If set to 'window', the text position is given
// with respect to the window coordinate system.
// If set to 'image', image coordinates are used.
// (This may be useful in zoomed images.)
//Row: The row coordinate of the desired text position.
// You can pass a single value or a tuple of values.
// See the explanation below.
// Default: 12.
//Column: The column coordinate of the desired text position.
// You can pass a single value or a tuple of values.
// See the explanation below.
// Default: 12.
//Color: defines the color of the text as string.
// If set to [] or '' the currently set color is used.
// If a tuple of strings is passed, the colors are used cyclically
// for every text position defined by Row and Column,
// or every new text line in case of |Row| == |Column| == 1.
//Box: A tuple controlling a possible box surrounding the text.
// Its entries:
// - Box[0]: Controls the box and its color. Possible values:
// -- 'true' (Default): An orange box is displayed.
// -- 'false': No box is displayed.
// -- color string: A box is displayed in the given color, e.g., 'white', '#FF00CC'.
// - Box[1] (Optional): Controls the shadow of the box. Possible values:
// -- 'true' (Default): A shadow is displayed in
// darker orange if Box[0] is not a color and in 'white' otherwise.
// -- 'false': No shadow is displayed.
// -- color string: A shadow is displayed in the given color, e.g., 'white', '#FF00CC'.
//
//It is possible to display multiple text strings in a single call.
//In this case, some restrictions apply on the
//parameters String, Row, and Column:
//They can only have either 1 entry or n entries.
//Behavior in the different cases:
// - Multiple text positions are specified, i.e.,
// - |Row| == n, |Column| == n
// - |Row| == n, |Column| == 1
// - |Row| == 1, |Column| == n
// In this case we distinguish:
// - |String| == n: Each element of String is displayed
// at the corresponding position.
// - |String| == 1: String is displayed n times
// at the corresponding positions.
// - Exactly one text position is specified,
// i.e., |Row| == |Column| == 1:
// Each element of String is display in a new textline.
//
//
//Convert the parameters for disp_text.
if ((int)((new HTuple(hv_Row_COPY_INP_TMP.TupleEqual(new HTuple()))).TupleOr(
new HTuple(hv_Column_COPY_INP_TMP.TupleEqual(new HTuple())))) != 0)
{
hv_Color_COPY_INP_TMP.Dispose();
hv_Column_COPY_INP_TMP.Dispose();
hv_CoordSystem_COPY_INP_TMP.Dispose();
hv_Row_COPY_INP_TMP.Dispose();
hv_GenParamName.Dispose();
hv_GenParamValue.Dispose();
return;
}
if ((int)(new HTuple(hv_Row_COPY_INP_TMP.TupleEqual(-1))) != 0)
{
hv_Row_COPY_INP_TMP.Dispose();
hv_Row_COPY_INP_TMP = 12;
}
if ((int)(new HTuple(hv_Column_COPY_INP_TMP.TupleEqual(-1))) != 0)
{
hv_Column_COPY_INP_TMP.Dispose();
hv_Column_COPY_INP_TMP = 12;
}
//
//Convert the parameter Box to generic parameters.
hv_GenParamName.Dispose();
hv_GenParamName = new HTuple();
hv_GenParamValue.Dispose();
hv_GenParamValue = new HTuple();
if ((int)(new HTuple((new HTuple(hv_Box.TupleLength())).TupleGreater(0))) != 0)
{
if ((int)(new HTuple(((hv_Box.TupleSelect(0))).TupleEqual("false"))) != 0)
{
//Display no box
using (HDevDisposeHelper dh = new HDevDisposeHelper())
{
{
HTuple
ExpTmpLocalVar_GenParamName = hv_GenParamName.TupleConcat(
"box");
hv_GenParamName.Dispose();
hv_GenParamName = ExpTmpLocalVar_GenParamName;
}
}
using (HDevDisposeHelper dh = new HDevDisposeHelper())
{
{
HTuple
ExpTmpLocalVar_GenParamValue = hv_GenParamValue.TupleConcat(
"false");
hv_GenParamValue.Dispose();
hv_GenParamValue = ExpTmpLocalVar_GenParamValue;
}
}
}
else if ((int)(new HTuple(((hv_Box.TupleSelect(0))).TupleNotEqual(
"true"))) != 0)
{
//Set a color other than the default.
using (HDevDisposeHelper dh = new HDevDisposeHelper())
{
{
HTuple
ExpTmpLocalVar_GenParamName = hv_GenParamName.TupleConcat(
"box_color");
hv_GenParamName.Dispose();
hv_GenParamName = ExpTmpLocalVar_GenParamName;
}
}
using (HDevDisposeHelper dh = new HDevDisposeHelper())
{
{
HTuple
ExpTmpLocalVar_GenParamValue = hv_GenParamValue.TupleConcat(
hv_Box.TupleSelect(0));
hv_GenParamValue.Dispose();
hv_GenParamValue = ExpTmpLocalVar_GenParamValue;
}
}
}
}
if ((int)(new HTuple((new HTuple(hv_Box.TupleLength())).TupleGreater(1))) != 0)
{
if ((int)(new HTuple(((hv_Box.TupleSelect(1))).TupleEqual("false"))) != 0)
{
//Display no shadow.
using (HDevDisposeHelper dh = new HDevDisposeHelper())
{
{
HTuple
ExpTmpLocalVar_GenParamName = hv_GenParamName.TupleConcat(
"shadow");
hv_GenParamName.Dispose();
hv_GenParamName = ExpTmpLocalVar_GenParamName;
}
}
using (HDevDisposeHelper dh = new HDevDisposeHelper())
{
{
HTuple
ExpTmpLocalVar_GenParamValue = hv_GenParamValue.TupleConcat(
"false");
hv_GenParamValue.Dispose();
hv_GenParamValue = ExpTmpLocalVar_GenParamValue;
}
}
}
else if ((int)(new HTuple(((hv_Box.TupleSelect(1))).TupleNotEqual(
"true"))) != 0)
{
//Set a shadow color other than the default.
using (HDevDisposeHelper dh = new HDevDisposeHelper())
{
{
HTuple
ExpTmpLocalVar_GenParamName = hv_GenParamName.TupleConcat(
"shadow_color");
hv_GenParamName.Dispose();
hv_GenParamName = ExpTmpLocalVar_GenParamName;
}
}
using (HDevDisposeHelper dh = new HDevDisposeHelper())
{
{
HTuple
ExpTmpLocalVar_GenParamValue = hv_GenParamValue.TupleConcat(
hv_Box.TupleSelect(1));
hv_GenParamValue.Dispose();
hv_GenParamValue = ExpTmpLocalVar_GenParamValue;
}
}
}
}
//Restore default CoordSystem behavior.
if ((int)(new HTuple(hv_CoordSystem_COPY_INP_TMP.TupleNotEqual("window"))) != 0)
{
hv_CoordSystem_COPY_INP_TMP.Dispose();
hv_CoordSystem_COPY_INP_TMP = "image";
}
//
if ((int)(new HTuple(hv_Color_COPY_INP_TMP.TupleEqual(""))) != 0)
{
//disp_text does not accept an empty string for Color.
hv_Color_COPY_INP_TMP.Dispose();
hv_Color_COPY_INP_TMP = new HTuple();
}
//
HOperatorSet.DispText(hv_WindowHandle, hv_String, hv_CoordSystem_COPY_INP_TMP,
hv_Row_COPY_INP_TMP, hv_Column_COPY_INP_TMP, hv_Color_COPY_INP_TMP, hv_GenParamName,
hv_GenParamValue);
//HOperatorSet.SetTposition(hv_WindowHandle, hv_Row_COPY_INP_TMP, hv_Column_COPY_INP_TMP);
//HOperatorSet.WriteString(hv_WindowHandle, hv_String);
hv_Color_COPY_INP_TMP.Dispose();
hv_Column_COPY_INP_TMP.Dispose();
hv_CoordSystem_COPY_INP_TMP.Dispose();
hv_Row_COPY_INP_TMP.Dispose();
hv_GenParamName.Dispose();
hv_GenParamValue.Dispose();
return;
}
catch (HalconException HDevExpDefaultException)
{
hv_Color_COPY_INP_TMP.Dispose();
hv_Column_COPY_INP_TMP.Dispose();
hv_CoordSystem_COPY_INP_TMP.Dispose();
hv_Row_COPY_INP_TMP.Dispose();
hv_GenParamName.Dispose();
hv_GenParamValue.Dispose();
throw HDevExpDefaultException;
}
}

HalconDotNet.HOperatorException:“HALCON error #5123: Wrong window type in operator disp_text”,没有找到合适解决方案,说是官方的BUG,后面尝试用 WriteString 发现可以用,简洁代码如下:
imgSource.HControl.hWindowCtrl.HalconWindow.SetTposition(result.LoactionY.ToInt(), result.LoactionX.ToInt());//设置输出位置
imgSource.HControl.hWindowCtrl.HalconWindow.SetColor(result.Color);//设置颜色
imgSource.HControl.hWindowCtrl.HalconWindow.SetFont("-Mono-Bold-40-");//设置字体
imgSource.HControl.hWindowCtrl.HalconWindow.WriteString(result.Message);//输出内容
完整设置字体不变形:.SetFont($"-Arial-50-*-1-*-*-1-") 50是字体大小

边栏推荐
- uniapp的request数据请求简单封装步骤
- Construction of knowledge map of financial securities and discovery of related stocks from the perspective of knowledge relevance
- FPGA时序约束分享04_output delay 约束
- FPGA timing constraint sharing 04_ Output delay constraint
- STM32 - capacitive touch button experiment
- Research on multi label patent classification based on pre training model
- Slam overview Reading Note 7: visual and visual intangible slam: state of the art, classification, and empirical 2021
- 力扣SQL语句习题,错题记录
- 正向代理与反向代理
- JS what is declaration in advance? The order of function and variable declaration in advance (the foreshadowing of execution context)
猜你喜欢
![[intensive reading of papers] grounded language image pre training (glip)](/img/3a/4ad136065acb8627df9e064ed8ef32.png)
[intensive reading of papers] grounded language image pre training (glip)

PROFINET 模拟器使用教程
![[note] logistic regression](/img/2b/07cc3c26b1b34fbf2f09edaa33668e.jpg)
[note] logistic regression

动态规划——股票买卖5

Interview eight part essay · TCP protocol

融合迁移学习与文本增强的中文成语隐喻知识识别与关联研究
![[related contents of multithreading]](/img/2d/c8bde21f13a5305ba54e9b52bd1e89.png)
[related contents of multithreading]

Construction of knowledge map of financial securities and discovery of related stocks from the perspective of knowledge relevance
How to solve cache avalanche, breakdown and penetration problems

Redis
随机推荐
<C> C语言哈希表使用
UnityUI方面处理(归纳与积累)
HDU1422 重温世界杯【DP】
Getting started for beginners: build your own blog with WordPress
Blocking queue
JS what is declaration in advance? The order of function and variable declaration in advance (the foreshadowing of execution context)
[medical industry] DICOM converter tools
Advanced MySQL III. storage engine
mysql保存数据提示:Out of range value for column错误
One of yolox improvements: add CBAM, Se, ECA attention mechanism
2022牛客多校二_ E I
知识关联视角下金融证券知识图谱构建与相关股票发现
Photo album based on gec6818 development board
基于GEC6818开发板的相册
Named entity recognition of Chinese electronic medical records based on Roberta WwM dynamic fusion model
Win11壁纸变黑怎么办?Win11壁纸变黑了的解决方法
Airport cloud business sign analysis
What if win11 wallpaper turns black? The solution of win11 wallpaper blackening
终于有人把面试必考的动态规划、链表、二叉树、字符串全部撸完了
Construction and empirical research of post talent demand analysis framework based on recruitment advertisement