我正在开发应用程序,我必须检测矩形对象和绘制轮廓我正在使用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);

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

谢谢.

Logo

为开发者提供学习成长、分享交流、生态实践、资源工具等服务,帮助开发者快速成长。

更多推荐