欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

opencvsharp瑕疵檢測(cè)的實(shí)現(xiàn)示例

 更新時(shí)間:2022年05月06日 10:05:31   作者:工控cc  
本文主要介紹了opencvsharp瑕疵檢測(cè)的實(shí)現(xiàn)示例,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧

功能演示

實(shí)現(xiàn)模板:

1.檢測(cè)這板件面的凹坑 ,并把這些凹坑繪制出來(lái)
2.界面上可以選擇,標(biāo)注面積大于指定值 的凹坑

在這里插入圖片描述

測(cè)試圖像

在這里插入圖片描述

面積小于10個(gè)像素凹坑標(biāo)注

在這里插入圖片描述

面積小于40個(gè)像素凹坑標(biāo)注

提示:以下是本篇文章正文內(nèi)容,下面案例可供參考

一、編程環(huán)境

C#2015+opencvsharp4.0

二、使用步驟

1.程序邏輯

1.先將圖像高斯雙邊濾波 ;

代碼如下(示例):

   Cv2.BilateralFilter(imageorg, gs, 0, 20, 5);   //高斯雙邊模糊
   //imageorg為源圖 Mat;
   //gs是濾波后 Mat; 

在這里插入圖片描述

高斯雙邊濾波后的圖像

2.圖像轉(zhuǎn)二值圖像

//先轉(zhuǎn)灰度圖像 
   Cv2.CvtColor(gs, image_gray,ColorConversionCodes.RGB2GRAY);   
//在轉(zhuǎn)二值圖像
   Cv2.Threshold(image_gray, bin, 100, 255, ThresholdTypes.BinaryInv);

在這里插入圖片描述

二值圖像

3.二值圖像輪廓發(fā)現(xiàn)

           //發(fā)現(xiàn)輪廓
            OpenCvSharp.Point[][] contours2;
            HierarchyIndex[] hierarchy2;
            Cv2.FindContours(bin, out contours2, out hierarchy2, RetrievalModes.External, ContourApproximationModes.ApproxNone);

4.根據(jù)界面的設(shè)置,繪制符合標(biāo)準(zhǔn)的輪廓

           //繪制輪廓
              for (int i = 0; i < contours2.Length; i++)
            {
                double size = Cv2.ArcLength(contours2[i], true);
                if(size > Double.Parse(textBox1.Text))
                Cv2.DrawContours(imageorg, contours2,i, new Scalar(0, 0, 255), 3);            
            }

5.顯示最終圖像

           //顯示
            Bitmap bitmap = BitmapConverter.ToBitmap(gs);
            pictureBox1.Image = bitmap;
            Cv2.ImWrite("12.jpg", imageorg);

三 、完整代碼演示

              private void button6_Click(object sender, EventArgs e)
        {
            Mat imageorg = Cv2.ImRead("E:\\CS學(xué)習(xí)\\opencvsharp2\\opencvsharp2\\data9.jpg");
            Mat image_gray = new Mat();
            Mat gs = new Mat();
            Mat bin=new Mat();
            Cv2.BilateralFilter(imageorg, gs, 0, 20, 5);   //高斯雙邊模糊
            //圖紙轉(zhuǎn)換
            Cv2.CvtColor(gs, image_gray,ColorConversionCodes.RGB2GRAY); 
            Cv2.Threshold(image_gray, bin, 100, 255, ThresholdTypes.BinaryInv);
            //發(fā)現(xiàn)輪廓
            OpenCvSharp.Point[][] contours2;
            HierarchyIndex[] hierarchy2;
            Cv2.FindContours(bin, out contours2, out hierarchy2, RetrievalModes.External, ContourApproximationModes.ApproxNone);
            //繪制指定輪廓 
            for (int i = 0; i < contours2.Length; i++)
            {
                double size = Cv2.ArcLength(contours2[i], true);
                if(size > Double.Parse(textBox1.Text))
                Cv2.DrawContours(imageorg, contours2,i, new Scalar(0, 0, 255), 3);

            }
            //顯示
            Bitmap bitmap = BitmapConverter.ToBitmap(imageorg);
            pictureBox1.Image = bitmap;
            Cv2.ImWrite("12.jpg", bin);
        }
          

到此這篇關(guān)于opencvsharp瑕疵檢測(cè)的實(shí)現(xiàn)示例的文章就介紹到這了,更多相關(guān)opencvsharp瑕疵檢測(cè)內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

最新評(píng)論