排序边界框与铊():opencv的机器人 [英] Sort bounding boxes with Tl() : Opencv Android

查看:180
本文介绍了排序边界框与铊():opencv的机器人的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图包围盒与Y轴进行排序,然后X轴,但结果我从TL找到()x和TL()。y的有点混乱,大量的工作后,我找不到任何东西文档。这里有一些结果,请看一看。我想他们是为了从1到30

I am trying to sort the bounding boxes with y axis and then x axis but the results I find from tl().x and tl().y are bit confusing and after lot of work I couldn't find anything in documentation. Here are some results please take a look. I want them to be in order from 1 to 30

code:

m = Utils.loadResource(MainActivity.this, R.drawable.sheet1, Highgui.CV_LOAD_IMAGE_COLOR);
//Mat original = Utils.loadResource(MainActivity.this, R.drawable.sheet1, Highgui.CV_LOAD_IMAGE_COLOR);
Bitmap bm = Bitmap.createBitmap(m.cols(), m.rows(),Bitmap.Config.ARGB_8888);

Imgproc.cvtColor(m, m, Imgproc.COLOR_BGR2GRAY);
Imgproc.medianBlur(m, m,3); 
Imgproc.threshold(m, m, 0, 255, Imgproc.THRESH_OTSU);
Core.bitwise_not(m, m);
Imgproc.dilate(m, m, Imgproc.getStructuringElement(Imgproc.MORPH_RECT, new Size(1,118)));

java.util.List<MatOfPoint> contours = new ArrayList<MatOfPoint>();                  
Imgproc.findContours(m.clone(), contours, new Mat() ,Imgproc.RETR_EXTERNAL , Imgproc.CHAIN_APPROX_SIMPLE);
Rect rect = Imgproc.boundingRect(contours.get(35));                         
Toast.makeText(MainActivity.this, "TL:"+rect.tl()+"BR:"+rect.br(), Toast.LENGTH_LONG).show();

编辑:

这是剪切区域和上面显示的坐标是这些框。

This is cropped region and the coordinates showing above are of these boxes.

原始图片:

推荐答案

所以,你要优先排序先从左到右,然后从上到下。 x坐标是更重要的,但是,对于的相似 X怎样才算是y。写一个排序功能,在其中您有伪code看起来像这样的关系:

So you want to sort with priority first left to right and then top to bottom. x coordinate is more important, however for similar x what counts is the y. Write a sorting function, in which you have a relationship which in pseudocode looks like this:

boolean isLessThan(bboxA,bboxB,unsigned int tolerance = 100) {

    if (bboxA.tl().x + tolerance < bboxB.tl().x);
         return true;
    if (bboxB.tl().x + tolerance < bboxA.tl().x);
         return false;
    return (bboxA.tl().y < bboxB.tl().y);

    }

(或硬code 宽容

这篇关于排序边界框与铊():opencv的机器人的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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