mirror of
https://github.com/openmv/openmv.git
synced 2025-11-04 14:49:50 +08:00
Add copy to framebuffer function and example script.
This commit is contained in:
parent
86b038df33
commit
d9b03641f7
@ -188,6 +188,16 @@ static mp_obj_t py_image_copy(uint n_args, const mp_obj_t *args, mp_map_t *kw_ar
|
|||||||
return img_obj;
|
return img_obj;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static mp_obj_t py_image_copy_to_fb(uint n_args, const mp_obj_t *args, mp_map_t *kw_args)
|
||||||
|
{
|
||||||
|
image_t *arg_img = py_image_cobj(args[0]);
|
||||||
|
fb->w = arg_img->w;
|
||||||
|
fb->h = arg_img->h;
|
||||||
|
fb->bpp = arg_img->bpp;
|
||||||
|
memcpy(fb->pixels, arg_img->pixels, fb->w * fb->h * fb->bpp);
|
||||||
|
return mp_const_true;
|
||||||
|
}
|
||||||
|
|
||||||
static mp_obj_t py_image_save(uint n_args, const mp_obj_t *args, mp_map_t *kw_args)
|
static mp_obj_t py_image_save(uint n_args, const mp_obj_t *args, mp_map_t *kw_args)
|
||||||
{
|
{
|
||||||
image_t *arg_img = py_image_cobj(args[0]);
|
image_t *arg_img = py_image_cobj(args[0]);
|
||||||
@ -1203,6 +1213,7 @@ static mp_obj_t py_image_find_keypoints(uint n_args, const mp_obj_t *args, mp_ma
|
|||||||
|
|
||||||
/* Image file functions */
|
/* Image file functions */
|
||||||
STATIC MP_DEFINE_CONST_FUN_OBJ_KW(py_image_copy_obj, 1, py_image_copy);
|
STATIC MP_DEFINE_CONST_FUN_OBJ_KW(py_image_copy_obj, 1, py_image_copy);
|
||||||
|
STATIC MP_DEFINE_CONST_FUN_OBJ_KW(py_image_copy_to_fb_obj, 1, py_image_copy_to_fb);
|
||||||
STATIC MP_DEFINE_CONST_FUN_OBJ_KW(py_image_save_obj, 2, py_image_save);
|
STATIC MP_DEFINE_CONST_FUN_OBJ_KW(py_image_save_obj, 2, py_image_save);
|
||||||
STATIC MP_DEFINE_CONST_FUN_OBJ_KW(py_image_compress_obj, 1, py_image_compress);
|
STATIC MP_DEFINE_CONST_FUN_OBJ_KW(py_image_compress_obj, 1, py_image_compress);
|
||||||
STATIC MP_DEFINE_CONST_FUN_OBJ_KW(py_image_compressed_obj, 1, py_image_compressed);
|
STATIC MP_DEFINE_CONST_FUN_OBJ_KW(py_image_compressed_obj, 1, py_image_compressed);
|
||||||
@ -1260,6 +1271,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_KW(py_image_find_keypoints_obj, 1, py_image_find_
|
|||||||
static const mp_map_elem_t locals_dict_table[] = {
|
static const mp_map_elem_t locals_dict_table[] = {
|
||||||
/* Image file functions */
|
/* Image file functions */
|
||||||
{MP_OBJ_NEW_QSTR(MP_QSTR_copy), (mp_obj_t)&py_image_copy_obj},
|
{MP_OBJ_NEW_QSTR(MP_QSTR_copy), (mp_obj_t)&py_image_copy_obj},
|
||||||
|
{MP_OBJ_NEW_QSTR(MP_QSTR_copy_to_fb), (mp_obj_t)&py_image_copy_to_fb_obj},
|
||||||
{MP_OBJ_NEW_QSTR(MP_QSTR_save), (mp_obj_t)&py_image_save_obj},
|
{MP_OBJ_NEW_QSTR(MP_QSTR_save), (mp_obj_t)&py_image_save_obj},
|
||||||
{MP_OBJ_NEW_QSTR(MP_QSTR_compress), (mp_obj_t)&py_image_compress_obj},
|
{MP_OBJ_NEW_QSTR(MP_QSTR_compress), (mp_obj_t)&py_image_compress_obj},
|
||||||
{MP_OBJ_NEW_QSTR(MP_QSTR_compressed), (mp_obj_t)&py_image_compressed_obj},
|
{MP_OBJ_NEW_QSTR(MP_QSTR_compressed), (mp_obj_t)&py_image_compressed_obj},
|
||||||
|
|||||||
@ -23,6 +23,7 @@ Q(match_descriptor)
|
|||||||
|
|
||||||
// Image class
|
// Image class
|
||||||
Q(copy)
|
Q(copy)
|
||||||
|
Q(copy_to_fb)
|
||||||
Q(save)
|
Q(save)
|
||||||
Q(compress)
|
Q(compress)
|
||||||
Q(compressed)
|
Q(compressed)
|
||||||
|
|||||||
24
usr/examples/03-Drawing/copy2fb.py
Normal file
24
usr/examples/03-Drawing/copy2fb.py
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
# Copy image to framebuffer.
|
||||||
|
#
|
||||||
|
# This example shows how to load and copy an image to framebuffer for testing.
|
||||||
|
|
||||||
|
import sensor, image
|
||||||
|
|
||||||
|
# Still need to init sensor
|
||||||
|
sensor.reset()
|
||||||
|
# Set sensor settings
|
||||||
|
sensor.set_contrast(1)
|
||||||
|
sensor.set_gainceiling(16)
|
||||||
|
|
||||||
|
# Set sensor pixel format
|
||||||
|
sensor.set_framesize(sensor.QQVGA)
|
||||||
|
sensor.set_pixformat(sensor.GRAYSCALE)
|
||||||
|
|
||||||
|
# Load image
|
||||||
|
img = image.Image("/image.pgm")
|
||||||
|
|
||||||
|
# Copy image to framebuffer
|
||||||
|
img.copy_to_fb()
|
||||||
|
|
||||||
|
# Update drawing
|
||||||
|
sensor.snapshot()
|
||||||
Loading…
Reference in New Issue
Block a user