日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 人工智能 > ChatGpt >内容正文

ChatGpt

Halcon资料:image,region,xld三者如何转化和保存

發(fā)布時間:2025/3/21 ChatGpt 75 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Halcon资料:image,region,xld三者如何转化和保存 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

一、說明

????????image,region,xld需要保存,最基本的思路是,將他們約定俗成,轉化成image類型保存。以下圍繞相關內容,進行紀要:

二、 圖像的兩個保存方法

算子是<1>和<2>:

2.1? write_image 函數


函數原型:write_image( Image:: Format, FillColor, FileName:)
功能:將圖像數據保存為圖像文件,目前支持的圖像格式有:tiff、bmp、jpeg、jp2、png和ima。

參數列表

  • 第1個參數Image是輸入變量,即圖像數據
  • 第2個參數Format是輸入變量,即圖像格式
  • 第3個參數FillColor是輸入變量,表示不屬于圖像區(qū)域的灰度像素填充值,默認值為0。
  • 第4個參數FileName是輸入變量,為保存圖像的名字

舉例

write_image( Image , 'bmp' , 0 , 'D:/image/1' )

除此之外,圖像還有其它保存法:

2.2 dump_window_image函數

????????該函數把WindowHandle所代表的窗口內全部像素保存成圖像。因此只要把圖片、region、字符提示都顯示在圖像窗口上,就會將整個窗口像截屏一樣保存到Image內

函數原型:dump_window_image( :Image:WindowHandle:)?

函數功能:將窗口內容拷貝到一個人圖像容器變量中。

參數列表

  • 第1個參數Image是輸出變量,即圖像數據
  • 第2個參數是窗口的句柄

舉例:將窗口內容保存進入image文件。

dump_window_image( Image , WindowHandle) //圖像名,窗口句柄 write_image( Image , 'bmp' , 0 , 'D:/image/1' )

例:將圖像直接保存

將窗口內容,全部保存圖像到設定目錄下。(保存帶有Region的圖像)。

例如:

dev_close_window () read_image (Image, 'black') threshold (Image, Region, 128, 255) dev_open_window_fit_image (Image, 0, 0, -1, -1, WindowHandle) dev_display (Image) dev_display (Region) disp_continue_message (WindowHandle, 'black', 'true') dump_window_image (Image1, WindowHandle) write_image (Image1, 'jpg', 0,'d:/1.jpg')

運行結果如下:

注意:如圖將“Run F5”也保存了,可見并非理想的數據。

三、圖像image、區(qū)域region和輪廓xld的相互轉換

3.1 將region轉xld

????????在擬合部分的邊緣提取和輪廓分割之間會用到,用boundary提取區(qū)域邊緣輸出的是區(qū)域(region),而輪廓分割需輸入xld輪廓,而所以需要轉換。
方法1

gen_contour_region_xld (SelectedRegions, Contours, 'border')

方法2:先將區(qū)域轉換骨架,然后再提取骨架輪廓

skeleton (Region2, Skeleton2) gen_contours_skeleton_xld (Skeleton2, Contours, 1, 'filter')

3.2、輪廓xld轉region

方法1

gen_region_contour_xld (SelectedXLD, RegionXLD, 'filled')

方法2:

*UnionContours1為輪廓 sort_contours_xld (UnionContours1, SortedContours, 'upper_left', 'true', 'column') count_obj (UnionContours1, Number) *將輪廓轉換成區(qū)域 gen_empty_obj (Line) for i := 1 to Number by 1 select_obj (SortedContours, ObjectSelected, i) get_contour_xld (ObjectSelected, Row, Col) gen_region_polygon (Region, Row, Col) concat_obj (Line, Region, Line) endfor

3.3、xld/region轉換成image

例1

*Halcon感興趣區(qū)域填充特定顏色 color24 := [255,0,0] color8 := 255 gen_region_contour_xld (UnionContoursCircles, Region1, 'filled') region_to_bin(Region, Binary, 0, 255, Width, Height) overpaint_region (Binary, Region1, color8, 'fill') write_image (Binary, 'bmp', 0, 'E:/Org.bmp')

例2

*創(chuàng)建空白圖像,將得到的區(qū)域貼到上面 get_image_size (ImageReduced, Width1, Height1) gen_image_proto (ImageReduced, ImageCleared, 128) paint_region (Region, ImageCleared, ImageResult1, 255, 'fill')

例3:xld->region->image

*無效set_system ('init_new_image', 'false') gen_region_contour_xld (ObjectSelected, Region, 'filled') gen_image_const (NewImage, 'byte', Width, Height) *Create an image with a specified constant gray value gen_image_proto (NewImage, ImageCleared1, 255) *Paint regions into an image paint_region (Region, ImageCleared1, ImageResult, 0, 'fill')write_image (ImageResult, 'jpeg', 0, 'D:/1111.jpg')*Overpaint regions in an image gen_image_proto (NewImage, ImageCleared2, 255) overpaint_region(ImageCleared2, Region, 0, 'fill')

注:paint_region 和overpaint_region最終的輸出結果是一樣的

四、從image裁剪需要的區(qū)域,成為新的image

這個當然已經歪曲了原圖像的內容,將其局部作為新圖處理。

read_image(Image,'monkey') gen_rectangle1 (ROI_0, 38.03, 46.95, 328.43, 312.37) reduce_domain (Image, ROI_0, ImageReduced) crop_domain(ImageReduced, ImagePart) write_image(ImagePart, 'bmp', 0, 'e:/1.bmp')

運行結果為:

總結

以上是生活随笔為你收集整理的Halcon资料:image,region,xld三者如何转化和保存的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。