C# OpenCvSharp實(shí)現(xiàn)去除字母后面的雜線
效果

項(xiàng)目

代碼
/// <summary>
/// Applies an adaptive threshold to an array.
/// </summary>
/// <param name="src">Source 8-bit single-channel image.</param>
/// <param name="dst">Destination image of the same size and the same type as src .</param>
/// <param name="maxValue">Non-zero value assigned to the pixels for which the condition is satisfied. See the details below.</param>
/// <param name="adaptiveMethod">Adaptive thresholding algorithm to use, ADAPTIVE_THRESH_MEAN_C or ADAPTIVE_THRESH_GAUSSIAN_C .</param>
/// <param name="thresholdType">Thresholding type that must be either THRESH_BINARY or THRESH_BINARY_INV .</param>
/// <param name="blockSize">Size of a pixel neighborhood that is used to calculate a threshold value for the pixel: 3, 5, 7, and so on.</param>
/// <param name="c">Constant subtracted from the mean or weighted mean (see the details below).
/// Normally, it is positive but may be zero or negative as well.</param>
public static void AdaptiveThreshold(InputArray src, OutputArray dst,double maxValue, AdaptiveThresholdTypes adaptiveMethod, ThresholdTypes thresholdType, int blockSize, double c)
using OpenCvSharp;
using System;
using System.Drawing;
using System.Windows.Forms;
namespace OpenCvSharp_Demo
{
public partial class frmMain : Form
{
public frmMain()
{
InitializeComponent();
}
string image_path = "";
private void Form1_Load(object sender, EventArgs e)
{
image_path = "1.jpg";
pictureBox1.Image = new Bitmap(image_path);
}
private void button2_Click(object sender, EventArgs e)
{
Mat gray = new Mat(image_path, ImreadModes.Grayscale);
Mat binary = new Mat();
Cv2.AdaptiveThreshold(~gray, binary, 255, AdaptiveThresholdTypes.MeanC, ThresholdTypes.Binary, 15, -2);
Mat kernel = Cv2.GetStructuringElement(MorphShapes.Rect, new OpenCvSharp.Size(4, 4), new OpenCvSharp.Point(-1, -1));
//開運(yùn)算
Mat dst = new Mat();
Cv2.MorphologyEx(binary, dst, MorphTypes.Open, kernel);
pictureBox2.Image = new Bitmap(dst.ToMemoryStream());
}
}
}以上就是C# OpenCvSharp實(shí)現(xiàn)去除字母后面的雜線的詳細(xì)內(nèi)容,更多關(guān)于C# OpenCvSharp去除字母雜線的資料請關(guān)注腳本之家其它相關(guān)文章!
相關(guān)文章
C#中級(jí)、double和decimal區(qū)別解析
在 C# 中,double和decimal都是用來表示帶小數(shù)的數(shù)值類型,但它們在內(nèi)部表示、精度、性能和適用場景上有本質(zhì)區(qū)別,本文給大家介紹C#中級(jí)、double和decimal區(qū)別解析,感興趣的朋友跟隨小編一起看看吧2025-11-11
C# 調(diào)用C++寫的dll的實(shí)現(xiàn)方法
C#調(diào)用C++的非托管類的dll其實(shí)很簡單基本就是固定的調(diào)用格式,有需要的朋友可以參考一下2013-10-10
C#中GraphicsPath的AddString方法用法實(shí)例
這篇文章主要介紹了C#中GraphicsPath的AddString方法用法,實(shí)例分析了AddString方法添加字符串的相關(guān)使用技巧,需要的朋友可以參考下2015-06-06
C#實(shí)現(xiàn)對(duì)文件進(jìn)行加密保護(hù)的示例代碼
這篇文章主要為大家詳細(xì)介紹了如何利用C#實(shí)現(xiàn)對(duì)文件進(jìn)行加密保護(hù)的功能,文中的示例代碼講解詳細(xì),對(duì)我們學(xué)習(xí)C#有一定的幫助,感興趣的小伙伴可以跟隨小編一起了解一下2022-12-12
C#判斷文件夾是否存在,并執(zhí)行刪除、創(chuàng)建操作方式
這篇文章主要介紹了C#判斷文件夾是否存在,并執(zhí)行刪除、創(chuàng)建操作方式,具有很好的參考價(jià)值,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2025-04-04
C#實(shí)現(xiàn)WinForm控件焦點(diǎn)的獲取與失去
在一個(gè)數(shù)據(jù)輸入表單中,當(dāng)用戶從一個(gè)文本框切換到另一個(gè)文本框時(shí),需要準(zhǔn)確地判斷焦點(diǎn)的轉(zhuǎn)移,以便進(jìn)行數(shù)據(jù)驗(yàn)證、提示信息顯示等操作,本文將探討 Winform 控件獲取與失去焦點(diǎn)的相關(guān)知識(shí),需要的朋友可以參考下2025-01-01

