- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
我正在尝试获取图像中的框角。以下是示例图像,它们的阈值结果和箭头后面的右侧是我需要的结果。您之前可能在 slack 上也看过这些图片,因为我将这些图片用于我在 slack 上的示例问题。
以下是允许我到达中间图像的代码。
import cv2
import numpy as np
img_file = 'C:/Users/box.jpg'
img = cv2.imread(img_file, cv2.IMREAD_COLOR)
img = cv2.blur(img, (5, 5))
hsv = cv2.cvtColor(img, cv2.COLOR_BGR2HSV)
h, s, v = cv2.split(hsv)
thresh0 = cv2.adaptiveThreshold(s, 255, cv2.ADAPTIVE_THRESH_GAUSSIAN_C, cv2.THRESH_BINARY_INV, 11, 2)
thresh1 = cv2.adaptiveThreshold(v, 255, cv2.ADAPTIVE_THRESH_GAUSSIAN_C, cv2.THRESH_BINARY_INV, 11, 2)
thresh2 = cv2.adaptiveThreshold(v, 255, cv2.ADAPTIVE_THRESH_GAUSSIAN_C, cv2.THRESH_BINARY_INV, 11, 2)
thresh = cv2.bitwise_or(thresh0, thresh1)
cv2.imshow('Image-thresh0', thresh0)
cv2.waitKey(0)
cv2.imshow('Image-thresh1', thresh1)
cv2.waitKey(0)
cv2.imshow('Image-thresh2', thresh2)
cv2.waitKey(0)
opencv 中是否有任何方法可以为我做这件事。我尝试了扩张 cv2.dilate()
和侵 eclipse cv2.erode()
但它在我的案例中不起作用。或者如果不行,那么可以采用其他替代方法它 ?谢谢
图像的 Canny 版本......左边是低阈值,右边是高阈值
最佳答案
下面是@dhanushka 方法的 python 实现
import cv2
import numpy as np
# load color image
im = cv2.imread('input.jpg')
# smooth the image with alternative closing and opening
# with an enlarging kernel
morph = im.copy()
kernel = cv2.getStructuringElement(cv2.MORPH_RECT, (1, 1))
morph = cv2.morphologyEx(morph, cv2.MORPH_CLOSE, kernel)
morph = cv2.morphologyEx(morph, cv2.MORPH_OPEN, kernel)
kernel = cv2.getStructuringElement(cv2.MORPH_RECT, (2, 2))
# take morphological gradient
gradient_image = cv2.morphologyEx(morph, cv2.MORPH_GRADIENT, kernel)
# split the gradient image into channels
image_channels = np.split(np.asarray(gradient_image), 3, axis=2)
channel_height, channel_width, _ = image_channels[0].shape
# apply Otsu threshold to each channel
for i in range(0, 3):
_, image_channels[i] = cv2.threshold(~image_channels[i], 0, 255, cv2.THRESH_OTSU | cv2.THRESH_BINARY)
image_channels[i] = np.reshape(image_channels[i], newshape=(channel_height, channel_width, 1))
# merge the channels
image_channels = np.concatenate((image_channels[0], image_channels[1], image_channels[2]), axis=2)
# save the denoised image
cv2.imwrite('output.jpg', image_channels)
如果您处理的图像是发票(或在白色背景上有大量文本),则上述代码不会给出好的结果。为了在此类图像上获得良好的效果,请删除
gradient_image = cv2.morphologyEx(morph, cv2.MORPH_GRADIENT, kernel)
并将morph
obj传递给split函数并移除for循环中的~
符号
关于python - 从阈值图像opencv python中去除噪声,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42065405/
我正在用 R 编写程序。我卡在这里。 我有像这样的矢量 X=c(84.05, 108.04, 13.95, -194.05, 64.03, 208.05, 84.13, 57.04) 我想在用 180
我正在编写一个应用程序,该应用程序涉及使用手指或手写笔在屏幕上书写。我有那部分工作。在 ACTION_DOWN 上,开始绘制;在 ACTION_MOVE 上,添加线段;在 ACTION_UP 上,完成
我正在尝试构建 OCR 以从图像中提取文本,我正在使用轮廓来形成文本字符的边界, 经过几次更改 cv2.threshold 的试验后,我在形成文本字符的边界时得到了最适合的轮廓。 #files = o
我正在尝试使用 OpenCV 的 cv::threshold函数(更具体 THRESH_OTSU ),只是我想用蒙版(任何形状)来做,以便在计算过程中忽略外部(背景)。 图像是单 channel (必
对于学校项目,我试图用 Python 编写一个程序来跟踪学生的运动。为了做到这一点,我正在使用 OpenCV。 在互联网上查找了一些教程后,我注意到几乎每个人都使用阈值来实现这一点,因为几乎每一步都需
我使用 jest 来驱动 selenium 测试,它报告一个需要 12 秒的测试缓慢(持续时间以红色突出显示)。在这种情况下,12 秒就可以了。 如何将阈值配置为 30 秒? 最佳答案 Jest is
我想找到 list1 中与 list2 中的值足够接近的值(基于指定的阈值),即与下面的代码类似的功能。然而,与 pyhton 的 set 交集相比,下面的 intersect_with_thresh
我正在尝试创建一张图表上有两个系列并带有阈值选项的浮线图。我知道当我只有 1 个系列时如何启用阈值(就像这里 http://people.iola.dk/olau/flot/examples/thre
我已正确应用 d3 (v 4.0) 直方图函数对数据数组进行分箱。我的代码如下所示: var bins = d3.histogram() .domain([data_points_min,
我正在使用带有自然语言全文的 Mysql FULLTEXT 搜索,不幸的是,我遇到了 FULLTEXT 50% 阈值,如果给定的关键字出现在总行数的 50% 时间,则不允许我搜索行。 我搜索并找到了一
关闭。此题需要details or clarity 。目前不接受答案。 想要改进这个问题吗?通过 editing this post 添加详细信息并澄清问题. 已关闭 8 年前。 Improve th
这是我的绘图数据 var data = [{ data: [[4, 80], [8, 50], [9, 130]], color: "r
是否可以制作Canny忽略短边还是忽略低梯度边?在我的例子中,我将卡片放在木头上,并在 canny 之后看到木结构的许多边缘 canny 函数中的两个阈值有什么用? 最佳答案 Large intens
我正在尝试使用 OpenCV 的 cv::threshold 函数(更具体的 THRESH_OTSU),只是我想使用掩码(任何形状) ), 以便在计算过程中忽略外部(背景)。 图像是单 channel
我正在寻找根据提供的音频、频率范围(例如 20hz-1000hz)和阈值缩放 PNG 文件,以获得平滑的效果。 例如,当有脚踢时,比例平滑到 120%,我想让那些音频可视化器,如 dubstep 等.
我正在尝试找到最佳阈值,以使我的逻辑回归具有最高的 f1 分数。但是,当我写下以下几行时: val f1Score = metrics.fMeasureByThreshold f1Score.fore
我使用 Flot 创建了一个实时(每 10 毫秒更新一次)垂直样条图。图表可见here on Codepen 。我包括了 Flot multiple threshold plugin ,但我希望阈值使
我有一个数据框,其中包含从第 1 天到第 7 天的三个人(John、Terry、Henry)的分数。 1 2 3 4 5 6 7
我正在尝试实现多级 Otsu 阈值,更具体地说,我需要 3 个阈值/4 个类。 我知道关于 SO 的 2 个类似问题:#34856019 和 #22706742。问题是我没有得到好的结果:我已经阅读了
The documentation在 THRESH_BINARY 上说: dst(x,y) = maxval if src(x,y) > thresh else 0 这对我来说并不意味着这不适用于彩色
我是一名优秀的程序员,十分优秀!