halcon/c++接口基礎 之 控制參數

HALCON/C++可以處理各種不同類型的字母數字混合的控制參數,如下:

  • 離散數字(long)
  • 浮點數字(double)
  • 字符串(char*)

控制參數的一個特殊形式是句柄,提供了途徑去訪問復雜的數據類型,像windows,圖像獲取設備,用于形狀匹配的模型。實際上,在內部,句柄總是以離散數字(long)表示。

HALCON/C++使用tuple表示控制參數的容器類。另外,tuple是多態的,可以包含各種類型的參數。為了實現這個目的,HCtrlVal被介紹,請看下一節。

The Basic Class for Control Parameters

HCtrlVal是類HTuple的基類,并且一般對于用戶隱藏。因為它僅僅用于臨時的類型轉換。核心點時它包含三種基本的控制參數類型,即離散數字(long),浮點類型(double),字符串類型(char*)。HCtrlVal提供了以下成員函數:

typedef long long Hlong;HCtrlVal(void)
Default constructor. HCtrlVal(Hlong l)
Constructing a value from long.HCtrlVal(int l)
Constructing a value from int.HCtrlVal(double d)
Constructing a value from double. HCtrlVal(const char *s)
Constructing a value from char *. HCtrlVal(const HCtrlVal &v)
Copy constructor. ~HCtrlVal(void)
Destructor. HCtrlVal& operator = (const HCtrlVal &v)
Assignment operator. int ValType() const
Type of a value (O: Hlong, int; 1: float, double; 2: string). 
見:
enum HCtrlType {LongVal   = LONG_PAR, DoubleVal = DOUBLE_PAR,StringVal = STRING_PAR,UndefVal  = UNDEF_PAR
};operator int(void) const
Conversion to int. operator Hlong(void) const
Conversion to long. operator double(void) const
Conversion to double. operator const char*(void) const
Conversion to char *. double D() const
Accessing a value and conversion to double. Hlong L() const
Accessing a value and conversion to Hlong. int I() const
Accessing a value and conversion to int. const char *S() const
Accessing a value and conversion to char *. HCtrlVal operator + (const HCtrlVal &val) const
Adding two values. HCtrlVal operator - (const HCtrlVal &val) const
Subtracting two values. HCtrlVal operator * (const HCtrlVal &val) const
Multiplying two values. HCtrlVal operator / (const HCtrlVal &val) const
Division of two values. 

這里面和我們前面介紹的HPixVal與int等各類型的轉換相似,HCtrlVal也提供了與基本類型的相互轉換和封裝。

另外有幾個轉換函數比較重要:

  • double D() const
    Accessing a value and conversion to double.

  • long L() const
    Accessing a value and conversion to long.

  • int I() const
    Accessing a value and conversion to int.

  • const char *S() const
    Accessing a value and conversion to char *.

Tuples

HTuple建立在HCtrlVal的基礎上。它實現了動態長度的HCtrlVal對象的數組。默認的構造函數定義了一個空的數組(Num()==0)。并且數組可以通過賦值動態地擴展。內存管理,如重新分配、釋放,也由類自身管理。訪問數組的序號是0到Num()-1

下面介紹幾個重要的成員函數,更詳細地請訪問:%HALCONROOT%\include\cpp。

  • HTuple(int length, const HTuple \&value)
    構造指定長度的常數組,同 tuple_gen_const.
  • HCtrlVal &operator [] (int i)
    設置第i個元素
  • HCtrlVal operator [] (int i) const
    讀取第i個元素

數組算術運算

  • HTuple operator + (const HTuple &val) const
    Adding two tuples element by element, similar to the operator tuple_add. The arrays have to be of the same size.

  • HTuple operator + (double &val) const
    HTuple operator + (int &val) const
    Adding a number to each element of the tuple, similar to the operator tuple_add.

  • HTuple operator - (const HTuple &val) const
    Subtracting two tuples element by element, similar to the operator tuple_sub. The arrays have to be of the same size.

  • HTuple operator - (double &val) const
    HTuple operator - (int &val) const
    Subtracting a number from each element of the tuple, similar to the operator tuple_sub.

  • HTuple operator * (const HTuple &val) const
    Multiplying two tuples element by element, similar to the operator tuple_mult. The arrays have to be of the same size.

  • HTuple operator * (double &val) const
    HTuple operator * (int &val) const
    Multiplying a number with each element of the tuple, similar to the operator tuple_mult.

  • HTuple operator / (const HTuple &val) const
    Division of two tuples element by element, similar to the operator tuple_div. The arrays have to be of the same size.

  • HTuple operator / (double &val) const
    HTuple operator / (int &val) const
    Division of each element of the tuple by a number, similar to the operator tuple_div.

例1

#include "HalconCpp.h"
using namespace Halcon;
#include "HIOStream.h"
#if !defined(USE_IOSTREAM_H)
using namespace std;
#endifvoid main()
{HTuple  t;cout << t.Num() << '\n';             // The length of the tuple is 0t[0] = 0.815;                        // Assigning values to the tuplet[1] = 42;t[2] = "HAL";cout << t.Num() << '\n';             // The length of the tuple is 3cout << "HTuple = " << t << '\n';    // Using the << operator double d = t[0];                     // Accessing the tuple, if theint   l = t[1];                     // the types of the elements//Hlong l=t[1];const char  *s = t[2];               // are known// Accessing the tuple, if the types of the elements are knownprintf("Values: %g %ld %s\n", t[0].D(), t[1].L(), t[2].S());
}

句柄封裝類

最突出的類是HWindow.自從Halcon 6.1開始,HALCON/C++也提供了訪問文件或者功能的句柄類,如圖像獲取裝置,測量,或者基于形狀的匹配。

Windows

HWindow以很方便的方式提供了Halcon窗口,halcon窗口的屬性很容易改變。并且圖像、區域、多邊形等都可以顯示在窗口上。下面列舉常用的成員函數:


創建窗口:

  • HWindow(int Row=0, int Column=0,
    int Width=-1, int Height=-1,
    int Father = 0, const char *Mode = “”,
    const char *Host = “”)
    Default constructor. The constructed window is opened.

  • ~HWindow(void)
    Destructor. This closes the window.

  • void Click(void) const
    等待用戶在窗口點擊鼠標

  • HDPoint2D GetMbutton(int *button) const
    HDPoint2D GetMbutton(void) const

    獲取鼠標點擊時的坐標,和鼠標的類型。見 get_mbutton.
    鼠標類型:
    1:
    Left button,
    2:
    Middle button,
    4:
    Right button.

  • HDPoint2D GetMposition(int *button) const
    HDPoint2D GetMposition(void) const
    獲取鼠標的位置和鼠標的點擊類型,不要求鼠標一定要點擊。見 get_mposition.

  • HCircle DrawCircle(void) const
    Waiting for the user to draw a circle in the window, see the reference manual entry of draw_circle.

  • HEllipse DrawEllipse(void) const
    Waiting for the user to draw an ellipse in the window, see the reference manual entry of draw_ellipse.

  • HRectangle1 DrawRectangle1(void) const
    Waiting for the user to draw a rectangle parallel to the coordinate axis in the window, see the reference manual entry of draw_rectangle1.

  • HRectangle2 DrawRectangle2(void) const
    Waiting for the user to draw a rectangle with an arbitrary orientation and size in the window, see the reference manual entry of draw_rectangle2.

例2

#include "HalconCpp.h"
using namespace Halcon;void main()
{HImage  image("E:\\halcon\\images\\control_unit.png");     // Reading an image from a fileHWindow w;                         // Opening an appropriate windowimage.Display(w);                  // Display the imagew.SetLut("change2");               // Set a lookup tablew.Click();                         // Waiting for a mouse clickw.SetLut("default");               // Set the default lookup tablew.SetPart(100, 100, 200, 200);        // Set a part of the windowimage.Display(w);w.Click();// Adapting the part to the image againw.SetPart(0, 0, image.Height() - 1, image.Width() - 1);image.Display(w);HRegionArray regs = image.Regiongrowing(1, 1, 4, 100);w.SetDraw("margin");w.SetColored(6);regs.Display(w);w.Click();image.Display(w);w.SetShape("rectangle1");regs.Display(w);
}

窗口在從文件中讀取圖像后打開,這意味著窗口被縮放到圖像的大小。
The lookup table is changed afterwards, and the program waits for a mouse click in the window. A part of the image is zoomed now, and the program waits again for a mouse click in the window. By applying a region growing algorithm from the HALCON library (Regiongrowing) regions are generated and displayed in the window. Only the margin of the regions is displayed. It is displayed in 6 different colors in the window. The example ends with another way of displaying the shape of regions. The smallest rectangle parallel to the coordinate axes surrounding each region is displayed.


打賞

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/news/258878.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/258878.shtml
英文地址,請注明出處:http://en.pswp.cn/news/258878.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

C#使用多態求方形面積周長和圓的面積周長

class class1{public static void Main(string[] args){//使用多態求矩形面積與周長和圓的面積與周長Shape cl new Circle(5);double clarea cl.GetArea();double clpar cl.GetPerimeter();Console.WriteLine("這個圓的面積是{0},周長是{1}", Math.Round(clarea, …

Java編程的邏輯 (84) - 反射

?本系列文章經補充和完善&#xff0c;已修訂整理成書《Java編程的邏輯》&#xff0c;由機械工業出版社華章分社出版&#xff0c;于2018年1月上市熱銷&#xff0c;讀者好評如潮&#xff01;各大網店和書店有售&#xff0c;歡迎購買&#xff0c;京東自營鏈接&#xff1a;http://…

C# 與 VC Dll 傳輸信息

考慮&#xff1a; 使用string類型傳送&#xff1b; 在VC Dll中解析字符&#xff1b; 使用 string 類型將解析的類型傳送到C#程序中&#xff1b; 建立VC解析的函數&#xff0c;提高代碼可重用性轉載于:https://www.cnblogs.com/ein-key5205/p/3597612.html

linux下python_linux下python安裝

Python2.5的安裝方法&#xff1a; 1&#xff0e;下載源代碼 http://www.python.org/ftp/python/2.5.2/Python-2.5.2.tar.bz2 2&#xff0e; 安裝 $ tar –jxvf Python-2.5.2.tar.bz2 $ cd Python-2.5.2 $ ./configure $ make $ make install 3. 測試 在命令行下輸入python&…

灰度圖像的8位平面分解

所謂灰度圖像&#xff0c;即指8位256顏色的圖像。將圖像的每一位分別取出來&#xff0c;我們就可以將一幅圖像分解開來&#xff0c;形成8幅圖像。下面我們分別介紹使用matlab分解圖像與使用halcon/c分解圖像的方法。 matlab8位分解 clc; clear all; A imread(lena.tif); % 顯…

Win10 UAP 綁定

Compiled DataBinding in Windows Universal Applications (UAP) http://nicksnettravels.builttoroam.com/post/2015/04/26/Compiled-DataBinding-in-Windows-Universal-Applications-(UAP).aspx 讀寫剪貼板 http://www.cnphp6.com/archives/80079 Learn how the Reversi samp…

HDUOJ----4501小明系列故事——買年貨(三維背包)

小明系列故事——買年貨 Time Limit: 5000/2000 MS (Java/Others) Memory Limit: 65535/32768 K (Java/Others)Total Submission(s): 2146 Accepted Submission(s): 953 Problem Description春節將至&#xff0c;小明要去超市購置年貨&#xff0c;于是小明去了自己經常去…

css 橫線_atom.css正式發布,從此跟CSS框架說拜拜。

atom.css 大家好&#xff0c;我寫了一個css庫atom.css&#xff0c;蠻好用的&#xff0c;所以忍不住分享給大家。(https://github.com/MatrixAge/atom.css)起因寫HTML幾年了&#xff0c;再到如今的JSX&#xff0c;最大的感受不是枯燥&#xff0c;而是眼花。寫樣式的時候&#xf…

halcon模板匹配學習(一) Matching 初印象

什么是模板匹配呢&#xff1f;簡單而言&#xff0c;就是在圖像中尋找目標圖像&#xff08;模板&#xff09;&#xff0c;或者說&#xff0c;就是在圖像中尋找與模板圖像相似部分的一種圖像處理技術。依賴于選擇的方法不同&#xff0c;模板匹配可以處理各種情形下的變換&#xf…

第五章 面向方面編程___AOP入門

上一篇講了 AOP 和 OOP 的區別&#xff0c;這一次我們開始入門 AOP 。實現面向方面編程的技術&#xff0c;主要分為兩大類&#xff1a; 一是 采用動態代理技術&#xff0c;利用截取消息的方式&#xff0c;對該消息進行裝飾&#xff0c;以取代原有對象行為的執行&#xff1b; 二…

java將xml中的標簽名稱轉為小寫_深入學習Java Web(七): JSTL標簽庫

本文轉自與博客園一杯涼茶的博客.在之前我們學過在JSP頁面上為了不使用腳本&#xff0c;所以我們有了JSP內置的行為、行為只能提供一小部分的功能&#xff0c;大多數的時候還是會用java腳本&#xff0c;接著就使用了EL表達式&#xff0c;基本上EL表達式看似能滿足我們的要求&am…

python中*args和**args的不同

上一段代碼&#xff0c;大家感受一下 def test_param(*args): print(args) def test_param2(**args): print(args) test_param(test1,test2) >>>(test1,test2) test_param2(p1test1,p2test2) >>>{p1:test1, p2:test2} python提供了兩種特別的方法來定義函數的…

halcon模板匹配學習(二) 準備模板

如下&#xff0c;我們將介紹匹配的第一個操作&#xff1a;準備模板 初始時刻&#xff0c;我們準備好參考圖像&#xff0c;并對其做一定的處理&#xff0c;然后我們需要從參考圖像中導出模板&#xff0c;也就是將參考圖像裁剪成所謂的模板圖像。獲取模板圖像可以通過設置ROI來完…

揭秘繼承技術之虛函數

虛函數 調用虛函數時函數行為將根據對象所屬類的不同而變化。 父類指針或引用指向子類對象時&#xff0c;可訪問子類重寫方法&#xff08; virtual函數&#xff09;但無法訪問在父類中沒有定義的子類方法和數據成員。 #include <iostream>using namespace std;class Supe…

java中GET方式提交和POST方式提交

java中GET方式提交的示例&#xff1a; /*** 獲取關注列表;* return*/SuppressWarnings("unchecked")public static ArrayList<String> getUserList() {StringBuffer bufferRes new StringBuffer();ArrayList<String> users null;try {URL realUrl new…

基于HALCON的模板匹配方法總結

很早就想總結一下前段時間學習HALCON的心得&#xff0c;但由于其他的事情總是抽不出時間。去年有過一段時間的集中學習&#xff0c;做了許多的練習和實驗&#xff0c;并對基于HDevelop的形狀匹配算法的參數優化進行了研究&#xff0c;寫了一篇《基于HDevelop的形狀匹配算法參數…

js 數組移除_2020前端面試--常見的js面試題

&#xff08;答案持續更新...&#xff09; 1.簡述同步和異步的區別js是一門單線程語言&#xff0c;所謂"單線程"&#xff0c;就是指一次只能完成一件任務。如果有多個任務&#xff0c;就必須排隊&#xff0c;前面一個任務完成&#xff0c;再執行后面一個任務&#xf…

spring-自動加載配置文件\使用屬性文件注入

在上一篇jsf環境搭建的基礎上 , 加入spring框架 , 先看下目錄結構 src/main/resources 這個source folder 放置web項目所需的主要配置,打包時,會自動打包到WEB-INF下 首先看下pom.xml,需要引入一些依賴項: 1 <project xmlns"http://maven.apache.org/POM/4.0.0" x…

pygame碰撞檢測

最近在學Pygame,花一段時間做了一個異常簡陋版的"打磚塊". 這次重點說一下困擾我比較長時間的碰撞檢測(個人太菜..). 按照網上教程比較普遍的方法(也可能是我沒看見別的),碰撞檢測依次計算移動物體與被碰撞物體各個邊之間坐標是否相交.例如下列代碼,檢測小球與窗口的…

2017-5-4 進程

進程&#xff1a;一個應用程序就是一個進程開啟某個進程Process.Start("文件縮寫名");通過絕對路徑開啟某個進程Process p new Process();p.StartInfo new ProcessStartInfo("要打開的程序絕對路徑");p.Start(); 獲取全部開啟的進程&#xff1a;Process.…