当前位置: 首页 > news >正文

python-opencv划痕检测-续

python-opencv划痕检测-续

这次划痕检测,是上一次划痕检测的续集。

处理的图像如下:
在这里插入图片描述

这次划痕检测,我们经过如下几步:
第一步:读取灰度图像
第二步:进行均值滤波
第三步:进行图像差分
第四步:阈值分割
第五步:轮廓检测
第六步:绘制轮廓,并将过滤面积较小的轮廓,且进行轮廓填充

代码如下:

import cv2
import copy
import math
import matplotlib.pyplot as plt
import matplotlib as mpl
import numpy as np
import ospath=r'sta.bmp'img=cv2.imread(path)def histogram_equalization(image):gray = imageequalized = cv2.equalizeHist(gray)return equalized# 图像去噪 - 高斯滤波
def gaussian_filtering(image):blurred = cv2.GaussianBlur(image, (3, 3), 0)return blurred#img=gaussian_filtering(img)#img = histogram_equalization(img)
img_gray=cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)def cv_show(name,img):cv2.imshow(name,img)#cv2.waitKey(0),接收0,表示窗口暂停cv2.waitKey(0)#销毁所有窗口cv2.destroyAllWindows()img_mean_3 = cv2.blur(img_gray, (10, 10))#图像差分
img_diffence=cv2.subtract(img_mean_3,img_gray)img_diffence1=img_mean_3-img_grayplt.subplot(131)
plt.imshow(img_diffence,'gray')
plt.title('img_diffence')#阈值分割_,img_binary=cv2.threshold(img_diffence,5,255,cv2.THRESH_BINARY_INV)
plt.subplot(132)
plt.imshow(img_binary,'gray')
plt.title('img_binary')plt.show()
#cv_show('imggrayimg=img_binarycout,hi=cv2.findContours(grayimg,cv2.RETR_TREE,cv2.CHAIN_APPROX_SIMPLE)#hierarchy 轮廓层级关系
result=np.zeros(img.shape,np.uint8)#绘制轮廓边框
for  i in range(len(cout)):moms=cv2.moments(cout[i])#计算轮廓的矩area=moms['m00']#面积if area>50 and area<1000:cv2.drawContours(result,cout,i,(0,0,255),thickness=cv2.FILLED,hierarchy=hi,maxLevel=0)cv_show('result',result)os.system("pause")

结果如下:
在这里插入图片描述
在这里插入图片描述

http://www.lryc.cn/news/242540.html

相关文章:

  • c++[string实现、反思]
  • c++版本opencv计算灰度图像的轮廓点
  • 【05】ES6:函数的扩展
  • Ubuntu20.04安装搜狗输入法
  • linux的基础命令
  • linux查询某个进程使用的内存量
  • list的总结
  • c语言数字转圈
  • Apache Superset数据分析平台如何实现公网实时远程访问数据【内网穿透】
  • HarmonyOS应用开发实战—登录页面【ArkTS】
  • @RequestMapping
  • 操作系统 应用题 例题+参考答案(考研真题)
  • 免费获取GPT-4的五种工具
  • XTU OJ 1146 矩阵乘法学习笔记
  • 基于官方YOLOv4开发构建目标检测模型超详细实战教程【以自建缺陷检测数据集为例】
  • 1、Docker概述与安装
  • 论文笔记——FasterNet
  • 计算机组成原理-固态硬盘SSD
  • Electron+VUE3开发简版的编辑器【文件预览】
  • docker、elasticsearch8、springboot3集成备忘
  • 【Lombok使用详解】
  • Tars框架 Tars-Go 学习
  • 基于JAVA+SpringBoot+VUE+微信小程序的前后端分离咖啡小程序
  • 2015年全国硕士研究生入学统一考试管理类专业学位联考数学试题——解析版
  • 优秀软件设计特征与原则
  • 设备管理系统-设备管理软件
  • 物联网AI MicroPython学习之语法 I2S音频总线接口
  • Day31| Leetcode 455. 分发饼干 Leetcode 376. 摆动序列 Leetcode 53. 最大子数组和
  • 基于C#实现赫夫曼树
  • Android 13.0 app进程保活白名单功能实现