Search code examples
javaandroidsortingopencvbounding-box

Equaling bounding box to another bounding box : Opencv , Android


I am trying to sort bounding boxes and in my algo I have a line in which bounding box of index j is equaling index j+1

 contourRects.get(j) = contourRects.get(j+1);

But it gives an error that left hand side can only be variable.

EDIT:

                int j;
                boolean flag = true;
                Rect temp;

                while(flag)
                {
                    flag = false;

                    for(j=0; j<contourRects.size(); j++)
                    {
                        if(contourRects.get(j).y < contourRects.get(j+1).y)
                        {
                            temp = contourRects.get(j);
                            contourRects(j) = contourRects.get(j+1);
                            contourRects.get(j+1) = temp;
                        }
                    }
                }

And one more thing contoursRect is a list

List<Rect> contourRects = new ArrayList();

Solution

  • You can use the f.f.g code:

    Collections.swap(contourRects, j, j + 1);
    

    Instead of:

     temp = contourRects.get(j);
     contourRects(j) = contourRects.get(j+1);
     contourRects.get(j+1) = temp;