c++ - 在 opencv 中清理扫描图像

标签 c++ opencv vision

我正在尝试对图像进行降噪,然后提取包含手写线条的图像骨架。我希望这条线是连续的和坚实的,但我使用的方法没有做到这一点,而且速度相对较慢。这是原始图像: 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/

相关文章:

c++ - static_cast 和 reinterpret_cast 的转换运算符 int() 失败

c++ - C++11 中的异步/ future 数量

opencv - ffmpeg 无法通过 MacPorts 构建

vision - 在 ios11 上检测圆圈宽度视觉框架?

vector<Object *> use 和 new Object() 的 C++ 编程问题

c++ - 1 个带有 cmake 的体系结构 x86_64 的重复符号

python - Mat不是数字元组openCV 2

python - OpenCv 按位运算物理意义

android - 哪个是 HSV 皮肤检测器 openCV android 的颜色空间?

android - 视觉 API 条码 - 将检测区域限制在屏幕的中心矩形