清洁opencv中的扫描图像
问题描述:
我试图去噪图像,然后提取包含手写线的图像的骨架。我希望这条线是连续而坚实的,但是我使用的方法没有做到这一点,而且速度相对较慢。这里的原始图像: Original Image清洁opencv中的扫描图像
Morphed 在经过变形的图像,你可以在右下角看到一个小岛。
上面的细化图像显示线条在结尾附近断开。
任何其他的方法来达到预期的效果?
我的代码如下所示:
int morph_elem = 2;
int morph_size = 10;
int morph_operator = 0;
Mat origImage = imread(origImgPath, CV_LOAD_IMAGE_COLOR);
medianBlur(origImage, origImage, 3);
cvtColor(origImage, origImage, COLOR_RGB2GRAY);
threshold(origImage, origImage, 0, 255, THRESH_OTSU);
Mat element = getStructuringElement(morph_elem, Size(2 * morph_size + 1, 2 * morph_size + 1), cv::Point(morph_size, morph_size));
morphologyEx(origImage, origImage, MORPH_OPEN, element);
thin(origImage, true, true, true);
答
减少线路割舍尝试使用adaptiveThreshold
,玩的方法和大小,看看有什么效果最好。 要删除小岛,只需执行findContours
,然后使用drawContours
与color=(255,255,255)
和thickness=-1
屏蔽掉不需要的规格,然后用wantedContours = [x for x in contours if contourArea(x) < 50]
之类的东西对其进行筛选。
答
您想要对图像执行一系列关闭和打开操作。最好你了解他们如何做出适当的选择。 看到这个职位:Remove spurious small islands of noise in an image - Python OpenCV
在二值图像(阈值之后)你可以'findContour's,并删除小的例如,使用'contourArea' – Miki