opencv for andriod java代码实现霍夫变化(HoughLinesP)

本文介绍如何在Android应用中利用Java代码通过OpenCV实现霍夫变换(HoughLinesP)来检测图像中的直线。具体步骤包括将位图转换为Mat对象,进行灰度转换、Canny边缘检测,最后应用霍夫概率变换找到并绘制直线。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

opencv for andriod java代码实现霍夫变化(HoughLinesP)

Mat mCannyMat1=new Mat();           
Mat rgbMat1 = new Mat();  
Mat grayMat1 = new Mat();           
Mat lines=new Mat();

Utils.bitmapToMat(bmp, rgbMat1);

//gray
Imgproc.cvtColor(rgbMat1, grayMat1, Imgproc.COLOR_RGB2GRAY);
//canny
Imgproc.Canny(grayMat1, mCannyMat1, 80, 160);
//houghlinesp
Imgproc.HoughLinesP(mCannyMat1, lines, 1, Math.PI /180, 30,100,30);

editText=(EditText)findViewById(R.id.show_feature_Text);
            editText.setText("lines="+lines.dump());
for (int y=0;y<lines1.rows();y++)
{
    double[] vec = lines1.get(y, 0);

    double  x1 = vec[0], 
    y1 = vec[1],
    x2 = vec[2],
    y2 = vec[3];    

    Point start = new Point(x1, y1);
    Point end = new Point(x2, y2);
    Imgproc.line(mCannyMat2, start, end, new Scalar(255,0,0), 1);
}

Bitmap grayBmp2 = Bitmap.createBitmap(bmp.getWidth(), bmp.getHeight(), Config.RGB_565);
Utils.matToBitmap(mCannyMat2, grayBmp2);

imageView.setImageBitmap(grayBmp2);
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值