Exchange the X and Y axis ...

Discussion related to "under the hood" OpenMV topics.
CMCheng
Posts: 9
Joined: Mon Aug 14, 2017 11:24 pm

Exchange the X and Y axis ...

Postby CMCheng » Tue May 21, 2019 9:59 pm

Hello,

Maybe it is a dumb question ... :lol: Is there any method to map the X axis to the Y and the Y to the X of the image object?

My application needs to see more on the vertical field so I rotate the camera by 90 degree. It works fine except that the X axis now becomes the vertical and Y becomes horizontal. I am thinking if the output of the sensor can have the X and Y exchanged, then everything will become "native". Is there any simple method to do that? Thanks!

Regards,
CM Cheng
User avatar
iabdalkader
Posts: 844
Joined: Sun May 24, 2015 3:53 pm

Re: Exchange the X and Y axis ...

Postby iabdalkader » Tue May 21, 2019 10:14 pm

Do you need to rotate the image ? See replace and transpose:

http://docs.openmv.io/library/omv.image ... ge.replace
CMCheng
Posts: 9
Joined: Mon Aug 14, 2017 11:24 pm

Re: Exchange the X and Y axis ...

Postby CMCheng » Wed May 22, 2019 1:48 am

Thanks for the reply. I tried the transpose and it works. However, it seems that there is some significant fps drop. I used the default code to test. Changed it to GRAYSCALE so the fps is larger and any changes to it is easier to notice.

The fps of the original code is over 50.
With the first "replace" it reduces the fps to 30.
With the two "replace" the fps drops to 24.

I am thinking if there is any method that do this in lower / hardware level. It is "native" so there is no fps drop. Like "QVGA" is not by software scaling down the "VGA".

Best regards,
CM Cheng

Code: Select all

import sensor, image, time

sensor.reset()
sensor.set_pixformat(sensor.GRAYSCALE)
sensor.set_framesize(sensor.QVGA)
sensor.skip_frames(time = 2000)

clock = time.clock()

while(True):
    clock.tick()
    img = sensor.snapshot()
    img.replace(transpose=True)
    img.replace(hmirror=True)
    print(clock.fps())
User avatar
kwagyeman
Posts: 3055
Joined: Sun May 24, 2015 2:10 pm

Re: Exchange the X and Y axis ...

Postby kwagyeman » Wed May 22, 2019 3:01 am

Hi, you can do both operations with the same call:

Code: Select all

img.replace(transpose=True, hmirror=True)
The only way to do this faster is to turn on hmirror on the camera sensor. The camera sensor doesn't support transpose however. The camera sensor does support hmirror and vflip however.

...

If you want fast transpose you have to modify this C code: https://github.com/openmv/openmv/blob/m ... sor.c#L793

This method is what takes pixels from DMA and puts them into the image. It's called when lines from the camera come in. So, it's done while reviving the image. Adding a feature to transpose while it's running doesn't seem like a big deal.
Nyamekye,
CMCheng
Posts: 9
Joined: Mon Aug 14, 2017 11:24 pm

Re: Exchange the X and Y axis ...

Postby CMCheng » Wed May 22, 2019 9:41 pm

img.replace(transpose=True, hmirror=True): The result is different if I put them into two instructions.

For changing the C code, I think it is too difficult to me :? I just want to know if there is a simple (and fast) method to do the transpose that I could have missed from the documents. If there is not, I can "mentally transpose" the axis when writing the code. :lol:

Thank you very much for your input.

Best regards,
CM Cheng
User avatar
kwagyeman
Posts: 3055
Joined: Sun May 24, 2015 2:10 pm

Re: Exchange the X and Y axis ...

Postby kwagyeman » Wed May 22, 2019 9:51 pm

Hi, if the result is different then that just means you need to do another operation instead.

img.replace(transpose=True, hmirror=True, vflip=True)

Cycle through all eight possible values of True/False above until you get the one you want.
Nyamekye,
CMCheng
Posts: 9
Joined: Mon Aug 14, 2017 11:24 pm

Re: Exchange the X and Y axis ...

Postby CMCheng » Wed May 22, 2019 10:23 pm

Hello Nyamekye,

It is off topic. I have connection problem with my PC before ( viewtopic.php?t=406 ). The recent update seems fixed it. Thanks!!

CM Cheng

Return to “Technical Discussion”

Who is online

Users browsing this forum: No registered users and 2 guests