如何用python精确定位五线谱

最精确的五线谱检测:

源码位置

连通域法
完美5线
  • 连通域检测标注label
  • 判断连通域的顶部(底部)是否是平的:
  • 判断连通域面积大小


    经过上面条件限制后的直线
  • 合并近似直线
  • 判断5线名称
    先输出1,5线的位置,再对其余位置合并以及判断位置
for i in (finallist):
    if (i.get_deltan()>15) and(i.get_deltal()<=15):
        i.set_5(5)
    elif (i.get_deltan()<=15 ) and(i.get_deltal()>15):
        i.set_5(1)
    
'''
pos:156 l5:5    distribute:None last:1  next:41
pos:198 l5:1    distribute:None last:38 next:3
pos:201 l5:None distribute:None last:2  next:3
pos:205 l5:None distribute:None last:3  next:1
pos:207 l5:None distribute:None last:1  next:2
pos:211 l5:None distribute:None last:2  next:2
pos:216 l5:5    distribute:None last:1  next:34
pos:254 l5:1    distribute:None last:32 next:8
pos:265 l5:None distribute:None last:5  next:5
pos:271 l5:None distribute:None last:2  next:3
pos:276 l5:5    distribute:None last:2  next:42
pos:321 l5:1    distribute:None last:40 next:5
pos:327 l5:None distribute:None last:2  next:2
pos:330 l5:None distribute:None last:1  next:5
pos:336 l5:None distribute:None last:4  next:5
pos:342 l5:5    distribute:None last:4  next:44
pos:386 l5:1    distribute:None last:43 next:3
pos:391 l5:None distribute:None last:3  next:2
pos:394 l5:None distribute:None last:1  next:2
pos:396 l5:None distribute:None last:1  next:1
pos:398 l5:None distribute:None last:1  next:5
'''
  • 确认五线后调整间距
  • 输出位置数据

其余尝试过的方法:

1 统计法

  • 每根五线谱在y轴上的像素累积作统计
像素平均值
  • 使用计数来作统计


    计数出现的五线位置

缺陷,谱子倾斜无解。若谱子很正,效果中上水平

2 霍夫空间法(预处理为candy边缘检测)

霍夫直线检测原理

极坐标下的霍夫变换

使用candy检测边缘后霍夫直线检测
  • 分段完美,五线定位需要迂回操作:从段落中均分出5条直线
    (预计效果很完美,还未尝试)

3 霍夫空间法(预处理为卷积边缘检测)

fit = np.array([
    [-2,-2,-2,-2,-2],
    [-1,-1,-1,-1,-1],
    [-0,-0,-0,-0,-0],
    [1,1,1,1,1],
    [2,2,2,2,2]    
])

fit = np.array([
    [-0,-0,-0,-0,-0],
    [2,2,2,2,2],
    [-0,-0,-0,-0,-0],
    [-2,-2,-2,-2,-2],
    [0,0,0,0,0]
    
])

  • 1 使用两个fitter的转置,过滤出竖线,再由原图减去
    过滤出的纵向图像

    消去纵向后的图像
  • 噪音太大,霍夫直线检测效果很差
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容