How to fast Create new Image

Discussion related to "under the hood" OpenMV topics.
skylin008
Posts: 65
Joined: Mon Mar 13, 2017 10:18 pm

How to fast Create new Image

Postby skylin008 » Wed Oct 16, 2019 6:03 am

Hello everyone!Now I had copy/crop the image accroding the ROI. How to fast clear the Old Image(size:320x240) and Create new Image accroding the ROI point width and heigh(40x50).Thanks !
User avatar
kwagyeman
Posts: 4271
Joined: Sun May 24, 2015 2:10 pm

Re: How to fast Create new Image

Postby kwagyeman » Wed Oct 16, 2019 2:14 pm

Not quite sure what you are trying to do? Have you looked at copy(), clear(), Image()?
Nyamekye,
skylin008
Posts: 65
Joined: Mon Mar 13, 2017 10:18 pm

Re: How to fast Create new Image

Postby skylin008 » Wed Oct 16, 2019 8:18 pm

Thanks kwagyeman for kindly support.I want to only show img17 in IDE from this code.But it glitter always.Thanks!

Code: Select all

# Hello World Example
#
# Welcome to the OpenMV IDE! Click on the green run arrow button below to run the script!

import sensor, image, time
import gc

sensor.reset()                      # Reset and initialize the sensor.
sensor.set_pixformat(sensor.RGB565) # Set pixel format to RGB565 (or GRAYSCALE)
sensor.set_framesize(sensor.QVGA)   # Set frame size to QVGA (320x240)
sensor.skip_frames(time = 2000)     # Wait for settings take effect.
clock = time.clock()                # Create a clock object to track the FPS.

while(True):
    clock.tick()                    # Update the FPS clock.
    img = sensor.snapshot()         # Take a picture and return the image.

    img1 = img.copy(roi = (40,145,40,2), x_scale = 1.0, y_scale = 1.0)
    img.draw_image(img1,0,0)


    img2 = img.copy(roi = (82,145,40,2), x_scale = 1.0, y_scale = 1.0)
    img.draw_image(img2,0,2)

    img3 = img.copy(roi = (114,145,40,2),x_scale = 1.0, y_scale = 1.0)
    img.draw_image(img3,0,4)

    for i in range(1,21):
        img4 = img.copy(roi = (140,(138+(i-1)*3),2,2),x_scale = 1.0, y_scale = 1.0)
        img.draw_image(img4, (0+(i-1)*2), 6)


    for i in range(1,21):
        img5 = img.copy(roi = (160,(138+(i-1)*3),2,2),x_scale = 1.0, y_scale = 1.0)
        img.draw_image(img5, (0+(i-1)*2), 8)


    for i in range(1,21):
        img6 = img.copy(roi = (176,(130+(i-1)*4),2,2),x_scale = 1.0, y_scale = 1.0)
        img.draw_image(img6, (0+(i-1)*2), 10)


    for i in range(1,21):
        img7 = img.copy(roi = (189,(130 + (i-1)*4), 2,2),x_scale =1.0, y_scale = 1.0)
        img.draw_image(img7, (0+(i-1)*2), 12)


    for i in range(1,21):
        img8 = img.copy(roi = (200,(123 + (i-1)*4), 2,3),x_scale =1.0, y_scale = 1.0)
        img.draw_image(img8, (0+(i-1)*2), 14)

    for i in range(1,21):
        img9 = img.copy(roi = (208,(115 + (i-1)*5), 2,3),x_scale =1.0, y_scale = 1.0)
        img.draw_image(img9, (0+(i-1)*2), 17)

    for i in range(1,21):
        img10 = img.copy(roi = (214,(108 + (i-1)*5), 2,4),x_scale =1.0, y_scale = 1.0)
        img.draw_image(img10, (0+(i-1)*2), 20)

    for i in range(1,21):
        img11 = img.copy(roi = (220,(100 + (i-1)*6), 2,4),x_scale =1.0, y_scale = 1.0)
        img.draw_image(img11, (0+(i-1)*2), 24)

    for i in range(1,21):
        img12 = img.copy(roi = (224,(93 + (i-1)*6), 2,5),x_scale =1.0, y_scale = 1.0)
        img.draw_image(img12, (0+(i-1)*2), 28)

    for i in range(1,21):
        img13 = img.copy(roi = (227,(85+ (i-1) * 6), 2,5), x_scale = 1.0, y_scale = 1.0)
        img.draw_image(img13, (0+(i-1)*2), 33)

    for i in range(1,21):
        img14 = img.copy(roi = (230,(78 + (i-1) * 7), 2, 6),x_scale = 1.0, y_scale = 1.0)
        img.draw_image(img14, (0 + (i-1) * 2), 39)

    for i in range(1,21):
        img15 = img.copy(roi = (232, (70 + (i-1) *7 ), 2, 6),x_scale = 1.0, y_scale = 1.0)
        img.draw_image(img15, (0 + (i-1) * 2), 45)

    for i in range(1,21):
        img16 = img.copy(roi = (234, (70 + (i-1) * 7), 2, 6),x_scale = 1.0, y_scale = 1.0)
        img.draw_image(img16 , (0 + (i -1)*2), 51)

    img17 = img.copy(roi = (0, 0, 40, 51), x_scale = 1.0, y_scale = 1.0, copy_to_fb = True)
    img.clear()
    img.draw_image(img17, 50, 50)





    print(clock.fps())              # Note: OpenMV Cam runs about half as fast when connected
                                    # to the IDE. The FPS should increase once disconnected.

User avatar
kwagyeman
Posts: 4271
Joined: Sun May 24, 2015 2:10 pm

Re: How to fast Create new Image

Postby kwagyeman » Thu Oct 17, 2019 12:53 pm

Code: Select all

# Hello World Example
#
# Welcome to the OpenMV IDE! Click on the green run arrow button below to run the script!

import sensor, image, time
import gc

sensor.reset()                      # Reset and initialize the sensor.
sensor.set_pixformat(sensor.RGB565) # Set pixel format to RGB565 (or GRAYSCALE)
sensor.set_framesize(sensor.QVGA)   # Set frame size to QVGA (320x240)
sensor.skip_frames(time = 2000)     # Wait for settings take effect.
clock = time.clock()                # Create a clock object to track the FPS.

while(True):
    clock.tick()                    # Update the FPS clock.
    img = sensor.snapshot()         # Take a picture and return the image.

    img1 = img.copy(roi = (40,145,40,2), x_scale = 1.0, y_scale = 1.0)
    img.draw_image(img1,0,0)


    img2 = img.copy(roi = (82,145,40,2), x_scale = 1.0, y_scale = 1.0)
    img.draw_image(img2,0,2)

    img3 = img.copy(roi = (114,145,40,2),x_scale = 1.0, y_scale = 1.0)
    img.draw_image(img3,0,4)

    for i in range(1,21):
        img4 = img.copy(roi = (140,(138+(i-1)*3),2,2),x_scale = 1.0, y_scale = 1.0)
        img.draw_image(img4, (0+(i-1)*2), 6)


    for i in range(1,21):
        img5 = img.copy(roi = (160,(138+(i-1)*3),2,2),x_scale = 1.0, y_scale = 1.0)
        img.draw_image(img5, (0+(i-1)*2), 8)


    for i in range(1,21):
        img6 = img.copy(roi = (176,(130+(i-1)*4),2,2),x_scale = 1.0, y_scale = 1.0)
        img.draw_image(img6, (0+(i-1)*2), 10)


    for i in range(1,21):
        img7 = img.copy(roi = (189,(130 + (i-1)*4), 2,2),x_scale =1.0, y_scale = 1.0)
        img.draw_image(img7, (0+(i-1)*2), 12)


    for i in range(1,21):
        img8 = img.copy(roi = (200,(123 + (i-1)*4), 2,3),x_scale =1.0, y_scale = 1.0)
        img.draw_image(img8, (0+(i-1)*2), 14)

    for i in range(1,21):
        img9 = img.copy(roi = (208,(115 + (i-1)*5), 2,3),x_scale =1.0, y_scale = 1.0)
        img.draw_image(img9, (0+(i-1)*2), 17)

    for i in range(1,21):
        img10 = img.copy(roi = (214,(108 + (i-1)*5), 2,4),x_scale =1.0, y_scale = 1.0)
        img.draw_image(img10, (0+(i-1)*2), 20)

    for i in range(1,21):
        img11 = img.copy(roi = (220,(100 + (i-1)*6), 2,4),x_scale =1.0, y_scale = 1.0)
        img.draw_image(img11, (0+(i-1)*2), 24)

    for i in range(1,21):
        img12 = img.copy(roi = (224,(93 + (i-1)*6), 2,5),x_scale =1.0, y_scale = 1.0)
        img.draw_image(img12, (0+(i-1)*2), 28)

    for i in range(1,21):
        img13 = img.copy(roi = (227,(85+ (i-1) * 6), 2,5), x_scale = 1.0, y_scale = 1.0)
        img.draw_image(img13, (0+(i-1)*2), 33)

    for i in range(1,21):
        img14 = img.copy(roi = (230,(78 + (i-1) * 7), 2, 6),x_scale = 1.0, y_scale = 1.0)
        img.draw_image(img14, (0 + (i-1) * 2), 39)

    for i in range(1,21):
        img15 = img.copy(roi = (232, (70 + (i-1) *7 ), 2, 6),x_scale = 1.0, y_scale = 1.0)
        img.draw_image(img15, (0 + (i-1) * 2), 45)

    for i in range(1,21):
        img16 = img.copy(roi = (234, (70 + (i-1) * 7), 2, 6),x_scale = 1.0, y_scale = 1.0)
        img.draw_image(img16 , (0 + (i -1)*2), 51)

    img17 = img.copy(roi = (0, 0, 40, 51), x_scale = 1.0, y_scale = 1.0)
    img.clear()
    img.draw_image(img17, 50, 50)





    print(clock.fps())              # Note: OpenMV Cam runs about half as fast when connected
                                    # to the IDE. The FPS should increase once disconnected.
? I removed the copy_to_fb call at the end. I have no clue what you are trying to do however.
Nyamekye,

Return to “Technical Discussion”

Who is online

Users browsing this forum: No registered users and 13 guests