image drawstring() landscape orientation (or image rotation function)?

Discussion related to "under the hood" OpenMV topics.
User avatar
kwiley
Posts: 107
Joined: Fri Dec 21, 2018 5:22 pm

image drawstring() landscape orientation (or image rotation function)?

Postby kwiley » Fri Jan 11, 2019 12:56 pm

Is there a straightforward way to write text onto the image in landscape orientation? I see no parameters to Image.draw_string() that would do this out of the box.

Alternatively, is there correspondingly simple way to rotate an image (one could rotate, write text, then rotate back in order to maintain an upright display). Neither the sensor nor the image modules seem to offer rotation functions.

Thanks.
User avatar
iabdalkader
Posts: 939
Joined: Sun May 24, 2015 3:53 pm

Re: image drawstring() landscape orientation (or image rotation function)?

Postby iabdalkader » Fri Jan 11, 2019 6:02 pm

kwiley wrote:
Fri Jan 11, 2019 12:56 pm
Is there a straightforward way to write text onto the image in landscape orientation? I see no parameters to Image.draw_string() that would do this out of the box.

Alternatively, is there correspondingly simple way to rotate an image (one could rotate, write text, then rotate back in order to maintain an upright display). Neither the sensor nor the image modules seem to offer rotation functions.

Thanks.
No not that I know of, the text was originally added for displaying the FPS. If you like you could submit a feature request on github for text rotation (much easier, faster to implement than the alternative)
User avatar
kwagyeman
Posts: 3271
Joined: Sun May 24, 2015 2:10 pm

Re: image drawstring() landscape orientation (or image rotation function)?

Postby kwagyeman » Sat Jan 12, 2019 12:49 pm

Hi, the latest firmware build offers vertical and horizontal mirroring along with image rotation. This does exactly what you want.

Code: Select all

# Vertical Flip - Horizontal Mirror - Transpose
#
# This example shows off how to vertically flip, horizontally mirror, or
# transpose an image. Note that:
#
# vflip=False, hmirror=False, transpose=False -> 0 degree rotation
# vflip=True,  hmirror=False, transpose=True  -> 90 degree rotation
# vflip=True,  hmirror=True,  transpose=False -> 180 degree rotation
# vflip=False, hmirror=True,  transpose=True  -> 270 degree rotation

import sensor, image, time, pyb

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

mills = pyb.millis()
counter = 0

while(True):
    clock.tick()

    img = sensor.snapshot().replace(vflip=(counter//2)%2,
                                    hmirror=(counter//4)%2,
                                    transpose=(counter//8)%2)

    if (pyb.millis() > (mills + 1000)):
        mills = pyb.millis()
        counter += 1

    print(clock.fps())
Attachments
firmware.zip
(920.08 KiB) Downloaded 69 times
Nyamekye,
User avatar
kwiley
Posts: 107
Joined: Fri Dec 21, 2018 5:22 pm

Re: image drawstring() landscape orientation (or image rotation function)?

Postby kwiley » Sat Jan 12, 2019 8:04 pm

Thanks. It isn't a crucial feature. It's just nice to support more a traditional landscape orientation is all. I'll give it a shot.

Return to “Technical Discussion”

Who is online

Users browsing this forum: Bing [Bot] and 7 guests