- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
最佳答案
失败的答案:- 这不是一个完美的解决方案,但需要进一步的工作以使其对各种图像具有鲁棒性。我注意到黑色线条中的噪点非常少,因此 Canny 在该区域内没有发现很多边缘。代码和结果如下:-
import numpy as np
import cv2
gray = cv2.imread('2.png')
edges = cv2.Canny(gray,10,60,apertureSize = 7)
cv2.imwrite('2-1-edges-10-60.jpg',edges)
kernel = np.ones((5,5),np.uint8)
closeEdges = cv2.morphologyEx(edges, cv2.MORPH_CLOSE, kernel)
cv2.imwrite('2-2-edges-10-60-dilated-1.jpg',closeEdges)
invertEdges = 255 - closeEdges
cv2.imwrite('2-3-invertedges-10-60.jpg',invertEdges)
minLineLength=100
lines = cv2.HoughLinesP(image=invertEdges,rho=1,theta=np.pi/180, threshold=200,lines=np.array([]), minLineLength=minLineLength,maxLineGap=80)
a,b,c = lines.shape
for i in range(a):
cv2.line(gray, (lines[i][0][0], lines[i][0][1]), (lines[i][0][2], lines[i][0][3]), (0, 0, 255), 1, cv2.LINE_AA)
cv2.imwrite('2-4-houghlines.jpg',gray)
在输出图像的反转上使用连通分量并找到最大尺寸的元素可能会有所帮助。
解决这个问题的另一种方法是使用梯度图像并直接找到梯度幅度小范围的区域。这种方法会更加灵活,因为它不需要使用固定阈值 - 如上所述的 10 和 60。阈值可以根据图像梯度进行自适应/您可以在使用硬编码阈值之前对图像梯度进行归一化。
更好的答案(准确率 30-40%)
import numpy as np
import cv2
import os
# Store all images in this folder
path='images-1'
def autocrop(image, threshold=0):
if len(image.shape) == 3:
flatImage = np.max(image, 2)
else:
flatImage = image
rows = np.where(np.max(flatImage, 0) > threshold)[0]
if rows.size:
cols = np.where(np.max(flatImage, 1) > threshold)[0]
image = image[cols[0]: cols[-1] + 1, rows[0]: rows[-1] + 1]
else:
image = image[:1, :1]
return image
def skeleton(img):
size = np.size(img)
skel = np.zeros(img.shape,np.uint8)
element = cv2.getStructuringElement(cv2.MORPH_CROSS,(3,3))
done = False
while( not done):
eroded = cv2.erode(img,element)
temp = cv2.dilate(eroded,element)
temp = cv2.subtract(img,temp)
skel = cv2.bitwise_or(skel,temp)
img = eroded.copy()
zeros = size - cv2.countNonZero(img)
if zeros==size:
done = True
return skel
def gamma_correction(img, correction):
img = img/255.0
img = cv2.pow(img, correction)
return np.uint8(img*255)
def auto_canny(image, sigma=0.33):
# compute the median of the single channel pixel intensities
v = np.median(image)
# apply automatic Canny edge detection using the computed median
lower = int(max(0, (1.0 - sigma) * v))
upper = int(min(255, (1.0 + sigma) * v))
edged = cv2.Canny(image, lower, upper)
# return the edged image
return edged
for file in os.listdir(path):
if file.endswith(".png"):
current = os.path.join(path, file)
img = cv2.imread(current, 0)
print 'processing ' + current
img = autocrop(img, 0)
cv2.imwrite(current + '-0-cropped.jpg', img)
height, width = img.shape[:2]
img = cv2.resize(img, (width, width))
cv2.imwrite(current + '-0-resized.jpg', img)
# cv2.imwrite(current +'-2-auto_canny_default.jpg', auto_canny(img))
# img = cv2.medianBlur(img,5)
# cv2.imwrite(current +'-0-medianBlur.jpg',img)
# th3 = cv2.adaptiveThreshold(img,255,cv2.ADAPTIVE_THRESH_GAUSSIAN_C, cv2.THRESH_BINARY,11,2)
# cv2.imwrite(current +'-1-threshold_gaussian.jpg',th3)
# laplacian = cv2.Laplacian(img,cv2.CV_64F)
# cv2.imwrite(current + '-3-threshold_gaussian.jpg', laplacian)
#img = cv2.bilateralFilter(img, 3, 3, 5)
edges = cv2.Canny(img,10,20,apertureSize = 5)
cv2.imwrite(current +'-1-edges-10-60.jpg',edges)
kernel = np.ones((3,3),np.uint8)
edges = cv2.morphologyEx(edges, cv2.MORPH_CLOSE, kernel)
cv2.imwrite(current +'-1-edgesClosed-10-60.jpg', edges)
edges = 255-edges
cv2.imwrite(current +'-2-edgesClosedInverted-10-60.jpg', edges)
im2, contours, hierarchy = cv2.findContours(edges, cv2.RETR_TREE, cv2.CHAIN_APPROX_NONE)
imgColor = cv2.cvtColor(img, cv2.COLOR_GRAY2BGR)
maxArea = 0
for cnt in contours:
if maxArea < cv2.contourArea(cnt):
maxArea = cv2.contourArea(cnt)
for cnt in contours:
rect = cv2.minAreaRect(cnt) #I have used min Area rect for better result
width = rect[1][0]
height = rect[1][1]
if cv2.contourArea(cnt) > int(maxArea/2.5) and ( width < height/2 or height < width/2):
cv2.drawContours(imgColor, cnt, -1, (0,255,0), 1)
cv2.imwrite(current+'-5-Contours.jpg',imgColor)
# edges = skeleton(255-edges)
# cv2.imwrite(current +'-2-skeleton.jpg', edges)
# edges = 255-edges
# minLineLength=int(width/4)
# threshold = 20
# maxLineGap = 1
# rho = 1
# lines = cv2.HoughLinesP(image=edges,rho=rho,theta=np.pi/180, threshold=threshold,lines=np.array([]), minLineLength=minLineLength,maxLineGap=maxLineGap)
# if lines is not None:
# a,b,c = lines.shape
# for i in range(a):
# cv2.line(img, (lines[i][0][0], lines[i][0][1]), (lines[i][0][2], lines[i][0][3]), (0, 0, 255), 1, cv2.LINE_AA)
# cv2.line(edges, (lines[i][0][0], lines[i][0][1]), (lines[i][0][2], lines[i][0][3]), (0, 0, 255), 1, cv2.LINE_AA)
# cv2.imwrite(current+'-5-houghlines.jpg',img)
# cv2.imwrite(current+'-6-houghlines.jpg',edges)
# print 'cool'
# else:
# cv2.imwrite(current+'-5-houghlines.jpg',img)
此外,请检查以下链接:
关于opencv - 在噪声很大的图像中检测窄线,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42788536/
我正在研究我的论文,以构建乐谱(乐谱)识别系统。这是我的输入文件: 这是一些预处理和去除五线谱后的结果: 我在这里遇到的问题是,在五线谱删除步骤之后出现了一些超小的、不需要的“点”。这些点/噪声与实际
这可能是一个愚蠢的问题(当然),但对于我已阅读/发现的所有内容,没有一个与我想做的相匹配......这是 GIT 的基本情况。 为了使我的情况更简单,我有两个分支: - master(主要分支) -
我的项目: 我正在开发一辆带有 3 轴加速度计和陀螺仪的槽车,试图估计汽车姿态(x、y、z、偏航、俯仰),但我的振动噪音有一个大问题(而汽车在例如,加速度计的噪声值在 ±4[g](其中 g = 9.8
我正在尝试实现 2D Perlin 噪声来创建类似 Minecraft 的地形(Minecraft 实际上并不使用 2D Perlin 噪声)而没有悬垂或洞穴之类的东西。 我这样做的方式是创建一个 [
我有一个代表图像的二维数组。我必须向图像添加 RMS 2 单位的背景高斯噪声。我不熟悉噪声的 RMS 测量以及如何添加它。您能否告诉我如何执行此操作? 最佳答案 按照我的理解,您想要在每个像素处添加遵
更新:正式问题列表: 2D 噪声实现的浮点值(输入参数和输出)代表什么? - 部分回答,输入是坐标。输出怎么样?另外,我可以使用我的整数作为坐标的 float 吗? 1.0、122.0 等? 在 2D
我正在尝试使用 Perlin 噪声生成地形。我了解如何使用笛卡尔坐标生成它,但无法完全理解它在球体上的工作方式。我知道您可以将 2D 表面投影到球体上,但失真不会扰乱噪声分布吗?要在球体表面生成均匀噪
按照目前的情况,这个问题不适合我们的问答形式。我们希望答案得到事实、引用或专业知识的支持,但这个问题可能会引发辩论、争论、投票或扩展讨论。如果您觉得这个问题可以改进并可能重新打开,visit the
我正在尝试将 fBm 实现到行星的球体上。为了创建我的球体,我将其从立方体转换为此类。不幸的是,生成的 fBm 显示为镜像补丁。此外,它只在 2 个面上执行(包装其他面的值)。当呈现为 sphere
我想知道为什么在 Simplex 推出后,Perlin 噪声至今仍然如此流行。单纯形噪声是由 Ken Perlin 自己制作的,它应该取代他的旧算法,该算法对于更高的维度来说速度较慢,但质量更好(
我终于设法为 Love 2D 编写了 Perlin 改进噪音的工作 Lua 版本。但是,当我运行它时,我得到了这个: 我想这很好。但我想要看起来更像这样的东西: 我怎样才能做到这一点? 最佳答案 第一
我终于设法为 Love 2D 编写了 Perlin 改进噪音的工作 Lua 版本。但是,当我运行它时,我得到了这个: 我想这很好。但我想要看起来更像这样的东西: 我怎样才能做到这一点? 最佳答案 第一
我正在尝试处理我从采样源数据行(Java Sound API)获得的字节数组。如果我将字节数组与小数相乘,播放流时会产生噪音。 在播放声音之前,我将立体声 wav 文件分成左右声道。这很好用。但是,如
对于我正在进行的元胞自动机项目,我需要使用不同的算法和技术随机生成二维 boolean 数组。目前,我在应用程序中只有一种随机化类型——循环遍历数组中的每个单元格并生成一个随机 double 变量,然
我叫 Chris,正在开发我的第一个 Java 游戏。到目前为止,我已经创建了一个基于图 block 的 2D 游戏,但是我的关卡是以这样一种方式完成的,如果我创建一个图像并且它全是绿色,那么绿色就代
block 之间的平滑 所以我一直在开发一个统一的游戏,想将我的世界从 150x150 的 map 扩展到一个看似无限的程序世界。我的计划是以Perlin Noise为基础,使用0-1的不同值来判断地
(此程序的依赖项:vector --any 和 JuicyPixels >= 2 。代码可用作 Gist。) {-# LANGUAGE Haskell2010 #-} {-# LANGUAGE Ban
我最近用 C# 编写了 Diamond-Square 过程生成算法的实现。但是,生成的噪声在所处理的“正方形”之间具有非常明显的边界。伪代码看起来像这样 gen() { This takes
我已经尝试了所有方法并阅读了我在互联网上看到的关于 Perlin Noise 或 Simplex Noise 的每一个链接,甚至剖析了一些我认为工作正常的 Javascript 示例。 但我仍然得到看
我在任何方面都不精通视频压缩,但目前正在从事一个使用 H.264 压缩残差图像的项目 我的问题更多是关于视频编码器的一般性问题。据我了解(正如维基百科所解释的那样), block 运动补偿编码器将当前
我是一名优秀的程序员,十分优秀!