栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

如何在不损坏文本的情况下消除点/噪音?

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

如何在不损坏文本的情况下消除点/噪音?

如何使用删除连接的小组件

connectedComponentsWithStats

import cv2import numpy as npimg = cv2.imread('path_to_your_image', 0)_, blackAndWhite = cv2.threshold(img, 127, 255, cv2.THRESH_BINARY_INV)nlabels, labels, stats, centroids = cv2.connectedComponentsWithStats(blackAndWhite, None, None, None, 8, cv2.CV_32S)sizes = stats[1:, -1] #get CC_STAT_AREA componentimg2 = np.zeros((labels.shape), np.uint8)for i in range(0, nlabels - 1):    if sizes[i] >= 50:   #filter small dotted regions        img2[labels == i + 1] = 255res = cv2.bitwise_not(img2)cv2.imwrite('res.png', res)

这是c ++示例:

Mat invBinarized;threshold(inputImage, invBinarized, 127, 255, THRESH_BINARY_INV);Mat labels, stats, centroids;auto nlabels = connectedComponentsWithStats(invBinarized, labels, stats, centroids, 8, CV_32S, CCL_WU);Mat imageWithoutDots(inputImage.rows, inputImage.cols, CV_8UC1, Scalar(0));for (int i = 1; i < nlabels; i++) {    if (stats.at<int>(i, 4) >= 50) {        for (int j = 0; j < imageWithoutDots.total(); j++) { if (labels.at<int>(j) == i) {     imageWithoutDots.data[j] = 255; }        }    }}cv::bitwise_not(imageWithoutDots, imageWithoutDots);

编辑:
另请参见

ConnectedComponentsWithStats的OpenCV文档

如何在Python中使用带有统计信息的openCV的连接组件

学习opencv3的示例



转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/669663.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号