python - 使用OpenCV做裂缝检测的问题
问题描述
import cv2 as cv
import numpy as np
src = cv.imread("Image set/Positive/00010.jpg")
cv.imshow("input", src)
gray = cv.cvtColor(src, cv.COLOR_BGR2GRAY)
ret, binary = cv.threshold(gray, 0, 255, cv.THRESH_BINARY_INV | cv.THRESH_OTSU)
se = cv.getStructuringElement(cv.MORPH_RECT, (10, 10), (-1, -1))
binary = cv.morphologyEx(binary, cv.MORPH_OPEN, se)
cv.imshow("binary", binary)
contours,hierachy=cv.findContours(binary,cv.RETR_EXTERNAL,cv.CHAIN_APPROX_SIMPLE)
height, width = src.shape[:2]
for c in range(len(contours)):
x, y, w, h = cv.boundingRect(contours[c])
area = cv.contourArea(contours[c])
if h > (height//2):
continue
if area < 150:
continue
cv.rectangle(src, (x, y), (x+w, y+h), (0, 0, 255), 1, 8, 0)
cv.drawContours(src, contours, c, (0, 255, 0), 1, 8)
cv.imshow("result", src)
cv.imwrite("result.jpg", src)
cv.waitKey(0)
cv.destroyAllWindows()
以上是我写的代码,我使用OpenCV尝试检测裂缝,但我只检测到部分裂缝而不是所有裂缝。我不知道如何解决这个问题。
解决方案
推荐阅读
- javascript - 如何将文本重新格式化为不同的模式?
- docker - 如何在 docker compose 文件上设置 MySQL 和 phpmyadmin
- javascript - JS 不会将导入和声明的变量读入 console.log
- javascript - 尝试读取从反应 js 中的 API 返回的响应时获取未定义
- google-compute-engine - 谷歌云控制台 - 找不到 phpmyadmin 404
- selection - bootstrap-vue 选择带有过滤器选项的组件?
- android - 为什么 API Level 29 WiFi 连接需要密码?
- php - PHP Traits 通用和单个(单独)属性范围
- c# - 如何将滚动条与 RichTextBox 中的行匹配
- swift - 在 TableViewCell 中使用协议发现 Nil