文章目錄
- 文章專欄
- 前言
- 文章解讀
- 前言
- 創建ROI
- 案例1:直接截取ROI
- 手動截取ROI
- 總結
- ROI套路
- 獲取窗口句柄
- 截取ROI區域
- 獲取有效區域
- Stop組合
文章專欄
Halcon開發
Halcon學習 練習項目gitee倉庫
CSDN Major 博主Halcon文章推薦
前言
今天來看第三章內容,既然是零基礎,而且我還有大概3-4個月的時間準備,我還是老老實實從頭開始學機器視覺好了。
文章解讀
下面我將 Region Of Interest 命名為[找重點]
前言
- [找重點]可以減少無效信息和
- [找重點]經常用于找用于模板匹配的區域
創建ROI
- Halcon提供了一個[reduce_domain]的方法去獲取圖片域的ROI信息。
案例1:直接截取ROI
*讀取圖片文件
read_image (Image, 'mreut')
*得到一個坐標為(256,256),半徑為200的圓
gen_circle (ROI, 256, 256, 200)
*截取這個圓內的圖像信息
reduce_domain (Image, ROI, ImageReduced)
*找到亞像素精度的圖片信息
edges_sub_pix (ImageReduced, Edges, 'lanser2', 0.5, 20, 40)
*顯示Image/ROI/Edges
dev_display (Image)
dev_display (ROI)
dev_display (Edges)
效果
手動截取ROI
* critical_points.hdev: locate saddle point markers in an image
*
dev_update_window ('off')
* ****
* 獲取圖片信息
* ****
*加載圖片
read_image (Image, 'landmarks')
*獲取圖片大小
get_image_size (Image, Width, Height)
*設置線段等基本參數
dev_close_window ()
*打開圖片長寬的窗口,拿到WindowHandle的句柄
*dev_open_window (0, 0, Width, Height, 'black', WindowHandle)
*我更推薦使用自適應圖片大小的窗體這個算子
dev_open_window_fit_image (Image, 0, 0, -1, -1, WindowHandle)
dev_set_part (0, 0, Height - 1, Width - 1)
dev_set_line_width (3)
dev_set_color ('blue')
dev_set_draw ('margin')
dev_display (Image)
set_display_font (WindowHandle, 20, 'mono', 'true', 'false')
* ****
* 截取ROI
* ****
disp_message (WindowHandle, '使用鼠標左鍵截取圖片區域,右鍵退出', 'window', 12, 12, 'blue', 'false')
dev_set_color ('white')
*--獲取繪畫的Region區域
draw_region (Region, WindowHandle)
dev_display (Region)
disp_continue_message (WindowHandle, 'black', 'true')
stop ()
* ****
* step: create ROI
* ****
* 使用reduce_domain算子,設置圖片的ROI
reduce_domain (Image, Region, ImageReduced)
disp_continue_message (WindowHandle, 'black', 'true')
stop ()
* ****
* step: process image within ROI
* ****
critical_points_sub_pix (ImageReduced, 'facet', 1.5, 8, RowMin, ColumnMin, RowMax, ColumnMax, RowSaddle, ColSaddle)*清空整個窗口
dev_clear_window ()
*只顯示ROI部分內容
dev_display (ImageReduced)
dev_set_color ('yellow')
for i := 0 to |RowSaddle| - 1 by 1gen_cross_contour_xld (Cross, RowSaddle[i], ColSaddle[i], 25, 0.785398)dev_display (Cross)
endfor
stop ()
dev_update_window ('on')
運行結果
總結
ROI就是個截取部分區域的功能。有主動設置區域和被動設置區域兩種方法。
ROI套路
獲取窗口句柄
*打開圖片長寬的窗口,拿到WindowHandle的句柄
*dev_open_window (0, 0, Width, Height, 'black', WindowHandle)
*我更推薦使用自適應圖片大小的窗體這個算子
dev_open_window_fit_image (Image, 0, 0, -1, -1, WindowHandle)
截取ROI區域
* 參數設置ROI區域
gen_circle (ROI, 256, 256, 200)
* 使用WindowHandle窗口句柄,鼠標截取ROI區域
draw_region (ROI, WindowHandle)
獲取有效區域
* 使用reduce_domain句柄,獲取ROI區域信息
reduce_domain (Image, ROI, ImageReduced)* 可以使用其它算子去解析ROI的ImageReduce區域。
critical_points_sub_pix (ImageReduced, 'facet', 1.5, 8, RowMin, ColumnMin, RowMax, ColumnMax, RowSaddle, ColSaddle)*--如果想凸顯ROI區域,可以進行如下操作
*清空整個窗口
dev_clear_window ()
*只顯示ROI部分內容
dev_display (ImageReduced)
Stop組合
* 使用disp_continue_message和stop組合顯示F5繼續程序的提示
disp_continue_message (WindowHandle, 'black', 'true')
stop ()