2

In answer to another question, Sushanth stated:

The lowest point of the rectangle(does not matter left or right) will always be the first sub-list of the "box" ndarray. So in the example I have given, the first sub-list [169 144] represents the "bottom right of this rectangle". Now this point will be the reference point to decide what the next sub-list represents. Meaning, the next sub-list will always represent the point that you first get when you move in the clockwise direction. (as shown in the second image of the for loop)

I don't understand how to tell if the lowest point is the bottom-left or bottom-right point on the bases of the "first sub-list".

I need to create a generalized code that can tell them apart so that I can reliably apply warpAffine transformation to a dataset of images (as shown here).

Cody Gray - on strike
  • 239,200
  • 50
  • 490
  • 574

2 Answers2

0

I learned later on that I actually didn't need that information for performing warpAffine transformation as the angle information is returned by minAreaRect

def warp_contour(img,cnt):
    rows, cols = img.shape
    
    rect = cv2.minAreaRect(cnt)
    center,_,angle = rect
    
    box = cv2.boxPoints(rect)
    box = np.int0(box)
    
    rot = cv2.getRotationMatrix2D(center, angle, 1)
    img = cv2.warpAffine(img, rot, (rows,cols))
    
    return img

But I won't be accepting this answer as I still want to know how to tell them apart.

0

This is Sushanth's answer to my question:

To determine whether it is a bottom-left or right in a scenario when the two bottom points have the same y-coordinate: i. First, have a conditional statement to see whether the two bottom points have the same y-coordinate. ii. If the condition is True, then check which coordinate has the lowest x-value(or the highest). The coordinate with the lowest x-value will be bottom-left of course! "How did you determine this just by looking at the sub-list?" -- I did not determine it by just looking at it! I could not! This is exactly why I wrote the above for-loop in my answer!

with minor spelling corrections from my side