HAlcon例子

气泡思想

* This example shows the use of the operator dyn_threshold for
* the segmentation of the raised dots of braille chharacters.
* The operator dyn_threshold is especially usefull if the
* background is inhomogeneously illuminated. In this example,
* the segmentation with a simple threshold is not possible
* because the brightness of the background increases from
* left to right.
* 
dev_update_off ()
* 
* Preparation
read_image (Image, 'photometric_stereo/embossed_01')
get_image_size (Image, Width, Height)
dev_get_window (WindowHandle)
if (is_handle_elem(WindowHandle) == true)* valid window handledev_resize_window_fit_image (Image, 0, 0, -1, -1)
elsedev_open_window_fit_image (Image, 0, 0, -1, -1, WindowHandle)
endif
set_display_font (WindowHandle, 16, 'mono', 'true', 'false')
dev_set_line_width (2)
* 
dev_display (Image)
Message := 'Original image'
disp_message (WindowHandle, Message, 'window', 12, 12, 'black', 'true')
disp_continue_message (WindowHandle, 'black', 'true')
stop ()
* 
* Use a strong mean filter on the image to blur out the braille points
*使用均值滤镜模糊盲文点,因为图像上的点有这不同光亮的
mean_image (Image, ImageMean, 59, 59)
* 
dev_display (ImageMean)
Message := 'Mean filtered image'
disp_message (WindowHandle, Message, 'window', 12, 12, 'black', 'true')
disp_continue_message (WindowHandle, 'black', 'true')
stop ()
* 
* Compare the original image with the blurred one and determine the
* region where the gray values of the two images differ by more than 15
*因只有小点点的光亮色彩不同,设定一个阈值,跟平均值相比交超出15的进行选中
dyn_threshold (Image, ImageMean, RegionDynThresh, 15, 'not_equal')
* 
dev_display (Image)
dev_display (RegionDynThresh)
Message := 'Regions segmented with dyn_threshold'
disp_message (WindowHandle, Message, 'window', 12, 12, 'black', 'true')
disp_continue_message (WindowHandle, 'black', 'true')
stop ()
* 
* Post-process the found regions
*先膨胀后收缩
closing_circle (RegionDynThresh, RegionClosing, 8.5)
*进行了开运算
opening_circle (RegionClosing, RegionOpening, 6.5)
*进行的打散
connection (RegionOpening, ConnectedRegions)
*在进行外接圆
smallest_circle (ConnectedRegions, Row, Column, Radius)gen_circle_contour_xld (ContCircle, Row, Column, Radius, 0, 6.28318, 'positive', 1)
* 
* Show the results
dev_display (Image)
dev_set_color ('green')
dev_display (ContCircle)
Message := 'Results of braille segmentation after morphology'
disp_message (WindowHandle, Message, 'window', 12, 12, 'black', 'true')
* 
dev_update_on ()

在这里插入图片描述

查找适合的圆及圆的面积和中心点

* ball.hdev: Inspection of Ball Bonding
* 窗口关闭
dev_update_window ('off')
dev_close_window ()
*开窗口
dev_open_window (0, 0, 728, 512, 'black', WindowID)
*读取图片
read_image (Bond, 'die/die_03')
*图像显示
dev_display (Bond)
*设置字体
set_display_font (WindowID, 14, 'mono', 'true', 'false')
*显示字体右下角
disp_continue_message (WindowID, 'black', 'true')
*停止
stop ()
*像素值范围找出来
threshold (Bond, Bright, 100, 255)
*装换成矩形
shape_trans (Bright, Die, 'rectangle2')
*设置一下颜色
dev_set_color ('green')
*设置一下宽度
dev_set_line_width (3)
*边缘
dev_set_draw ('margin')
*
dev_display (Die)
*显示边缘
disp_continue_message (WindowID, 'black', 'true')
stop ()
*减少范围,找出感兴趣区域
reduce_domain (Bond, Die, DieGrey)
*找到的0,到50区域
threshold (DieGrey, Wires, 0, 50)
*进行边缘提取
fill_up_shape (Wires, WiresFilled, 'area', 1, 100)
dev_display (Bond)
dev_set_draw ('fill')
dev_set_color ('red')
dev_display (WiresFilled)
*进行填充
disp_continue_message (WindowID, 'black', 'true')
stop ()
*形态学开运算,范围面积为15.5的圆进行放,放进去的
opening_circle (WiresFilled, Balls, 15.5)
dev_set_color ('green')
dev_display (Balls)
*能放进去的区域保留
disp_continue_message (WindowID, 'black', 'true')
stop ()
*找出圆形的区域
connection (Balls, SingleBalls)
*这些区域是不是特别的圆,不是特别的圆进行去掉
select_shape (SingleBalls, IntermediateBalls, 'circularity', 'and', 0.85, 1.0)
*对区域进行排序,在通过颜色排序
sort_region (IntermediateBalls, FinalBalls, 'first_point', 'true', 'column')
dev_display (Bond)
dev_set_colored (12)
dev_display (FinalBalls)
disp_continue_message (WindowID, 'black', 'true')
stop ()
*经外界圆得到中心点,半径
smallest_circle (FinalBalls, Row, Column, Radius)
*对变量进行赋值
NumBalls := |Radius|
*得到直径
Diameter := 2 * Radius
*所有的和除于个数得到平局
meanDiameter := mean(Diameter)
*找出数值最小的值
minDiameter := min(Diameter)
dev_display (Bond)
*进行显示面积,但是以像素为单位
disp_circle (WindowID, Row, Column, Radius)
dev_set_color ('white')
disp_message (WindowID, 'D: ' + Diameter$'.4', 'image', Row - 2 * Radius, Column, 'white', 'false')
dev_update_window ('on')

在这里插入图片描述

设置ROI金属凸轮正反位置判断

read_image(Image, 'D:/c++/image/6')*画ROI感兴趣区域
dev_open_window (0, 0, 512, 512, 'black', WindowHandle)
dev_display (Image)
Row1:=30
Column1:=31
Row2:=210
Column2:=212
draw_rectangle1_mod (WindowHandle, 100, 100, 200, 200, Row1, Column1, Row2, Column2)
*显示ROI区域 
gen_rectangle1(Rectangle, Row1, Column1, Row2, Column2)
*截取了ROI区域的
reduce_domain(Image, Rectangle, ImageReduced)
*提取亮度阈值
binary_threshold(ImageReduced, Region, 'max_separability', 'light', UsedThreshold)
*做开运算吧小的去掉
opening_rectangle1(Region, RegionOpening, 10, 10)
*有两个连到一起,运用腐蚀进行分开
erosion_circle(RegionOpening, RegionErosion, 7.5)
*进行打散
connection(RegionErosion, ConnectedRegions)dilation_circle(ConnectedRegions, ObjectSelected, 5.5)*设置字体
set_display_font ( WindowHandle, 44, 'mono', 'true', 'false')connection(ObjectSelected, ConnectedRegions1)
*得到roi区域面积,宽和高
area_center(Rectangle, Area, Row, Column)
*只找到上面的分割图,就可以
select_shape(ConnectedRegions1, SelectedRegions, 'row', 'and', 0, Row)
*找到一整个原件的宽度符合阈值
select_shape(SelectedRegions, SelectedRegions1, 'width', 'and', 100, 99999)
*查看有几个分割区域
count_obj(SelectedRegions1, Number)*循环判断是否有正反
for Index := 1 to Number  by 1*选中SelectedRegions1中的循环第几个 select_obj(SelectedRegions1, ObjectSelected, Index)*进行类接矩形,得到的矩形的左上和右下坐标位置inner_rectangle1(ObjectSelected, Row11, Column11, Row21, Column21)*inner_rectangle1(RegionDilation, Row11, Column11, Row21, Column21)*进行画图填充gen_rectangle1(Rectangle1, Row11, Column11, Row21, Column21)*进行了开运算opening_rectangle1(ObjectSelected, RegionOpeningTOU, 10,Row21-Row11+10 )*进行打散connection(RegionOpeningTOU, ConnectedRegionsT)*找到面积最大的select_shape_std(ConnectedRegionsT, SelectedRegionsT, 'max_area', 1)*把大的减去就是小头difference(ObjectSelected, SelectedRegionsT, RegionDifference)*进行打散connection(RegionDifference, ConnectedRegionsW)*找到最大的那个select_shape_std(ConnectedRegionsW, SelectedRegions2, 'max_area', 1)*找到了两头area_center(SelectedRegionsT, Area1, Row3, Column3)area_center(SelectedRegions2, Area2, Row4, Column4)*判断如果是前面的矩形大于后面的矩形就是NG,否则不是if(Column3 < Column4)*设置光标位置set_tposition(:: 窗口句柄,行坐标,列坐标:)set_tposition(WindowHandle, Row4, Column4)*在窗口打印字符串write_string( : : 窗口句柄, 字符串: )write_string(WindowHandle, 'NG')stop()elseset_tposition(WindowHandle, Row4, Column4)write_string(WindowHandle, 'OK')stop()endif
endfor

在这里插入图片描述

read_image(Image, 'D:/c++/image/5')*读取图像大小
get_image_size(Image, Width, Height)
*使用窗口
dev_clear_window()
dev_open_window(0, 0, Width/2, Height/2, 'black', WindowHandle)
dev_display(Image)*创建roi区域
draw_rectangle1(WindowHandle, Row1, Column1, Row2, Column2)*显示出来
gen_rectangle1(Rectangle, Row1, Column1, Row2, Column2)*roi区域剪辑出来
reduce_domain(Image, Rectangle, ImageReduced)*动态阈值处理,均值滤波
mean_image(ImageReduced, ImageMean, 3, 3)
dyn_threshold(ImageReduced, ImageMean, RegionDynThresh, 2, 'light')
*进行打散操作
connection(RegionDynThresh, ConnectedRegions)
*面积筛选
select_shape(ConnectedRegions, SelectedRegions, 'area', 'and', 350, 99999)
*进行找出边缘
fill_up(SelectedRegions, RegionFillUp)*进行开运算
opening_circle(RegionFillUp, RegionOpening, 40.5)
*进行外接圆过滤
select_shape(RegionOpening, SelectedRegions1, 'outer_radius', 'and', 80, 99999)
*有几个分割区域
count_obj(SelectedRegions1, Number)
*进行判断,有一个区域正常,否者不是
if(Number # 1)stop()
endif*进行膨胀变大
dilation_circle(SelectedRegions1, RegionDilation, 17.5)
*在进行裁剪得到想要的特征位置
reduce_domain(ImageMean, RegionDilation, ImageReduced1)
*显示边缘检测
binary_threshold(ImageReduced1, Region, 'max_separability', 'light', UsedThreshold)
*进行打散
connection(Region, ConnectedRegions1)count_obj(ConnectedRegions1, Number1)
*外界圆半径
select_shape(ConnectedRegions1, SelectedRegions2, 'outer_radius', 'and', 80, 99999)count_obj(SelectedRegions2, Number2)if(Number2 # 1)stop()
endif*用面积,和圆度进行区分筛选
select_shape(ConnectedRegions1, SelectedRegions3, ['area','circularity'], 'and', [180,0.8 ], [220,1])count_obj(SelectedRegions3, Number3)if(Number3 # 1)stop()
endifdev_display(SelectedRegions3)
dev_display(SelectedRegions2)
*找出圆的中心点
smallest_circle(SelectedRegions3, Row, Column, Radius)
*用中心点进行画圆
gen_circle(Circle, Row, Column, Radius)
*外边
fill_up(SelectedRegions2, RegionFillUp1)
*生成矩形
boundary(RegionFillUp1, RegionBorder, 'inner')
*外接矩形的参数
smallest_rectangle2(RegionFillUp1, Row3, Column3, Phi, Length1, Length2)
*生成一个矩形
gen_rectangle2(Rectangle1, Row, Column, Phi,  Radius,40)*一个矩形和第二生成的矩形进行相交的得到外面的矩形短线
intersection(Rectangle1, RegionBorder, RegionIntersection)*求出圆的中心点到矩形的位置
distance_pr(RegionIntersection, Row, Column, DistanceMin, DistanceMax)*第二种求出中心点算法
*画出中心点
gen_region_points(Region1, Row, Column)*求出中心点到直线的距离
distance_rr_min(RegionIntersection, Region1, MinDistance, Row11, Column11, Row21, Column21)*生成点到直线的距离
gen_region_line(RegionLines, Row11, Column11,Row21, Column21)

在这里插入图片描述

笛卡尔和条形码

* Read circularly printed bar codes.
* 
dev_update_off ()
get_system ('clip_region', Information)
set_system ('clip_region', 'true')
read_image (Image, 'circular_barcode')
get_image_size (Image, Width, Height)
dev_close_window ()
dev_open_window (0, 0, Width / 2, Height / 2, 'black', WindowHandle)
dev_set_colored (12)
dev_display (Image)
set_display_font (WindowHandle, 14, 'mono', 'true', 'false')
stop ()
* 
* Segment the ring on the CD that contains the bar code.
*找出0100内的
threshold (Image, Region, 0, 100)
*做闭区间
closing_circle (Region, Region, 3.5) 
*进行打散
connection (Region, ConnectedRegions)
*进行圆的宽和高进行过滤
select_shape (ConnectedRegions, Ring, ['width','height'], 'and', [550,550], [750,750])
*进行变成圆
shape_trans (Ring, OuterCircle, 'outer_circle')
*补齐,除去之前的圆环
complement (Ring, RegionComplement)
*进行打散
connection (RegionComplement, ConnectedRegions)
*在进行过滤
select_shape (ConnectedRegions, InnerCircle, ['width','height'], 'and', [450,450], [650,650])* Determine the parameters of the ring that contains the bar code.
*得到外圆的中心和半径
smallest_circle (Ring, Row, Column, OuterRadius)*得到内圆的中心和半径
smallest_circle (InnerCircle, InnerRow, InnerColumn, InnerRadius)
dev_set_color ('green')
dev_set_draw ('margin')
dev_set_line_width (3)
dev_display (Image)
dev_display (OuterCircle)
dev_display (InnerCircle)
stop ()
* 
* Now read the bar code. This is done by computing the polar transformation
* of the ring in the image that contains the bar code.
*自己设置的宽度
WidthPolar := 1440*高度是外圆减去内圆,再减去10
HeightPolar := round(OuterRadius - InnerRadius - 10)*进行笛卡尔转换,前面描述的是圆的坐标宽和高,后面描述的就是笛卡尔
polar_trans_image_ext (Image, PolarTransImage, Row, Column, rad(360), 0, OuterRadius - 5, InnerRadius + 5, WidthPolar, HeightPolar, 'bilinear')*黑变白,反转
invert_image (PolarTransImage, ImageInvert)
* 
* Since the bar code region is quite flat the image height is doubled.
*按给定因子缩放图像
zoom_image_factor (ImageInvert, ImageZoomed, 1, 2, 'weighted')*创建bar conde reder的模型
create_bar_code_model ([], [], BarCodeHandle)
* 
* Bars are small and the contrast is low; therefore the threshold is raised from 0.05 to 0.1.
*设置解码参数
set_bar_code_param (BarCodeHandle, 'element_size_min', 1.5)
set_bar_code_param (BarCodeHandle, 'meas_thresh', 0.3)*查找条码,进行解成128
find_bar_code (ImageZoomed, SymbolRegions, BarCodeHandle, 'Code 128', DecodedDataStrings)
dev_set_window_extents (-1, -1, WidthPolar / 2, HeightPolar)
dev_display (ImageZoomed)
dev_display (SymbolRegions)
set_system ('clip_region', Information)*设置文字
disp_message (WindowHandle, DecodedDataStrings, 'image', 10, 180, 'black', 'true')
stop ()
* 
* Transform the code region back to the original image and display it.
zoom_region (SymbolRegions, SymbolRegions, 1, 0.5)*将极坐标中的一个区域变换回笛卡尔坐标。
polar_trans_region_inv (SymbolRegions, CodeRegionCircular, Row, Column, rad(360), 0, OuterRadius - 5, InnerRadius + 5, WidthPolar, HeightPolar, Width, Height, 'nearest_neighbor')
dev_set_window_extents (-1, -1, Width / 2, Height / 2)
dev_display (Image)
dev_display (CodeRegionCircular)
disp_message (WindowHandle, DecodedDataStrings, 'window', 12, 12, 'black', 'true')

在这里插入图片描述

极坐标,光度立体,ocr

* This program demonstrates the use of the photometric stereo technique
* to read imprinted letters on a tire with a low cost setup.
* Even if the light sources are not very homogeneous and their
* orientation is only very roughly known, the text can be
* read robustly.
* 
* Initialization
PolarTransWidth := 512
PolarTransHeight := 80
* 
dev_close_window ()
dev_update_off ()
read_image (Images, 'photometric_stereo/tire_0' + [1:4])
select_obj (Images, ObjectSelected, 1)
dev_open_window_fit_image (ObjectSelected, 0, 0, -1, -1, WindowHandle)
set_display_font (WindowHandle, 16, 'mono', 'true', 'false')
for Index := 1 to 4 by 1select_obj (Images, ObjectSelected, Index)dev_display (ObjectSelected)disp_message (WindowHandle, 'Image ' + Index + '/4', 'window', 12, 12, 'black', 'true')wait_seconds (0.5)
endfor
* 
* We do not know the exact orientations of the light sources
* and therefore use only very rough estimates.
Tilts := [180,270,0,90]
Slants := [45,45,45,45]
* 
* Apply photometric stereo to determine the surface gradient
*用不同的光拍一张照片,使用光度立体
photometric_stereo (Images, HeightField, Gradient, Albedo, Slants, Tilts, 'gradient', 'poisson', [], [])
* 
* Calculate the surface curvature for easy segmentation of the letters
*计算曲面曲率以便于字母分割 
derivate_vector_field (Gradient, Result, 3, 'mean_curvature')* Display surface curvature,显示曲面曲率
dev_display (Result)
disp_message (WindowHandle, 'Surface curvature image', 'window', 12, 12, 'black', 'true')
disp_continue_message (WindowHandle, 'black', 'true')
stop ()
* * Segment text and base line
* The base line of the text is used to align
* the text horizontally (to simplify the OCR)*分段文本和基线*文本的基线用于对齐*文本水平显示(简化OCR
*基本的阈值处理
threshold (Result, Region, -0.2, -0.01)
connection (Region, ConnectedRegions)
*宽度和行进行过滤
select_shape (ConnectedRegions, BaseLine, ['width','row'], 'and', [600,280], [99999,350])* The base line is converted to an XLD contour
* to determine the radius of the line by fitting
* a circle to the contour
*基线将转换为XLD轮廓
*通过拟合确定直线半径的步骤
*与等高线成圆
gen_contour_region_xld (BaseLine, Contours, 'center')
*轮廓分割
segment_contours_xld (Contours, ContoursSplit, 'lines_circles', 8, 14, 12)*选取多种特征要求的XLD轮廓或多边形
select_contours_xld (ContoursSplit, SelectedContours, 'contour_length', 500, 1e10, -0.5, 0.5)*用圆近似XLD轮廓;
fit_circle_contour_xld (ContoursSplit, 'ahuber', -1, 0, 0, 3, 1, Row, Column, Radius, StartPhi, EndPhi, PointOrder)
* Generate circle contours for debugging (not used)
* gen_circle_contour_xld (ContCircle, Row, Column, Radius, StartPhi, EndPhi, PointOrder, 1)
* If more than 1 contour have been selected,
* choose the one with the largest radius
I := sort_index(Radius)[|Radius| - 1]
* If the point order of the fitted circle is 'positive',
* start and end angle have to be swapped for the polar transform
if (PointOrder[I] == 'positive')Tmp := StartPhi[I]StartPhi[I] := EndPhi[I]EndPhi[I] := Tmp
endif
* Perform a polar transform on the region
* to align the text with the base line
*极坐标通过圆进行拉直
polar_trans_region (Region, RegionPolarTrans, Row[I], Column[I], StartPhi[I], EndPhi[I], Radius[I] + PolarTransHeight, Radius[I], PolarTransWidth, PolarTransHeight, 'nearest_neighbor')
* Select characters from the transformed region
connection (RegionPolarTrans, ConnectedTransRegions)
select_shape (ConnectedTransRegions, Letters, ['height','width'], 'and', [40,20], [60,50])*进行相关位置排序
sort_region (Letters, SortedLetters, 'character', 'true', 'row')
* Create a black & white image from the region for the OCR,从OCR区域创建黑白图像* 将区域转换为二进制字节图像。
region_to_bin (SortedLetters, BinImage, 0, 255, 512, 100)
* Read text using a pre-trained classifier*从文件中读取OCR的.omc分类器,链接:https://www.cnblogs.com/xh6300/p/13392610.html
read_ocr_class_mlp ('Industrial_NoRej', OCRHandle)*使用 OCR 分类器对多个字符进行分类。 
do_ocr_multi_class_mlp (SortedLetters, BinImage, OCRHandle, Class, Confidence)
* 
* Display results
dev_display (ObjectSelected)
area_center (SortedLetters, Area, Row, Column)
dev_open_window (60, 12, PolarTransWidth, PolarTransHeight + 50, 'black', WindowHandle1)
set_display_font (WindowHandle1, 16, 'mono', 'true', 'false')
dev_set_part (-30, 0, PolarTransHeight - 1 + 20, PolarTransWidth - 1)
dev_display (SortedLetters)
DispRow := mean(Row) + 30
disp_message (WindowHandle1, 'OCR result after polar transform', 'window', 12, 12, 'black', 'true')
disp_message (WindowHandle1, Class, 'image', DispRow, Column - 18, 'black', 'true')

在这里插入图片描述

使用另一种能过滤区域

* ball_seq.hdev: Inspection of Ball Bonding
* 
dev_update_off ()*4张图
ImageNames := 'die/' + ['die_02','die_03','die_04','die_07']
dev_set_colored (12)
read_image (Bond, ImageNames[0])
get_image_size (Bond, Width, Height)
dev_close_window ()
dev_open_window (0, 0, Width, Height, 'black', WindowHandle)
set_display_font (WindowHandle, 16, 'mono', 'true', 'false')
dev_set_draw ('margin')
dev_set_line_width (3)
NumImages := |ImageNames|
for I := 0 to NumImages - 1 by 1read_image (Bond, ImageNames[I])dev_display (Bond)*找出灰色的最小和最大的,min_max_gray (Bond, Bond, 0, Min, Max, Range)*用最大的灰度值减去80threshold (Bond, Bright, Max - 80, 255)shape_trans (Bright, Die, 'rectangle2')dev_display (Die)reduce_domain (Bond, Die, DieGrey)min_max_gray (Die, Bond, 0, Min, Max, Range)threshold (DieGrey, Wires, 0, Min + 30)*1100的进行填充fill_up_shape (Wires, WiresFilled, 'area', 1, 100)*进行开运算opening_circle (WiresFilled, Balls, 9.5)connection (Balls, SingleBalls)*选出矩形select_shape_std (SingleBalls, Rect, 'rectangle1', 90)*在把矩形给去掉difference (SingleBalls, Rect, IntermediateBalls)gen_empty_region (Forbidden)expand_gray (IntermediateBalls, Bond, Forbidden, RegionExpand, 4, 'image', 6)*开运算变成了圆opening_circle (RegionExpand, RoundBalls, 15.5)sort_region (RoundBalls, FinalBalls, 'first_point', 'true', 'column')smallest_circle (FinalBalls, Row, Column, Radius)NumBalls := |Radius|Diameter := 2 * RadiusmeanDiameter := sum(Diameter) / NumBallsmimDiameter := min(Diameter)dev_display (RoundBalls)if (I != NumImages)disp_continue_message (WindowHandle, 'black', 'true')endifstop ()
endfor

在这里插入图片描述

使用放射变换让图片确定位置,在进行,面积和灰度进行判断

* This example demonstrates an application from the pharmaceutical
* industry. The task is to check the content of automatically filled
* blisters. The first image (reference) is used to locate the chambers
* within a blister shape as a reference model, which is then used to
* realign the subsequent images along to this reference shape. Using
* blob analysis the content of each chamber is segmented and finally
* classified by a few shape features.
* 
dev_close_window ()
dev_update_off ()
read_image (ImageOrig, 'blister/blister_reference')
dev_open_window_fit_image (ImageOrig, 0, 0, -1, -1, WindowHandle)
set_display_font (WindowHandle, 14, 'mono', 'true', 'false')
dev_set_draw ('margin')
dev_set_line_width (3)
* 
* In the first step, we create a pattern to cut out the chambers in the
* subsequent blister images easily.access_channel (ImageOrig, Image1, 1)*阈值分割 
threshold (Image1, Region, 90, 255)
shape_trans (Region, Blister, 'convex')*角度,用于计算区域的方位信息 
orientation_region (Blister, Phi)*找出中心点,和角度
area_center (Blister, Area1, Row, Column)
*要放射变换,
vector_angle_to_rigid (Row, Column, Phi, Row, Column, 0, HomMat2D)
affine_trans_image (ImageOrig, Image2, HomMat2D, 'constant', 'false')*根据得到的中心点和角度对其进行画框
gen_empty_obj (Chambers)
for I := 0 to 4 by 1Row := 88 + I * 70for J := 0 to 2 by 1Column := 163 + J * 150gen_rectangle2 (Rectangle, Row, Column, 0, 64, 30)concat_obj (Chambers, Rectangle, Chambers)endfor
endfor
affine_trans_region (Blister, Blister, HomMat2D, 'nearest_neighbor')
*与原的矩形进行相减得到,
difference (Blister, Chambers, Pattern)
union1 (Chambers, ChambersUnion)
orientation_region (Blister, PhiRef)
PhiRef := rad(180) + PhiRef
area_center (Blister, Area2, RowRef, ColumnRef)
* 
* 
* Each image read will be aligned to this pattern and reduced to the area of interest,
* which is the chambers of the blister
Count := 6
for Index := 1 to Count by 1read_image (Image, 'blister/blister_' + Index$'02')threshold (Image, Region, 90, 255)connection (Region, ConnectedRegions)select_shape (ConnectedRegions, SelectedRegions, 'area', 'and', 5000, 9999999)shape_trans (SelectedRegions, RegionTrans, 'convex')* * Align pattern along blister of imageorientation_region (RegionTrans, Phi)area_center (RegionTrans, Area3, Row, Column)vector_angle_to_rigid (Row, Column, Phi, RowRef, ColumnRef, PhiRef, HomMat2D)affine_trans_image (Image, ImageAffineTrans, HomMat2D, 'constant', 'false')* * Segment pillsreduce_domain (ImageAffineTrans, ChambersUnion, ImageReduced)decompose3 (ImageReduced, ImageR, ImageG, ImageB)var_threshold (ImageB, Region, 7, 7, 0.2, 2, 'dark')connection (Region, ConnectedRegions0)closing_rectangle1 (ConnectedRegions0, ConnectedRegions, 3, 3)fill_up (ConnectedRegions, RegionFillUp)select_shape (RegionFillUp, SelectedRegions, 'area', 'and', 1000, 99999)opening_circle (SelectedRegions, RegionOpening, 4.5)connection (RegionOpening, ConnectedRegions)select_shape (ConnectedRegions, SelectedRegions, 'area', 'and', 1000, 99999)shape_trans (SelectedRegions, Pills, 'convex')* * Classify segmentation results and display statisticscount_obj (Chambers, Number)gen_empty_obj (WrongPill)gen_empty_obj (MissingPill)for I := 1 to Number by 1select_obj (Chambers, Chamber, I)intersection (Chamber, Pills, Pill)area_center (Pill, Area, Row1, Column1)if (Area > 0)min_max_gray (Pill, ImageB, 0, Min, Max, Range)if (Area < 3800 or Min < 60)concat_obj (WrongPill, Pill, WrongPill)endifelseconcat_obj (MissingPill, Chamber, MissingPill)endifendfor* dev_clear_window ()dev_display (ImageAffineTrans)dev_set_color ('forest green')count_obj (Pills, NumberP)count_obj (WrongPill, NumberWP)count_obj (MissingPill, NumberMP)dev_display (Pills)if (NumberMP > 0 or NumberWP > 0)disp_message (WindowHandle, 'Not OK', 'window', 12, 12 + 600, 'red', 'true')elsedisp_message (WindowHandle, 'OK', 'window', 12, 12 + 600, 'forest green', 'true')endif* Message := '# Correct pills: ' + (NumberP - NumberWP)Message[1] := '# Wrong pills  :  ' + NumberWPMessage[2] := '# Missing pills:  ' + NumberMP* Colors := gen_tuple_const(3,'black')if (NumberWP > 0)Colors[1] := 'red'endifif (NumberMP > 0)Colors[2] := 'red'endifdisp_message (WindowHandle, Message, 'window', 12, 12, Colors, 'true')dev_set_color ('red')dev_display (WrongPill)dev_display (MissingPill)if (Index < Count)disp_continue_message (WindowHandle, 'black', 'true')endifstop ()
endfor

在这里插入图片描述

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/79009.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

vue3的生命周期

1.vue3生命周期官方流程图 2.vue3中的选项式生命周期 vue3中的选项式生命周期钩子基本与vue2中的大体相同&#xff0c;它们都是定义在 vue实例的对象参数中的函数&#xff0c;它们在vue中实例的生命周期的不同阶段被调用。生命周期函数钩子会在我们的实例挂载&#xff0c;更新…

竞赛 基于机器视觉的火车票识别系统

文章目录 0 前言1 课题意义课题难点&#xff1a; 2 实现方法2.1 图像预处理2.2 字符分割2.3 字符识别部分实现代码 3 实现效果最后 0 前言 &#x1f525; 优质竞赛项目系列&#xff0c;今天要分享的是 基于机器视觉的火车票识别系统 该项目较为新颖&#xff0c;适合作为竞赛…

23下半年学习计划

大二上学期计划 现在已经是大二了&#xff0c;java只学了些皮毛&#xff0c;要学的知识还有很多&#xff0c;新的学期要找准方向&#xff0c;把要学的知识罗列&#xff0c;按部就班地完成计划&#xff0c;合理安排时间&#xff0c;按时完成学习任务。 学习node.js&#xff0c…

运维学习之部署Grafana

sudo nohup wget https://dl.grafana.com/oss/release/grafana-10.1.1.linux-amd64.tar.gz &后台下载压缩包&#xff0c;然后按一下回车键。 ps -aux | grep 15358发现有两条记录&#xff0c;就是还在下载中。 ps -aux | grep 15358发现有一条记录&#xff0c;并且tail …

一百七十八、ClickHouse——海豚调度执行ClickHouse的.sql文件

一、目的 由于数仓的ADS层是在ClickHouse中&#xff0c;即把Hive中DWS层的结果数据同步到ClickHouse中&#xff0c;因此需要在ClickHouse中建表&#xff0c;于是需要海豚调度执行ClickHouse的.sql文件 二、实施步骤 &#xff08;一&#xff09;第一步&#xff0c;海豚建立Cl…

Python in Visual Studio Code 2023年9月更新

作者&#xff1a;Courtney Webster - Program Manager, Python Extension in Visual Studio Code 排版&#xff1a;Alan Wang 我们很高兴地宣布 Visual Studio Code 的 Python 和 Jupyter 扩展将于 2023 年 9 月发布&#xff01; 此版本包括以下内容&#xff1a; • 将 Python …

使用 Nginx 实现企业微信域名配置中的校验文件跳转

背景 在企业微信中配置业务域名时&#xff0c;通常需要在该域名的根路径下放置一个校验文件&#xff0c;以验证域名的所有权。然而&#xff0c;如果该域名是第三方的&#xff0c;你可能无法直接在根路径下放置文件。在这种情况下&#xff0c;你可以使用 Nginx 来实现校验文件的…

2023 Google 开发者大会|Mobile开发专题追踪

文章目录 前言大会介绍涉及内容MobileWebAICloud Mobile开发专题多终端应用的开发适配大屏视频流可穿戴设备电视新的设计中心 构建高质量的应用高级相机和媒体功能用户的安全和隐私更精细的视觉体验 小结 前言 哈喽大家好&#xff0c;我是阿Q。近期&#xff0c;【2023 Google …

python: excel假期时间提取统计

# encoding: utf-8 # 版权所有 2023 涂聚文有限公司 # 许可信息查看&#xff1a; # 描述&#xff1a; # Author : geovindu,Geovin Du 涂聚文. # IDE : PyCharm 2023.1 python 311 # Datetime : 2023/9/3 7:04 # User : geovindu # Product : PyCharm # Proje…

Redis 数据一致性方案的分析与研究

点击下方关注我&#xff0c;然后右上角点击...“设为星标”&#xff0c;就能第一时间收到更新推送啦~~~ 一般的业务场景都是读多写少的&#xff0c;当客户端的请求太多&#xff0c;对数据库的压力越来越大&#xff0c;引入缓存来降低数据库的压力是必然选择&#xff0c;目前业内…

常用数据库的 API - 开篇

API API 这个词在大多数人看来可能和 CNS 差不多&#xff0c;前者天天听说就是用不上&#xff0c;后者天天读就是发不了。 不过&#xff0c;通过今天的一个简短介绍&#xff0c;今后 API 这个东西你就用上了&#xff0c;因为在文章最后我将会展示一个最最基础且高频的 API 使…

【CSS3】

文章目录 1.简介2.边框3.圆角4.背景5.渐变CSS3 径向渐变6.文本效果7.字体8.2D转换9.3D转换10.过渡11.动画12.多列13.用户界面14.按钮 ​ 1.简介 模块 CSS3 被拆分为"模块"。旧规范已拆分成小块&#xff0c;还增加了新的。 一些最重要 CSS3 模块如下&#xff1a; 选…

时序数据库

时序数据库在许多应用领域中得到广泛应用,包括物联网(IoT)监控、应用性能监控(APM)、日志分析、金融数据分析、工业自动化和能源管理等。一些知名的开源和商业时序数据库包括InfluxDB、Prometheus、OpenTSDB、TimescaleDB和Kdb+等。 上图是一个典型的时序数据示意图,由…

慢查询SQL如何优化

一.什么是慢SQL? 慢SQL指的是Mysql中执行比较慢的SQL,排查慢SQL最常用的方法是通过慢查询日志来查找慢SQL。Mysql的慢查询日志是Mysql提供的一种日志记录&#xff0c;它用来记录Mysql中响应时间超过long_query_time值的sql,long_query_time的默认时间为10s. 二.查看慢SQL是否…

网络原理(一)网络基础,包括IP ,网络相关的定义

网络基础&#xff0c;包括IP &#xff0c;网络相关的定义 网络基础冲突域广播域DNSNATNAPT 网络基础 以下图片是书上的网图。 什么是IP地址&#xff1f; IP地址&#xff08;Internet Protocol Address&#xff09;是指互联网协议地址&#xff0c;又译为网际协议地址。P地址是…

PHP自己的框架2.0设置常量并绑定容器(重构篇三)

目录 1、设置常量并绑定容器 2、容器增加设置当前容器的实例和绑定一个类实例当容器 3、将常量绑定到容器中 4、运行效果 1、设置常量并绑定容器 2、容器增加设置当前容器的实例和绑定一个类实例当容器 //设置当前容器的实例public static function setInstance($instance){…

SW的stp文件转成CAD格式文件学习笔记

SW的stp文件转成CAD格式文件 文章目录 SW的stp文件转成CAD格式文件另存为part文件&#xff08;零件图&#xff09;另存为CAD文件 另存为part文件&#xff08;零件图&#xff09; 如图一个STP文件&#xff0c;右上角标注是什么文件呢 另存为零件图&#xff0c;即另存为part …

Python语言概述

​ 视频版教程 Python3零基础7天入门实战视频教程 Python作为一门非常流行的高级编程语言&#xff0c;自从22年开始&#xff0c;TIOBE编程语言排行榜Python一直排第一。 Python简洁高效&#xff0c;丰富的应用场景&#xff0c;受到广大程序员&#xff0c;科研工作者的喜爱。 …

基于图像形态学处理和边缘提取算法的路面裂痕检测matlab仿真

目录 1.算法运行效果图预览 2.算法运行软件版本 3.部分核心程序 4.算法理论概述 5.算法完整程序工程 1.算法运行效果图预览 2.算法运行软件版本 matlab2022a 3.部分核心程序 [Rr,Cc] size(Image1);% 获取 Image1 矩阵的大小&#xff08;行数和列数&#xff09; % 创…

哨兵1号(Sentinel-1)SAR卫星介绍

1. 哥白尼计划 说起欧空局的哨兵1号&#xff0c;就不得不先说一下欧空局的“哥白尼计划”。 欧空局的哥白尼计划&#xff08;Copernicus Programme&#xff09;是欧空局与欧盟合作的一项极其重要的地球观测计划。该计划旨在提供免费开放的、可持续的地球观测数据&#xff0c…