检测图像中的矩形并使用android中的open cv绘制轮廓

Dee*_*hel 5 android opencv

我正在开发应用程序,我必须检测矩形对象和绘制轮廓我正在使用Open cv android库....

我成功地检测到圆形并在图像内部绘制轮廓但反复无法检测方形或矩形并绘制....这是我的代码为圆形..

Bitmap imageBmp = BitmapFactory.decodeResource(MainActivityPDF.this.getResources(),R.drawable.loadingplashscreen);

Mat imgSource = new Mat(), imgCirclesOut = new Mat();

Utils.bitmapToMat(imageBmp , imgSource);

    //grey opencv
Imgproc.cvtColor(imgSource, imgSource, Imgproc.COLOR_BGR2GRAY);

Imgproc.GaussianBlur( imgSource, imgSource, new Size(9, 9), 2, 2 );
Imgproc.HoughCircles( imgSource, imgCirclesOut, Imgproc.CV_HOUGH_GRADIENT, 1, imgSource.rows()/8, 200, 100, 0, 0 );

float circle[] = new float[3];

for (int i = 0; i < imgCirclesOut.cols(); i++)
{
        imgCirclesOut.get(0, i, circle);
    org.opencv.core.Point center = new org.opencv.core.Point();
    center.x = circle[0];
    center.y = circle[1];
    Core.circle(imgSource, center, (int) circle[2], new Scalar(255,0,0,255), 4);
    }
    Bitmap bmp = Bitmap.createBitmap(imageBmp.getWidth(), imageBmp.getHeight(), Bitmap.Config.ARGB_8888);

    Utils.matToBitmap(imgSource, bmp);


    ImageView frame = (ImageView) findViewById(R.id.imageView1);

    //Bitmap bmp = Bitmap.createBitmap(100, 100, Bitmap.Config.ARGB_8888);
    frame.setImageBitmap(bmp);
Run Code Online (Sandbox Code Playgroud)

任何帮助检测android的方形/矩形......我想知道2天..每个例子都是在C++或C++中我无法通过这些语言......

谢谢.

00z*_*tti 0

通过使用霍夫变换,您走在正确的道路上。您必须使用 Houghlines 并检查获得的线是否有交点,而不是使用 Houghcircles。如果你确实必须找到矩形(而不是 4 个有边多边形) - 你应该寻找具有相同角度(+- 小偏移)的线,如果你找到至少一对这样的线,你必须寻找放置的线与此垂直,也找到一对并检查交叉点。使用向量(端点 - 起点)和线来执行角度和相交测试应该不是什么大问题。