日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

OpenCVSharp入门教程 特征提取③——HoughLinesP直线寻找,直线提取

發布時間:2023/12/15 编程问答 36 豆豆
生活随笔 收集整理的這篇文章主要介紹了 OpenCVSharp入门教程 特征提取③——HoughLinesP直线寻找,直线提取 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

文章目錄

  • 一、前文
  • 二、算法流程
  • 三、界面布局
  • 四、功能實現
    • 4.1 打開圖片
    • 4.2 HoughLinesP直線提取—源碼
    • 4.3 HoughLinesP直線提取—參數講解
  • 五、運行效果圖
  • 六、參考

一、前文

Hough變換
經典的直線檢測算法

二、算法流程

  • 高斯模糊
  • Canny邊緣檢測
  • HoughLinesP直線尋找,直線提取
  • 三、界面布局

    • 一個Label
    • N個Button
    • 三個Picture

    四、功能實現

    4.1 打開圖片

    private void openFileBtn_Click(object sender, EventArgs e){OpenFileDialog openfiledialog = new OpenFileDialog();openfiledialog.Filter = "PNG Files (*.png)|*.png|JPG Files (*.jpg)|*.jpg|GIF Files (*.gif)|*.gif";openfiledialog.RestoreDirectory = true;if (openfiledialog.ShowDialog() == DialogResult.OK){Console.WriteLine(openfiledialog.FileName);fileName = openfiledialog.FileName;//Mat src = new Mat("foo.png", LoadMode.Color);Mat src = new Mat(fileName);//Mat src = new Mat(fileName, ImreadModes.Color);var frameBitmap = BitmapConverter.ToBitmap(src);pictureBox1.Image?.Dispose();pictureBox1.Image = frameBitmap;}}

    4.2 HoughLinesP直線提取—源碼

    private void houghLinesBtn_Click(object sender, EventArgs e) {cannyBtn_Click(sender, e);mOutput = new Mat(mInput.Rows, mInput.Cols, MatType.CV_8UC4);mInput.CopyTo(mOutput);double rho = 1;double theta = 1;int threshold = 10;double minLineLength = 0;double maxLineGap = 0;var res = Cv2.HoughLinesP(edges,rho: rho,theta: theta / 100.0,threshold: threshold,minLineLength: minLineLength,maxLineGap: maxLineGap);for (int i = 0; i < res.Length; i++){Scalar color = Scalar.RandomColor();Cv2.Line(mOutput, res[i].P1, res[i].P2,color: color,thickness: 2,lineType: LineTypes.Link8);}srcPictureBox.Image = BitmapConverter.ToBitmap(mInput);grayPictureBox.Image = BitmapConverter.ToBitmap(edges);dstPictureBox.Image = BitmapConverter.ToBitmap(mOutput); }

    4.3 HoughLinesP直線提取—參數講解

    // // 摘要: // Finds lines segments in a binary image using probabilistic Hough transform. // // 參數: // image: // // rho: // Distance resolution of the accumulator in pixels // // theta: // Angle resolution of the accumulator in radians // // threshold: // The accumulator threshold parameter. Only those lines are returned that get enough // votes ( > threshold ) // // minLineLength: // The minimum line length. Line segments shorter than that will be rejected. [By // default this is 0] // // maxLineGap: // The maximum allowed gap between points on the same line to link them. [By default // this is 0] // // 返回結果: // The output lines. Each line is represented by a 4-element vector (x1, y1, x2, // y2) public static LineSegmentPoint[] HoughLinesP(InputArray image, double rho, double theta, int threshold, double minLineLength = 0, double maxLineGap = 0);
    • image,灰度圖片輸入
    • rho,步長為1的半徑
    • theta,步長為π/180的角來,來搜索所有可能的直線
    • threshold,閾值,大于閾值 threshold 的線段才可以被確認為直線。該值越小,判定出的直線越多;值越大,判定出的直線就越少。
    • minLineLength,線段的最短長度,長度小于該值的線段會被忽略
    • maxLineGap,兩條線段之間的最大間隔,間隔小于該值的兩條線會被當成一條線

    五、運行效果圖

    從左到右

    • 第一張是原圖
    • 第二張是高斯模糊的結果圖
    • 第三張是HoughLinesP直線提取的結果圖


    六、參考

    OpenCV—直線檢測

    覺得好,就一鍵三連唄(點贊+收藏+關注)

    總結

    以上是生活随笔為你收集整理的OpenCVSharp入门教程 特征提取③——HoughLinesP直线寻找,直线提取的全部內容,希望文章能夠幫你解決所遇到的問題。

    如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。