facebookresearch / fairo

A modular embodied agent architecture and platform for building embodied agents
MIT License
843 stars 87 forks source link

Harmonize opencv and numpy coordinate conversions #358

Open anuragprat1k opened 3 years ago

anuragprat1k commented 3 years ago

Type of Issue

OpenCV

0/0---X--->
 |
 |
 Y
 |
 |
 v

Numpy

0/0---column--->
 |
 |
row
 |
 |
 v

We deal with this conversion in the perception stack to make things work but don't have clear types or boundaries defined which creates a minefield for bugs that you have to tread about carefully. Fix this.

Select the type of issue:

soumith commented 3 years ago

from the diagram, are you saying that they are the same co-ordinate system?

anuragprat1k commented 3 years ago

from the diagram, are you saying that they are the same co-ordinate system?

the axis ordering is different because of how indexing works in each - a point at (a,b) in one is at (b,a) in the other.

soumith commented 3 years ago

oh i see, OpenCV returns[x,y] and numpy returns[row, column], got it. I'd have expected OpenCV to return [y, x]. Actually I quickly googled, and they say OpenCV is indeed row-major and returns accessors as [y, x]: https://stackoverflow.com/questions/8184053/accessing-elements-of-a-cvmat-with-atfloati-j-is-it-x-y-or-row-col

anuragprat1k commented 3 years ago

right, that is part of the problem - the order of opencv image coordinate system is the reverse of what you would need for row-major access. So, if you have (x,y) in opencv image coordinates (as in the diagram above), row-major access means you'll need to still use (y,x) to access it (see one of the answers from above https://stackoverflow.com/a/42327350)

soumith commented 3 years ago

that's also what I'm saying.

Whether you use numpy or OpenCV, you use row-major. So they are consistent.