1

I have an image from which i have created some lines. I have saved starting and end points of line. Lines are basically long side of rectangle that is bounding a white blob in image. Rectangles are placed in some circle. Image is shown as below image description

Issue is when rectangle is formed in the lower part of circle, Starting point can be thought as the lower most Point of the circle i.e near the edge of circle, but when Rectangle is formed in the upper part of the circle as shown in the last dial of the image it is difficult to find out which point to choose as the starting point to find out the starting point which is near center of the dial.

Is there any workaround on how i can swap points of line in upper region of circle. Kindly guide me as i am out of ideas with this now.

Here is code to select longest side of rectangle and printing its points

int maxIndex = 0;
for (int a = 1; a < length.length; a++){
    double newnumber = length[a];
    if ((newnumber > length[maxIndex])){
        maxIndex = a;
    }
} 
System.out.println("Start= "+pts[maxIndex].toString()+" End= "+pts[(maxIndex+1)%4].toString()+", Length="+length[maxIndex]);

Regards,

Saghir A. Khatri
  • 3,429
  • 6
  • 45
  • 76
  • `RotatedRect` has an `angle` [property](http://docs.opencv.org/java/2.4.2/org/opencv/core/RotatedRect.html#angle) – Miki Aug 04 '15 at 13:58
  • @Miki I get angles in -ve values. i want them in 360degrees format. i found one of answer that is in 180degree. trying to extend that answer for 360 http://stackoverflow.com/a/21427814/659944 – Saghir A. Khatri Aug 05 '15 at 06:19

1 Answers1

0

Maybe it's a bludge, but the first thing that came to mind is to sum the Y values of the corners, dont divide by 4 though (not required). If they are above the threshold of 4*sum when the rectangle is horizontal then you know it's 'up'.

Use this in an IF statement to switch code for up and down cases...

int totalY = 0;

for(int i = 0; i < 4; i++){
    totalY += vectorOfYourPoints[i].y;
}

if(totalY > someThresholdYoullSet){
    //do the thing you need to do if it's UP
} else {
    //do the thing you need to do if it's DOWN
}
Lamar Latrell
  • 1,669
  • 13
  • 28