Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/313.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 如何仅提取看起来像手写的轮廓?_Python_Image Processing - Fatal编程技术网

Python 如何仅提取看起来像手写的轮廓?

Python 如何仅提取看起来像手写的轮廓?,python,image-processing,Python,Image Processing,我想仅提取属于此图像上笔迹的轮廓: 以下是提取轮廓的代码: import cv2 import matplotlib.pyplot as plt img = cv2.imread(PATH TO FRAME) print("img shape=", img.shape) gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY) cv2.imshow("image", gray) cv2.waitKey(1) ####

我想仅提取属于此图像上笔迹的轮廓:

以下是提取轮廓的代码:

import cv2
import matplotlib.pyplot as plt


img = cv2.imread(PATH TO FRAME)
print("img shape=", img.shape)
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)

cv2.imshow("image", gray)
cv2.waitKey(1)
#### extract all contours
# Find Canny edges 
edged = cv2.Canny(gray, 30, 200) 
cv2.waitKey(0) 
  
# Finding Contours 
# Use a copy of the image e.g. edged.copy() 
# since findContours alters the image 
contours, hierarchy = cv2.findContours(edged,  
    cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_NONE) 
  
cv2.imshow('Canny Edges After Contouring', edged) 
cv2.waitKey(0) 
  
print("Number of Contours found = " + str(len(contours))) 
  
# Draw all contours 
# -1 signifies drawing all contours 
cv2.drawContours(img, contours, -1, (0, 255, 0), 3) 
  
cv2.imshow('Contours', img) 
cv2.waitKey(0) 

您是专门要求这张图片还是要求一张普通图片(这恰好是一个例子)-您在写作品之前有这张图片吗

如果对于该图像,您可以确定笔迹的位置(左下方的大矩形),然后仅提取该区域中的轮廓。 您可以通过在任何写入之前和之后处理图像,或者通过知道左下角的区域已处理该图像来确定该矩形

另一个选项:你可以从后面减去前面的图像,只留下已经添加的内容


我意识到,虽然他们实际上并没有从轮廓中检测出笔迹,但他们可能会达到同样的目的——铜版纸越多,检测起来就越困难。预先处理或获取感兴趣区域可能会使轮廓问题变得更简单。

您可以从一些已经检测手写文本的神经网络模型开始。然后,重新训练它,使其检测手写文本并忽略机器打印的文本。例如,您可以从以下文字检测器型号开始: