消除图像中文本的干扰曲线? [英] Eliminating Interferential Curve of Text in Images?
本文介绍了消除图像中文本的干扰曲线?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如您所见,我有一些公式的图像
但是它有一些干扰曲线,所以如何将其删除?
我试图侵蚀和扩张但失败了。
解决方案
您可以使用图像修复删除这些行。但需要先做一个面具。看看这个 -
此代码(python)可帮助您制作面具:
import cv2
import numpy as np
imgg = cv2.imread(your_image.png)
flag = False
def draw(event,x,y,flags, param):
全局标志
如果event == cv2.EVENT_LBUTTONDOWN:
flag = True
elif event == cv2.EVENT_MOUSEMOVE:
if flag == True:
cv2.circle(img,(x,y),2,(255,255,255), - 1)
elif event == cv2.EVENT_LBUTTONUP:
flag = False
img = np.zeros(imgg.shape [:2],np.uint8)
cv2.namedWindow('image ')
cv2.setMouseCallback('image',draw)
while(1):
cv2.imshow('image',imgg)
cv2.imshow (mask,img)
if(cv2.waitKey(1))== 27:
break
cv2.imwrite(mask.png,img)
cv2 .destroyAllWindows()
As you can see,I have an image of some formulas
but it has some interferential curve,so how can I to remove it?
I tried to erode and dilate but failed.
解决方案
You can remove those lines by using image inpainting. But need to make a mask first. Take a look at this- http://docs.opencv.org/trunk/df/d3d/tutorial_py_inpainting.html
I just tried one see-
This code (python) helps you make a mask:
import cv2
import numpy as np
imgg=cv2.imread("your_image.png")
flag = False
def draw(event,x,y,flags,param):
global flag
if event == cv2.EVENT_LBUTTONDOWN:
flag = True
elif event == cv2.EVENT_MOUSEMOVE:
if flag == True:
cv2.circle(img,(x,y),2,(255,255,255),-1)
elif event == cv2.EVENT_LBUTTONUP:
flag = False
img = np.zeros(imgg.shape[:2], np.uint8)
cv2.namedWindow('image')
cv2.setMouseCallback('image',draw)
while(1):
cv2.imshow('image',imgg)
cv2.imshow("mask",img)
if(cv2.waitKey(1))==27:
break
cv2.imwrite("mask.png",img)
cv2.destroyAllWindows()
这篇关于消除图像中文本的干扰曲线?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文