Android的OpenCV的绘图霍夫线 [英] Android OpenCV Drawing Hough Lines

查看:159
本文介绍了Android的OpenCV的绘图霍夫线的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用OpenCV的在Android手机上检测线。我修改了教程1基本 - 2.使用OpenCV的摄像头的样品。我也使用霍夫线变换作为一个例子。 不过,我越来越怪异号码(至少我认为是怪异的数字)的点。范围为1000 -1000为湾

我不完全理解code(主要是对加/减1000 *(一个或部分-b))。

在最后,我没有看到行的。

谁能给我个忙吗?也让我知道如果你需要更多的信息。

  capture.retrieve(mGray,Highgui.CV_CAP_ANDROID_GREY_FRAME);
Imgproc.Canny(mGray,mIntermediateMat,80,100);
Imgproc.HoughLines(mIntermediateMat,mLines,1,Math.PI / 180,100);

标颜色=新的标量(0,0,255);

双[]的数据;
双RHO,THETA;
点PT1 =新的点();
点PT2 =新的点();
双A,B;
双X0,Y0;
的for(int i = 0; I< mLines.cols();我++)
{
    数据= mLines.get(0,I);
    rho沸石=数据[0];
    THETA =数据[1];
    A = Math.cos(THETA);
    B = Math.sin(THETA);
    X0 = A * RHO;
    Y0 = B * RHO;
    pt1.x = Math.round(X0 +​​ 1000 *( -  B));
    pt1.y = Math.round(Y0 + 1000 * A);
    pt2.x = Math.round(X0  -  1000 *( -  B));
    pt2.y = Math.round(Y0  -  1000 * A);
    Core.line(mIntermediateMat,PT1,PT2,色彩,3);
}

Imgproc.cvtColor(mIntermediateMat,mRgba,Imgproc.COLOR_GRAY2BGRA,4);

BMP位= Bitmap.createBitmap(mRgba.cols(),mRgba.rows(),Bitmap.Config.ARGB_8888);

如果(Utils.matToBitmap(mRgba,BMP))
    返回BMP;

bmp.recycle();
返回null;
 

解决方案

我使用的<一个href="http://opencv.itseez.com/modules/imgproc/doc/feature_detection.html#houghlinesp">HoughLineP找到我的框线,并吸引他们回来。

下面是我的code ...希望这会有所帮助。

 垫mYuv =新垫();
    垫mRgba =新垫();
    垫thresholdImage =新垫(getFrameHeight()+ getFrameHeight()/ 2,getFrameWidth(),CvType.CV_8UC1);
    mYuv.put(0,0,数据);
    Imgproc.cvtColor(mYuv,mRgba,Imgproc.COLOR_YUV420sp2RGB,4);
    Imgproc.cvtColor(mRgba,thresholdImage,Imgproc.COLOR_RGB2GRAY,4);
    Imgproc.Canny(thresholdImage,thresholdImage,80,100,3);
    垫线=新材料();
    INT阈值= 50;
    INT minLineSize = 20;
    INT lineGap = 20;

    Imgproc.HoughLinesP(thresholdImage,线,1,Math.PI / 180,阈值,minLineSize,lineGap);

    为(中间体X = 0 X  - 其中; lines.cols(); X ++)
    {
          双[] VEC = lines.get(0,X);
          双X1 = vec的[0],
                 Y1 = vec的[1],
                 X2 = vec的[2],
                 Y2 = vec的[3];
          点开始=新的点(X1,Y1);
          点结束=新的点(x2,y2);

          Core.line(mRgba,开始,结束,新的标量(255,0,0),3);

    }

    BMP位= Bitmap.createBitmap(getFrameWidth(),getFrameHeight(),Bitmap.Config.ARGB_8888);

    如果(Utils.matToBitmap(mRgba,BMP))
         返回BMP;
 

I am trying to use OpenCV on an android phone to detect lines. I modified the 'Tutorial 1 Basic - 2. Use OpenCV Camera' sample. I am also using Hough Line Transform as an example. However, I am getting weird numbers (at least what I believe to be weird numbers) for the points. In the range 1000 to -1000 for b.

I don't fully understand the code (mostly the part about adding/subtracting 1000 * (a or -b)).

In the end I do not see the lines at all.

Could anyone give me a hand? Also let me know if you need more information.

capture.retrieve(mGray, Highgui.CV_CAP_ANDROID_GREY_FRAME);
Imgproc.Canny(mGray, mIntermediateMat, 80, 100);
Imgproc.HoughLines(mIntermediateMat, mLines, 1, Math.PI/180, 100);

Scalar color = new Scalar(0, 0, 255);

double[] data;
double rho, theta;
Point pt1 = new Point();
Point pt2 = new Point();
double a, b;
double x0, y0;
for (int i = 0; i < mLines.cols(); i++)
{
    data = mLines.get(0, i);
    rho = data[0];
    theta = data[1];
    a = Math.cos(theta);
    b = Math.sin(theta);
    x0 = a*rho;
    y0 = b*rho;
    pt1.x = Math.round(x0 + 1000*(-b));
    pt1.y = Math.round(y0 + 1000*a);
    pt2.x = Math.round(x0 - 1000*(-b));
    pt2.y = Math.round(y0 - 1000 *a);
    Core.line(mIntermediateMat, pt1, pt2, color, 3);
}

Imgproc.cvtColor(mIntermediateMat, mRgba, Imgproc.COLOR_GRAY2BGRA, 4);

Bitmap bmp = Bitmap.createBitmap(mRgba.cols(), mRgba.rows(), Bitmap.Config.ARGB_8888);

if (Utils.matToBitmap(mRgba, bmp))
    return bmp;

bmp.recycle();
return null;

解决方案

I am using HoughLineP to find lines in my frame and draw them back out.

Here is my code... hope this helps.

    Mat mYuv = new Mat();
    Mat mRgba = new Mat();
    Mat thresholdImage = new Mat(getFrameHeight() + getFrameHeight() / 2, getFrameWidth(), CvType.CV_8UC1);
    mYuv.put(0, 0, data);
    Imgproc.cvtColor(mYuv, mRgba, Imgproc.COLOR_YUV420sp2RGB, 4);
    Imgproc.cvtColor(mRgba, thresholdImage, Imgproc.COLOR_RGB2GRAY, 4);
    Imgproc.Canny(thresholdImage, thresholdImage, 80, 100, 3);
    Mat lines = new Mat();
    int threshold = 50;
    int minLineSize = 20;
    int lineGap = 20;

    Imgproc.HoughLinesP(thresholdImage, lines, 1, Math.PI/180, threshold, minLineSize, lineGap);

    for (int x = 0; x < lines.cols(); x++) 
    {
          double[] vec = lines.get(0, x);
          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);

          Core.line(mRgba, start, end, new Scalar(255,0,0), 3);

    }

    Bitmap bmp = Bitmap.createBitmap(getFrameWidth(), getFrameHeight(), Bitmap.Config.ARGB_8888);

    if (Utils.matToBitmap(mRgba, bmp))
         return bmp;

这篇关于Android的OpenCV的绘图霍夫线的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆