|

变量名 | 类 型 | 静态 | 数组 | 备 注 | img | 多维矩阵类 | | | cap | 视频采集类 | | | product | myproduct | | 0 | grayImage | 多维矩阵类 | | | binImage | 多维矩阵类 | | | ontours | 多维数组点2i类 | | | Contours | 多维矩阵类 | | | i | 整数型 | | | area | 双精度小数型 | | | M | 矩类 | | | center_x | 双精度小数型 | | | center_y | 双精度小数型 | | | rect | 矩形2i类 | | | isNew | 逻辑型 | | | h | 双精度小数型 | | | v | 双精度小数型 | | | p | myproduct | | | idx | 整数型 | | | objs | defect_object | | 0 | roi | 多维矩阵类 | | | j | 整数型 | | |
cap. 打开 (“E:\新建文件夹\\缺陷检测代码素材\1.mp4”, 0, ) 如果真 (cap. 已打开 () = 假) 视觉_控制台输出 (“打开视频文件失败.”) 返回 (-1 ) 判断循环首 (cap. 读 (img )) 视觉_颜色空间转换 (img, grayImage, #颜色_BGR转GRAY, 0 ) 视觉_阈值 (grayImage, binImage, 128, 255, #阈值_二进制 ) 视觉_查找轮廓 (binImage, ontours, , #检测_外部, #逼近_任何, ) Contours = 矩阵 (grayImage. 尺寸2i (), , #八位无符号整数_单通道, 0 )  计次循环首 (ontours. 尺寸 (), i )  area = 视觉_轮廓面积 (ontours. 取点2i类数组 (i - 1 ), 假)  如果真 (area > 18000 )   M = 视觉_计算矩 (ontours. 取点2i类数组 (i - 1 ), , 真)    center_x = M. m10 () ÷ M. m00 ()   center_y = M. m01 () ÷ M. m00 ()   rect = 视觉_最大轮廓矩形 (ontours. 取点2i类数组 (i - 1 ))    isNew = 真    如果真 (center_x > 100 )    计次循环首 (取数组成员数 (product ), i )     h = 取绝对值 (center_x - product [i ].cx )     v = 取绝对值 (center_y - product [i ].cy )     如果真 (h < 25 且 v < 25 )      isNew = 假            product [i ].cx = center_x       product [i ].cy = center_y       product [i ].rect = rect           计次循环尾 ()    如果真 (isNew )     p.cx = center_x      p.cy = center_y      p.rect = rect      idx = idx + 1      p.index = idx     加入成员 (product, p )             计次循环尾 ()  计次循环首 (取数组成员数 (product ), i )  如果真 (product [i ].cx > 600 )  到循环尾 () roi = img.感兴区域 (product [i].rect, ) defect_detect (roi, objs ) 视觉_矩形 (img, product [i ].rect, 标量 (0, 255, 0 ), 1, 8, 0 ) 视觉_放置文本 (img, 到文本 (product [i ].index ), 点2i (product [i ].rect.左边, product [i ].rect.顶边 ), #字体_衬线_简单, 1, 标量 (255, 255, 0 ), 1, 8, 假)  计次循环首 (取数组成员数 (objs ), j )   objs [j ].rect.左边 = objs [j ].rect.左边 + product [i ].rect.左边    objs [j ].rect.顶边 = objs [j ].rect.顶边 + product [i ].rect.顶边   视觉_矩形 (img, objs [j ].rect, 标量 (0, 0, 255 ), 1, 8, 0 )    如果真 (objs [j ].type = 1 )      视觉_放置文本 (img, “scratch”, 点2i (objs [j ].rect.左边, objs [j ].rect.顶边 ), #字体_衬线_简单, 0.5, 标量 (255, 255, 0 ), 1, 8, 假)   如果真 (objs [j ].type = 2 )      视觉_放置文本 (img, “blot”, 点2i (objs [j ].rect.左边, objs [j ].rect.顶边 ), #字体_衬线_简单, 0.5, 标量 (255, 255, 0 ), 1, 8, 假)      计次循环尾 () 计次循环尾 () 视觉_显示图像 (“小白鼠”, img ) 视觉_等待按键 (30 ) 判断循环尾 ()返回 (0 ) |
defect_detect | | | |
roi | 多维矩阵类 | | | | objj | defect_object | | | |
变量名 | 类 型 | 静态 | 数组 | 备 注 | obj | defect_object | | 0 | grayImage | 多维矩阵类 | | | binImage | 多维矩阵类 | | | contours | 多维数组点2i类 | | | i | 整数型 | | | area | 双精度小数型 | | | rect | 矩形2i类 | | | defect_roi | 多维矩阵类 | | | threImage | 多维矩阵类 | | | contours_defect | 多维数组点2i类 | | | mask | 多维矩阵类 | | | result | 多维矩阵类 | | | hist | 多维矩阵类 | | | ranges | 小数型 | | 2 | h | 整数型 | | | hh | 双精度小数型 | | 256 | sum | 双精度小数型 | | | hist_sum_scratch | 双精度小数型 | | | hist_sum_blot | 双精度小数型 | | | type | 整数型 | | | info | defect_object | | | 视觉_颜色空间转换 (roi, grayImage, #颜色_BGR转GRAY, 0 ) 视觉_阈值 (grayImage, binImage, 128, 255, #阈值_二进制 ) 视觉_查找轮廓 (binImage, contours, , #检测_树, #逼近_任何, ) 计次循环首 (contours. 尺寸 (), i ) area = 视觉_轮廓面积 (contours. 取点2i类数组 (i - 1 ), 假) 如果真 (area > 100 且 area < 15000 )  rect = 视觉_最大轮廓矩形 (contours. 取点2i类数组 (i - 1 ))   defect_roi = roi. 感兴区域 (rect, )  视觉_颜色空间转换 (defect_roi, grayImage, #颜色_BGR转GRAY, 0 )  视觉_阈值 (grayImage, threImage, 128, 255, #阈值_二进制_取反 )  视觉_查找轮廓 (threImage, contours_defect, , #检测_外部, #逼近_任何, )  mask = 矩阵 (grayImage. 尺寸2i (), , #八位无符号整数_单通道, 0 ) 视觉_填充多边形 (mask, contours_defect, , , 标量 (255, 255, 255 ), 8, 0, ) 视觉_按位_与 (grayImage, mask, result, )   ranges [1 ] = 0   ranges [2 ] = 255  视觉_计算直方图 (result, 0, , hist, 256, ranges, 真, 假)  h = hist. 数据指针 ()  计次循环首 (256, i )   hh [i ] = 指针到小数 (h )   h = h + 4    sum = sum + hh [i ]  计次循环尾 ()  变量循环首 (90, 135, 1, i )   hist_sum_scratch = hist_sum_scratch + hh [i ]  变量循环尾 ()  hist_sum_scratch = hist_sum_scratch ÷ sum   变量循环首 (15, 90, 1, i )   hist_sum_blot = hist_sum_blot + hh [i ]  变量循环尾 ()  hist_sum_blot = hist_sum_blot ÷ sum   type = 0   如果真 (hist_sum_scratch > 0.1 )   type = 1   如果真 (hist_sum_blot > 0.3 )   type = 2      info.type = type   info.rect = rect  加入成员 (obj, info )  计次循环尾 ()objj = obj
|
|