我正在尝试对图像进行降噪,然后提取包含手写线条的图像骨架。我希望这条线是连续的和坚实的,但我使用的方法没有做到这一点,而且速度相对较慢。这是原始图像: Original Image
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]
的东西过滤它之后.
关于c++ - 在 opencv 中清理扫描图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39081810/