沒看過這麼複雜的處理程序!
真的需要這麼麻煩?
- ***找模型區域 可以進行 "前處理"
- ***使用合理的模型區域隊原始圖形 建立shape model 如果擔心輪廓不夠好 那就是 shape model 不適用
- ***或是要限制模型區域 及輪廓對比條件等參數 應該不是把待測圖也進行一番前處理在比對
- read_image(Image_Input, 'Image_20250109141448255.jpg')
- * write_image (Image_Input1, 'bmp', 0, 'C:/Users/13980/Desktop/test0123/0123input.bmp')
- * read_image (Image_Input, 'C:/Users/13980/Desktop/test0123/0123input.bmp')
- get_image_size (Image_Input, Width, Height)
- dev_open_window (0, 0, Width, Height, 'black', WindowHandle)
- dev_display(Image_Input)
- set_display_font(WindowHandle, 14, 'mono', 'true', 'false')
- dev_set_draw ('margin')
- dev_set_line_width(3)
- *设定被提取的颜色
- is_get_color :=1
- Row_Get_Color_Point:=862
- Column_Get_Color_Point:=685
- *颜色提取
- decompose3(Image_Input,Red_Input,Green_Input,Blue_Input)
- trans_from_rgb(Red_Input, Green_Input, Blue_Input, Hue_Input, Saturation_Input, Value_Input, 'hsv')
- Extract_H:=13
- Extract_S:=255
- Extract_V:=155
- if (is_get_color==1)
- get_grayval (Hue_Input, Row_Get_Color_Point, Column_Get_Color_Point, Extract_H)
- get_grayval (Saturation_Input, Row_Get_Color_Point, Column_Get_Color_Point, Extract_S)
- get_grayval (Value_Input, Row_Get_Color_Point, Column_Get_Color_Point, Extract_V)
- endif
- * 对S分量图像进行阈值处理
- threshold (Saturation_Input, HighSaturation, Extract_S-100, Extract_S+100)
- * 提取H分量图像
- reduce_domain (Hue_Input, HighSaturation, HighHue)
- * 针对提取的H分量进行阈值处理
- threshold (HighHue, Result, Extract_H-10, Extract_H+10)
- * 再将其从原始图像中提取出来
- reduce_domain (Image_Input, Result, ImageReduced)
- * 最后显示读取图片
- dev_clear_window ()
- dev_display(ImageReduced)
- * write_image (ImageReduced, 'bmp', 0, 'C:/Users/13980/Desktop/test0123/0123.bmp')
- * 提取出来的颜色图转黑白
- rgb1_to_gray (ImageReduced, GrayImage)
- opening_circle(GrayImage, RegionOpening, 3)
- closing_circle(RegionOpening, RegionOpening, 3)
- gen_rectangle1 (Rectangle, 750, 250, 1000, 950)
- reduce_domain(GrayImage,RegionOpening, Image_Shape)
- reduce_domain(Image_Shape,Rectangle, Image_Shape2)
- scale_image (Image_Shape2, Image_Shape2, 1, 255)
- if (is_get_color==1)
- * 创建轮廓模板 ,这里在进行开闭运算为了降低轮廓复杂度
- opening_circle(Image_Shape2, Image_Shape3,5)
- closing_circle(Image_Shape3, Image_Shape4, 20)
- reduce_domain(Image_Shape2,Image_Shape4, Image_Shape5)
- scale_image (Image_Shape5, Image_Shape6, 1, 255)
- write_image (Image_Shape6, 'bmp', 0, 'd:/012355.bmp')
- read_image (image_222,'d:/012355.bmp')
- * convert_image_type (Image_Shape6, image_222, 'byte')
- copy_image (Image_Shape6, DupImage)
- dev_clear_window ()
- dev_display(Image_Shape6)
- *提取边缘
- edges_sub_pix (Image_Shape6, Edges, 'canny', 1, 20, 40)
- *训练模板
- [i][b] **找到shape model 的區域 使用原始圖檔進行訓練! 不要進行奇怪的填充[/b][/i]
-
- [b][i] create_shape_model(Image_Input, 'auto', -0.39, 0.79, 'auto', 'auto', 'use_polarity', 'auto', 'auto', ModelID1)[/i][/b]
- *匹配此模板
- [b]find_shape_model (Image_Input, ModelID_shape_xld, -0.39, 0.79, 0.5, 1, 0.5, 'least_squares', 0, 0.9, Row, Column, Angle, Score)[/b]
- *匹配此模板
- [i][b] write_shape_model(ModelID_shape_xld,'d:/ModelID_shape_xld2.shapexldmodel')[/b][/i]
- [i][b] inspect_shape_model (Image_Input, ModelImages, ModelRegions, 4, 30)[/b][/i]
- [i][b] create_scaled_shape_model (Image_Input, 'auto', -0.39, 0.79, 'auto', 0.9, 1.1, 'auto', 'auto', 'use_polarity', 'auto', 'auto', ModelID)[/b][/i]
- [i][b] get_shape_model_contours(ModelIDContours, ModelID, 1)[/b][/i]
- [i][b] find_scaled_shape_model (Image_Input, ModelID, -0.39, 0.78, 1, 1.1, 0.2, 1, 0.5, 'least_squares', 0, 0.9, Row1, Column1, Angle1, Scale, Score1)[/b][/i]
- else
- Row_Base:=196.746
- Column_Base:=280.996
- * 匹配轮廓
- read_shape_model('C:/Users/13980/Desktop/test0123/ModelID_shape_xld2.shapexldmodel',ModelID_shape_xld)
- *find_shape_model (ImageReduced, ModelID_shape_xld, -0.39, 0.79, 0.5, 1, 0.5, 'least_squares', 0, 0.9, Row, Column, Angle, Score)
- *提取边缘
- *edges_sub_pix (Image_Shape2, Edges, 'canny', 1, 20, 40)
- find_shape_model (Image_Shape2, ModelID_shape_xld, -0.39, 0.79, 0.3, 1, 0.5, 'least_squares', 0, 0.4, Row, Column, Angle, Score)
- get_shape_model_contours(ModelContours, ModelID_shape_xld, 1)
- dev_clear_window ()
- dev_display(Image_Shape2)
- dev_set_color('green')
- dev_display(ModelContours)
- Row_Offset:=Row-Row_Base
- Column_Offset:=Column-Column_Base
-
- endif
- *模板坐标
复制代码 |