Hough线变换

一. hough变换与Canny边缘检测

1.hough线检测有两个方法,

  • Image(TColor,TDepth).HoughLines : 在进行Canny边缘检测之后应用Hough变换以检测线
  • Image(TColor,TDepth).HoughLinesBianry:对二进制图像进行hough变换(例如对Canny边缘检测结果进hough变换)

    1. hough变换构造函数:
public LineSgement2D[][] HoughLinesBianry(
    double rhoResolution,    //线检测中线最小距离单位像素,一般取1
    double thetaResolution,  //线检测中的线的倾斜角度 单位弧度
    int threshold,           //线最小像素数  超过该像素接受
    double minLineWidth,     //线宽最小值  以下两个是线与线之间最小width and gap 单位 pixel
    double gapBetweenLines   //线间距
)   
  1. hough 变换方法:
Image< Bgr,Byte> img1 = new Image< Bgr,Byte>(new Bitmap(pictureBox*.Image | ofd.FileName);
LineSegment2D[] lines = img1.HoughLinesBinary(1,Math.PI/45.0,20,30,10)[0];
Image< Bgr,Byte> ImageLines = new Image< Bgr,Byte>(CannyGray.width,Canny,Height);
foreach(LineSegment2D line in lines){
    ImageLines.Draw(line,new Bgr(Color.DeepSkyBlue),5);
}
pictureBox*.Image = imageLines.ToBitmap();
}

}


  1. hough 圆检测
    • 构造函数:

public CircleF[][] HoughCircles( //CircleF radius and the location of the circle
TColor cannyThreshold, //
TColor accumulatorThreshold, //圆最小像素
double dp, //>=1 分辨率参数,大于1时分辨率大于1
double minDist, //防止重复, 圆之间最小距离
int minRadius, // 最小圆
int maxRadius //最大圆
)
  • hough圆检测实例:(hough圆检测之前若是有边缘检测效果会下降,原因回头注意查看,检测第二个参数跟像素之间的色差好像有关,回头查看)(!圆检测参数注意查看)
OpenFileDialog ofd1 = new OpenFileDialog();
if (ofd1.ShowDialog() == DialogResult.OK)
{
    pictureBox2.Image = (new Image<Bgr, Byte>(ofd1.FileName)).ToBitmap() ;
    //Image<Bgr, Byte> img1 = new Image<Bgr, Byte>(new Bitmap(pictureBox1.Image));
    Image<Bgr, Byte> img1 = new Image<Bgr, Byte>(ofd1.FileName);
    //convert the img1 to grayscale and the filter out the noise
    Image<Gray, Byte> img2 = img1.Convert<Gray, Byte>().PyrDown().PyrUp();
    CircleF[] HoughCircles = img2.HoughCircles(
        new Gray(180),
        new Gray(120),
        2.0,
        50.0,
        20,
        100
     )[0];
    //draw circles
    Image<Bgr, Byte> imageCircles = img1;
    foreach (CircleF circle in HoughCircles)
    {
        imageCircles.Draw(circle, new Bgr(Color.Yellow), 5);
    }
    pictureBox1.Image = imageCircles.ToBitmap();
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值