当前位置:   article > 正文

halcon 皮革纹理表面缺陷检测

皮革纹理表面缺陷

  1. *获取图像大小
  2. get_image_size (Image, Width, Height)
  3. *将图像转化为频域图像
  4. rft_generic (Image, ImageFFT, 'to_freq', 'none', 'complex', Width)
  5. *生成一个高斯滤波核
  6. gen_gauss_filter (ImageGauss, 50, 50, 0, 'n', 'rft', Width, Height)
  7. *将频域图像核高斯滤波核进行卷积运算
  8. convol_fft (ImageFFT, ImageGauss, ImageConvol)
  9. *将卷积后的图像转换为空间域图像
  10. rft_generic (ImageConvol, IlluminationImage, 'from_freq', 'none', 'byte', Width)
  11. return ()
  12. * select_mask_obj selects one or more single elements of the object array
  13. * Objects and returns them in SelectedObjects.
  14. * The elements of Mask determine if the corresponding elements of Objects are selected.
  15. * If the value is greater than 0, the corresponding element is selected.
  16. *
  17. * Check number of elements
  18. count_obj (Objects, Number)
  19. if (Number != |Mask|)
  20. throw ('Number of elements in Objects and Mask do not match.')
  21. endif
  22. *
  23. * Check type of mask elements
  24. AllNumbers := sum(is_real_elem(Mask)) + sum(is_int_elem(Mask)) == |Mask|
  25. if (not AllNumbers and Mask != [])
  26. throw ('Invalid type: Elements of Mask must be integer or real numbers.')
  27. endif
  28. *
  29. * Use select_mask for tuples to generate a list of object indices.
  30. Indices := select_mask([1:|Mask|],Mask)
  31. select_obj (Objects, SelectedObjects, Indices)
  32. return ()
  1. * 关闭窗口
  2. dev_close_window ()
  3. *关闭程序计数器,图形变量,窗口图形更新
  4. dev_update_off ()
  5. *图像路径
  6. Path := 'lcd/mura_defects_texture_'
  7. *读取一张图像
  8. read_image (Image, Path + '01')
  9. *获取图像大小
  10. get_image_size (Image, Width, Height)
  11. *打开一个新窗口
  12. dev_open_window (0, 0, 640, 480, 'black', WindowHandle)
  13. *设置字体信息:字体大小为16,字体为mono,粗体,斜体
  14. set_display_font (WindowHandle, 14, 'mono', 'true', 'false')
  15. *设置区域的填充方式
  16. dev_set_draw ('margin')
  17. *设置线宽度
  18. dev_set_line_width (3)
  19. *设置输出对象显示颜色
  20. dev_set_color ('red')
  21. for F := 1 to 2 by 1
  22. read_image (Image, Path + F$'.2i')
  23. *获取彩色图像的三个通道,R,G,B
  24. decompose3 (Image, R, G, B)
  25. *缺陷是暗斑。 因此,通过原始图像减去背景照明,从而使缺陷变得更加明显。
  26. estimate_background_illumination (B, ImageFFT1)
  27. *用缺陷图减去背景图
  28. sub_image (B, ImageFFT1, ImageSub, 2, 100)
  29. *中值滤波
  30. median_image (ImageSub, ImageMedian, 'circle', 9, 'mirrored')
  31. *提取分水岭盆地
  32. watersheds_threshold (ImageMedian, Basins, 20)
  33. *计算灰度共生矩阵的灰度值特性,暗斑的能量非常低
  34. cooc_feature_image (Basins, ImageMedian, 6, 0, Energy, Correlation, Homogeneity, Contrast)
  35. *Energy小于0.05,Mask为1,否则为0
  36. Mask := Energy [<=] 0.05
  37. select_mask_obj (Basins, Defects, Mask)
  38. * 显示图像
  39. dev_display (Image)
  40. * 显示缺陷
  41. dev_display (Defects)
  42. stop()
  43. endfor

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/我家自动化/article/detail/262642?site
推荐阅读
相关标签
  

闽ICP备14008679号