Code Monkey home page Code Monkey logo

Comments (6)

Neutree avatar Neutree commented on May 29, 2024

maybe you can use image.Image() now, this create a image with size 320x240 and RGB565 format

from maixpy-v1.

edward687 avatar edward687 commented on May 29, 2024

maybe you can use image.Image() now, this create a image with size 320x240 and RGB565 format
God, How to rewrite the following code with
extra_fb = sensor.alloc_extra_fb(sensor.width(), sensor.height(), sensor.RGB565) extra_fb.replace(sensor.snapshot())

from maixpy-v1.

sw-dev-code avatar sw-dev-code commented on May 29, 2024

@Neutree Can you send me an example of image.Image usage because when I'm using as extra_fb = image.Image(size=(320, 240)) I'm getting out of heap memory error.

Even when I lower the resolution to 176, 120 error remains.

My goal is to use this openMV example: in_memory_basic_frame_differencing.py

Board is MaixCube.

from maixpy-v1.

Neutree avatar Neutree commented on May 29, 2024

@MIlan991 you can change gc size bigger by

from Maix import utils
utils.gc_heap_size(new_size)

default is 512*1024

from maixpy-v1.

sw-dev-code avatar sw-dev-code commented on May 29, 2024

@Neutree Thank you. I will try it. What is the maximum size I can set with MaixCube?

from maixpy-v1.

sw-dev-code avatar sw-dev-code commented on May 29, 2024

@Neutree I've given it a test but without success. Still getting the error even when heap size is increased to 2048*1024. The function that creates this error is img.get_histogram(). When I remove that function everything works well.

Code:

# In Memory Basic Frame Differencing Example
#
# This example demonstrates using frame differencing with your OpenMV Cam. It's
# called basic frame differencing because there's no background image update.
# So, as time passes the background image may change resulting in issues.

import sensor, image, os
from Maix import utils

TRIGGER_THRESHOLD = 5

utils.gc_heap_size(2048 * 1024)

sensor.reset()                      # Reset and initialize the sensor. It will
                                    # run automatically, call sensor.run(0) to stop
sensor.set_pixformat(sensor.RGB565) # Set pixel format to RGB565 (or GRAYSCALE)
sensor.set_framesize(sensor.QQQQVGA)   # 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.

print("About to save background image...")
gc.enable()
extra_fb = image.Image(size=(40, 30), copy_to_fb = False)
sensor.skip_frames(time = 2000) # Give the user time to get ready.
extra_fb.replace(sensor.snapshot())
print("Saved background image - Now frame differencing!")

while(True):
    clock.tick() # Track elapsed milliseconds between snapshots().
    img = sensor.snapshot() # Take a picture and return the image.
    # Replace the image with the "abs(NEW-OLD)" frame difference.
    img.difference(extra_fb)

    hist = img.get_histogram()
    # This code below works by comparing the 99th percentile value (e.g. the
    # non-outlier max value against the 90th percentile value (e.g. a non-max
    # value. The difference between the two values will grow as the difference
    # image seems more pixels change.
    diff = hist.get_percentile(0.99).l_value() - hist.get_percentile(0.90).l_value()
    triggered = diff > TRIGGER_THRESHOLD

    print(clock.fps(), triggered, gc.mem_free()) # Note: Your OpenMV Cam runs about half as fast while
    # connected to your computer. The FPS should increase once disconnected.
    gc.collect()

from maixpy-v1.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.