输入字符图片二值化后输出依旧很潦草
如题
(白纸+扫描仪+QQ截图)
以下是我用来二值化图片的代码
import os
from PIL import Image
import cv2
source_dir = 'now_style_samples'
target_dir = 'style_samples'
if not os.path.exists(target_dir):
os.makedirs(target_dir)
files = os.listdir(source_dir)
for file in files:
image = Image.open(os.path.join(source_dir, file)).convert('1')
aspect_ratio = image.width / image.height
new_width = int(image.width * 2)
new_height = int(new_width / aspect_ratio)
new_size = (new_width, new_height)
image = image.resize(new_size, Image.LANCZOS)
image.save(os.path.join(target_dir, file))
for file in files:
image = cv2.imread(os.path.join(source_dir, file), cv2.IMREAD_GRAYSCALE)
_, image = cv2.threshold(image, 127, 255, cv2.THRESH_BINARY)
aspect_ratio = image.shape[1] / image.shape[0]
new_width = int(image.shape[1] * 2)
new_height = int(new_width / aspect_ratio)
new_size = (new_width, new_height)
image = cv2.resize(image, new_size, interpolation=cv2.INTER_LANCZOS4)
cv2.imwrite(os.path.join(target_dir, file), image)
使用Microsoft Whiteboard写字后通过Snipaste截图生成的也有如上问题
以上两种方法都通过了贴出来的二值化代码处理
模型训练使用的数据集是casia-hwdb,里面起码一半以上的数据都是狂草风格,模型从这样的数据训练出来就是这个样子了,清理下训练数据,重新训练模型可能能好些
狂草风格,模型从这样的数据训练出来就是这个样子了,清理下训练数据,重新训练模型可能能好些
要怎么清理呢
我找到可能比较好的办法了,看一下我的回答喵
可以看下这位老铁的复现结果https://github.com/dailenson/SDT/issues/75#issuecomment-2031897517
用数位板,狂草主要是噪点
分享一下纸写扫描的生成结果和数位板写的生成结果
[自动回复]Sorry,the DALAO you talked with is so busy that can't answer you forever,please never send amessages again.
