mirror of
https://github.com/openmv/openmv.git
synced 2025-11-04 14:49:50 +08:00
Allow building the image library and modules without a filesystem.
* Images, models and descriptors I/O can be disabled with imlib flag. * Image creation in memory still works if image I/O is disabled. * TF and Haar can still load built-in models/cascades if image I/O is disabled.
This commit is contained in:
parent
7ea7bc01f7
commit
a0d7cf13ad
@ -11,6 +11,9 @@
|
|||||||
#ifndef __IMLIB_CONFIG_H__
|
#ifndef __IMLIB_CONFIG_H__
|
||||||
#define __IMLIB_CONFIG_H__
|
#define __IMLIB_CONFIG_H__
|
||||||
|
|
||||||
|
// Enable Image I/O
|
||||||
|
//#define IMLIB_ENABLE_IMAGE_IO
|
||||||
|
|
||||||
// Enable LAB LUT
|
// Enable LAB LUT
|
||||||
//#define IMLIB_ENABLE_LAB_LUT
|
//#define IMLIB_ENABLE_LAB_LUT
|
||||||
|
|
||||||
|
|||||||
@ -11,6 +11,9 @@
|
|||||||
#ifndef __IMLIB_CONFIG_H__
|
#ifndef __IMLIB_CONFIG_H__
|
||||||
#define __IMLIB_CONFIG_H__
|
#define __IMLIB_CONFIG_H__
|
||||||
|
|
||||||
|
// Enable Image I/O
|
||||||
|
#define IMLIB_ENABLE_IMAGE_IO
|
||||||
|
|
||||||
// Enable LAB LUT
|
// Enable LAB LUT
|
||||||
#define IMLIB_ENABLE_LAB_LUT
|
#define IMLIB_ENABLE_LAB_LUT
|
||||||
|
|
||||||
@ -121,9 +124,8 @@
|
|||||||
// Enable find_keypoints()
|
// Enable find_keypoints()
|
||||||
//#define IMLIB_ENABLE_FIND_KEYPOINTS
|
//#define IMLIB_ENABLE_FIND_KEYPOINTS
|
||||||
|
|
||||||
#if defined(IMLIB_ENABLE_FIND_LBP) || defined(IMLIB_ENABLE_FIND_KEYPOINTS)
|
// Enable load, save and match descriptor
|
||||||
#define IMLIB_ENABLE_DESCRIPTOR
|
//#define IMLIB_ENABLE_DESCRIPTOR
|
||||||
#endif
|
|
||||||
|
|
||||||
// Enable find_hog()
|
// Enable find_hog()
|
||||||
//#define IMLIB_ENABLE_HOG
|
//#define IMLIB_ENABLE_HOG
|
||||||
|
|||||||
@ -11,6 +11,9 @@
|
|||||||
#ifndef __IMLIB_CONFIG_H__
|
#ifndef __IMLIB_CONFIG_H__
|
||||||
#define __IMLIB_CONFIG_H__
|
#define __IMLIB_CONFIG_H__
|
||||||
|
|
||||||
|
// Enable Image I/O
|
||||||
|
#define IMLIB_ENABLE_IMAGE_IO
|
||||||
|
|
||||||
// Enable LAB LUT
|
// Enable LAB LUT
|
||||||
#define IMLIB_ENABLE_LAB_LUT
|
#define IMLIB_ENABLE_LAB_LUT
|
||||||
|
|
||||||
@ -131,9 +134,8 @@
|
|||||||
// Enable find_keypoints()
|
// Enable find_keypoints()
|
||||||
#define IMLIB_ENABLE_FIND_KEYPOINTS
|
#define IMLIB_ENABLE_FIND_KEYPOINTS
|
||||||
|
|
||||||
#if defined(IMLIB_ENABLE_FIND_LBP) || defined(IMLIB_ENABLE_FIND_KEYPOINTS)
|
// Enable load, save and match descriptor
|
||||||
#define IMLIB_ENABLE_DESCRIPTOR
|
#define IMLIB_ENABLE_DESCRIPTOR
|
||||||
#endif
|
|
||||||
|
|
||||||
// Enable find_hog()
|
// Enable find_hog()
|
||||||
#define IMLIB_ENABLE_HOG
|
#define IMLIB_ENABLE_HOG
|
||||||
|
|||||||
@ -11,6 +11,9 @@
|
|||||||
#ifndef __IMLIB_CONFIG_H__
|
#ifndef __IMLIB_CONFIG_H__
|
||||||
#define __IMLIB_CONFIG_H__
|
#define __IMLIB_CONFIG_H__
|
||||||
|
|
||||||
|
// Enable Image I/O
|
||||||
|
#define IMLIB_ENABLE_IMAGE_IO
|
||||||
|
|
||||||
// Enable LAB LUT
|
// Enable LAB LUT
|
||||||
#define IMLIB_ENABLE_LAB_LUT
|
#define IMLIB_ENABLE_LAB_LUT
|
||||||
|
|
||||||
@ -131,9 +134,8 @@
|
|||||||
// Enable find_keypoints()
|
// Enable find_keypoints()
|
||||||
#define IMLIB_ENABLE_FIND_KEYPOINTS
|
#define IMLIB_ENABLE_FIND_KEYPOINTS
|
||||||
|
|
||||||
#if defined(IMLIB_ENABLE_FIND_LBP) || defined(IMLIB_ENABLE_FIND_KEYPOINTS)
|
// Enable load, save and match descriptor
|
||||||
#define IMLIB_ENABLE_DESCRIPTOR
|
#define IMLIB_ENABLE_DESCRIPTOR
|
||||||
#endif
|
|
||||||
|
|
||||||
// Enable find_hog()
|
// Enable find_hog()
|
||||||
#define IMLIB_ENABLE_HOG
|
#define IMLIB_ENABLE_HOG
|
||||||
|
|||||||
@ -11,6 +11,9 @@
|
|||||||
#ifndef __IMLIB_CONFIG_H__
|
#ifndef __IMLIB_CONFIG_H__
|
||||||
#define __IMLIB_CONFIG_H__
|
#define __IMLIB_CONFIG_H__
|
||||||
|
|
||||||
|
// Enable Image I/O
|
||||||
|
#define IMLIB_ENABLE_IMAGE_IO
|
||||||
|
|
||||||
// Enable LAB LUT
|
// Enable LAB LUT
|
||||||
#define IMLIB_ENABLE_LAB_LUT
|
#define IMLIB_ENABLE_LAB_LUT
|
||||||
|
|
||||||
@ -131,9 +134,8 @@
|
|||||||
// Enable find_keypoints()
|
// Enable find_keypoints()
|
||||||
#define IMLIB_ENABLE_FIND_KEYPOINTS
|
#define IMLIB_ENABLE_FIND_KEYPOINTS
|
||||||
|
|
||||||
#if defined(IMLIB_ENABLE_FIND_LBP) || defined(IMLIB_ENABLE_FIND_KEYPOINTS)
|
// Enable load, save and match descriptor
|
||||||
#define IMLIB_ENABLE_DESCRIPTOR
|
#define IMLIB_ENABLE_DESCRIPTOR
|
||||||
#endif
|
|
||||||
|
|
||||||
// Enable find_hog()
|
// Enable find_hog()
|
||||||
#define IMLIB_ENABLE_HOG
|
#define IMLIB_ENABLE_HOG
|
||||||
|
|||||||
@ -11,6 +11,9 @@
|
|||||||
#ifndef __IMLIB_CONFIG_H__
|
#ifndef __IMLIB_CONFIG_H__
|
||||||
#define __IMLIB_CONFIG_H__
|
#define __IMLIB_CONFIG_H__
|
||||||
|
|
||||||
|
// Enable Image I/O
|
||||||
|
#define IMLIB_ENABLE_IMAGE_IO
|
||||||
|
|
||||||
// Enable LAB LUT
|
// Enable LAB LUT
|
||||||
#define IMLIB_ENABLE_LAB_LUT
|
#define IMLIB_ENABLE_LAB_LUT
|
||||||
|
|
||||||
@ -131,9 +134,8 @@
|
|||||||
// Enable find_keypoints()
|
// Enable find_keypoints()
|
||||||
#define IMLIB_ENABLE_FIND_KEYPOINTS
|
#define IMLIB_ENABLE_FIND_KEYPOINTS
|
||||||
|
|
||||||
#if defined(IMLIB_ENABLE_FIND_LBP) || defined(IMLIB_ENABLE_FIND_KEYPOINTS)
|
// Enable load, save and match descriptor
|
||||||
#define IMLIB_ENABLE_DESCRIPTOR
|
#define IMLIB_ENABLE_DESCRIPTOR
|
||||||
#endif
|
|
||||||
|
|
||||||
// Enable find_hog()
|
// Enable find_hog()
|
||||||
#define IMLIB_ENABLE_HOG
|
#define IMLIB_ENABLE_HOG
|
||||||
|
|||||||
@ -11,6 +11,9 @@
|
|||||||
#ifndef __IMLIB_CONFIG_H__
|
#ifndef __IMLIB_CONFIG_H__
|
||||||
#define __IMLIB_CONFIG_H__
|
#define __IMLIB_CONFIG_H__
|
||||||
|
|
||||||
|
// Enable Image I/O
|
||||||
|
#define IMLIB_ENABLE_IMAGE_IO
|
||||||
|
|
||||||
// Enable LAB LUT
|
// Enable LAB LUT
|
||||||
//#define IMLIB_ENABLE_LAB_LUT
|
//#define IMLIB_ENABLE_LAB_LUT
|
||||||
|
|
||||||
@ -131,9 +134,8 @@
|
|||||||
// Enable find_keypoints()
|
// Enable find_keypoints()
|
||||||
#define IMLIB_ENABLE_FIND_KEYPOINTS
|
#define IMLIB_ENABLE_FIND_KEYPOINTS
|
||||||
|
|
||||||
#if defined(IMLIB_ENABLE_FIND_LBP) || defined(IMLIB_ENABLE_FIND_KEYPOINTS)
|
// Enable load, save and match descriptor
|
||||||
#define IMLIB_ENABLE_DESCRIPTOR
|
#define IMLIB_ENABLE_DESCRIPTOR
|
||||||
#endif
|
|
||||||
|
|
||||||
// Enable find_hog()
|
// Enable find_hog()
|
||||||
#define IMLIB_ENABLE_HOG
|
#define IMLIB_ENABLE_HOG
|
||||||
|
|||||||
@ -6,10 +6,14 @@
|
|||||||
* File System Helper Functions
|
* File System Helper Functions
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
#include "imlib_config.h"
|
||||||
|
#if defined(IMLIB_ENABLE_IMAGE_IO)
|
||||||
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include "py/runtime.h"
|
#include "py/runtime.h"
|
||||||
#include "extmod/vfs.h"
|
#include "extmod/vfs.h"
|
||||||
#include "extmod/vfs_fat.h"
|
#include "extmod/vfs_fat.h"
|
||||||
|
|
||||||
#include "common.h"
|
#include "common.h"
|
||||||
#include "fb_alloc.h"
|
#include "fb_alloc.h"
|
||||||
#include "ff_wrapper.h"
|
#include "ff_wrapper.h"
|
||||||
@ -460,3 +464,4 @@ void write_data(FIL *fp, const void *data, UINT size)
|
|||||||
if (bytes != size) ff_write_fail(fp);
|
if (bytes != size) ff_write_fail(fp);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#endif //IMLIB_ENABLE_IMAGE_IO
|
||||||
|
|||||||
@ -8,12 +8,15 @@
|
|||||||
*
|
*
|
||||||
* BMP reader/writer.
|
* BMP reader/writer.
|
||||||
*/
|
*/
|
||||||
#include <arm_math.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <ff.h>
|
|
||||||
#include "ff_wrapper.h"
|
|
||||||
#include "xalloc.h"
|
|
||||||
#include "imlib.h"
|
#include "imlib.h"
|
||||||
|
#if defined(IMLIB_ENABLE_IMAGE_IO)
|
||||||
|
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include "py/obj.h"
|
||||||
|
#include "py/nlr.h"
|
||||||
|
|
||||||
|
#include "xalloc.h"
|
||||||
|
#include "ff_wrapper.h"
|
||||||
|
|
||||||
// This function inits the geometry values of an image (opens file).
|
// This function inits the geometry values of an image (opens file).
|
||||||
bool bmp_read_geometry(FIL *fp, image_t *img, const char *path, bmp_read_settings_t *rs)
|
bool bmp_read_geometry(FIL *fp, image_t *img, const char *path, bmp_read_settings_t *rs)
|
||||||
@ -216,10 +219,12 @@ void bmp_read(image_t *img, const char *path)
|
|||||||
void bmp_write_subimg(image_t *img, const char *path, rectangle_t *r)
|
void bmp_write_subimg(image_t *img, const char *path, rectangle_t *r)
|
||||||
{
|
{
|
||||||
rectangle_t rect;
|
rectangle_t rect;
|
||||||
if (!rectangle_subimg(img, r, &rect)) ff_no_intersection(NULL);
|
if (!rectangle_subimg(img, r, &rect)) {
|
||||||
|
nlr_raise(mp_obj_new_exception_msg(&mp_type_OSError, "No intersection!"));
|
||||||
|
}
|
||||||
|
|
||||||
FIL fp;
|
FIL fp;
|
||||||
file_write_open(&fp, path);
|
file_write_open(&fp, path);
|
||||||
|
|
||||||
file_buffer_on(&fp);
|
file_buffer_on(&fp);
|
||||||
if (IM_IS_GS(img)) {
|
if (IM_IS_GS(img)) {
|
||||||
const int row_bytes = (((rect.w * 8) + 31) / 32) * 4;
|
const int row_bytes = (((rect.w * 8) + 31) / 32) * 4;
|
||||||
@ -300,3 +305,4 @@ void bmp_write_subimg(image_t *img, const char *path, rectangle_t *r)
|
|||||||
|
|
||||||
file_close(&fp);
|
file_close(&fp);
|
||||||
}
|
}
|
||||||
|
#endif //IMLIB_ENABLE_IMAGE_IO
|
||||||
|
|||||||
@ -6,6 +6,8 @@
|
|||||||
* FFT LIB - can do 1024 point real FFTs and 512 point complex FFTs
|
* FFT LIB - can do 1024 point real FFTs and 512 point complex FFTs
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
#include "py/nlr.h"
|
||||||
|
#include "py/obj.h"
|
||||||
#include <arm_math.h>
|
#include <arm_math.h>
|
||||||
#include "fb_alloc.h"
|
#include "fb_alloc.h"
|
||||||
#include "ff_wrapper.h"
|
#include "ff_wrapper.h"
|
||||||
@ -548,7 +550,9 @@ void fft1d_run_again(fft1d_controller_t *controller)
|
|||||||
void fft2d_alloc(fft2d_controller_t *controller, image_t *img, rectangle_t *r)
|
void fft2d_alloc(fft2d_controller_t *controller, image_t *img, rectangle_t *r)
|
||||||
{
|
{
|
||||||
controller->img = img;
|
controller->img = img;
|
||||||
if (!rectangle_subimg(controller->img, r, &controller->r)) ff_no_intersection(NULL);
|
if (!rectangle_subimg(controller->img, r, &controller->r)) {
|
||||||
|
nlr_raise(mp_obj_new_exception_msg(&mp_type_OSError, "No intersection!"));
|
||||||
|
}
|
||||||
|
|
||||||
controller->w_pow2 = int_clog2(controller->r.w);
|
controller->w_pow2 = int_clog2(controller->r.w);
|
||||||
controller->h_pow2 = int_clog2(controller->r.h);
|
controller->h_pow2 = int_clog2(controller->r.h);
|
||||||
|
|||||||
@ -8,9 +8,11 @@
|
|||||||
*
|
*
|
||||||
* A simple GIF encoder.
|
* A simple GIF encoder.
|
||||||
*/
|
*/
|
||||||
|
#include "imlib.h"
|
||||||
|
#if defined(IMLIB_ENABLE_IMAGE_IO)
|
||||||
|
|
||||||
#include "fb_alloc.h"
|
#include "fb_alloc.h"
|
||||||
#include "ff_wrapper.h"
|
#include "ff_wrapper.h"
|
||||||
#include "imlib.h"
|
|
||||||
#define BLOCK_SIZE (126) // (2^7) - 2 // (DO NOT CHANGE!)
|
#define BLOCK_SIZE (126) // (2^7) - 2 // (DO NOT CHANGE!)
|
||||||
|
|
||||||
void gif_open(FIL *fp, int width, int height, bool color, bool loop)
|
void gif_open(FIL *fp, int width, int height, bool color, bool loop)
|
||||||
@ -115,3 +117,4 @@ void gif_close(FIL *fp)
|
|||||||
write_byte(fp, ';');
|
write_byte(fp, ';');
|
||||||
file_close(fp);
|
file_close(fp);
|
||||||
}
|
}
|
||||||
|
#endif //IMLIB_ENABLE_IMAGE_IO
|
||||||
|
|||||||
@ -10,7 +10,9 @@
|
|||||||
* Based on the work of Francesco Comaschi (f.comaschi@tue.nl)
|
* Based on the work of Francesco Comaschi (f.comaschi@tue.nl)
|
||||||
*/
|
*/
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <arm_math.h>
|
#include "py/obj.h"
|
||||||
|
#include "py/nlr.h"
|
||||||
|
|
||||||
#include "ff.h"
|
#include "ff.h"
|
||||||
#include "ff_wrapper.h"
|
#include "ff_wrapper.h"
|
||||||
#include "xalloc.h"
|
#include "xalloc.h"
|
||||||
@ -163,6 +165,7 @@ array_t *imlib_detect_objects(image_t *image, cascade_t *cascade, rectangle_t *r
|
|||||||
return objects;
|
return objects;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if defined(IMLIB_ENABLE_IMAGE_IO)
|
||||||
int imlib_load_cascade_from_file(cascade_t *cascade, const char *path)
|
int imlib_load_cascade_from_file(cascade_t *cascade, const char *path)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
@ -248,6 +251,7 @@ error:
|
|||||||
file_close(&fp);
|
file_close(&fp);
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
#endif //(IMLIB_ENABLE_IMAGE_IO)
|
||||||
|
|
||||||
int imlib_load_cascade(cascade_t *cascade, const char *path)
|
int imlib_load_cascade(cascade_t *cascade, const char *path)
|
||||||
{
|
{
|
||||||
@ -277,8 +281,12 @@ int imlib_load_cascade(cascade_t *cascade, const char *path)
|
|||||||
cascade->weights_array = (int8_t *)eye_weights_array;
|
cascade->weights_array = (int8_t *)eye_weights_array;
|
||||||
cascade->rectangles_array = (int8_t *)eye_rectangles_array;
|
cascade->rectangles_array = (int8_t *)eye_rectangles_array;
|
||||||
} else {
|
} else {
|
||||||
|
#if defined(IMLIB_ENABLE_IMAGE_IO)
|
||||||
// xml cascade
|
// xml cascade
|
||||||
return imlib_load_cascade_from_file(cascade, path);
|
return imlib_load_cascade_from_file(cascade, path);
|
||||||
|
#else
|
||||||
|
nlr_raise(mp_obj_new_exception_msg(&mp_type_OSError, "Image I/O is not supported"));
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
int i;
|
int i;
|
||||||
|
|||||||
@ -863,6 +863,7 @@ void imlib_bayer_to_binary(image_t *img, int x_offset, int y_offset, int width,
|
|||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
#if defined(IMLIB_ENABLE_IMAGE_IO)
|
||||||
static save_image_format_t imblib_parse_extension(image_t *img, const char *path)
|
static save_image_format_t imblib_parse_extension(image_t *img, const char *path)
|
||||||
{
|
{
|
||||||
size_t l = strlen(path);
|
size_t l = strlen(path);
|
||||||
@ -964,10 +965,12 @@ static void imlib_read_pixels(FIL *fp, image_t *img, int n_lines, img_read_setti
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#endif //IMLIB_ENABLE_IMAGE_IO
|
||||||
|
|
||||||
void imlib_image_operation(image_t *img, const char *path, image_t *other, int scalar, line_op_t op, void *data)
|
void imlib_image_operation(image_t *img, const char *path, image_t *other, int scalar, line_op_t op, void *data)
|
||||||
{
|
{
|
||||||
if (path) {
|
if (path) {
|
||||||
|
#if defined(IMLIB_ENABLE_IMAGE_IO)
|
||||||
uint32_t size = fb_avail() / 2;
|
uint32_t size = fb_avail() / 2;
|
||||||
void *alloc = fb_alloc(size, FB_ALLOC_NO_HINT); // We have to do this before the read.
|
void *alloc = fb_alloc(size, FB_ALLOC_NO_HINT); // We have to do this before the read.
|
||||||
// This code reads a window of an image in at a time and then executes
|
// This code reads a window of an image in at a time and then executes
|
||||||
@ -979,7 +982,8 @@ void imlib_image_operation(image_t *img, const char *path, image_t *other, int s
|
|||||||
img_read_settings_t rs;
|
img_read_settings_t rs;
|
||||||
bool vflipped = imlib_read_geometry(&fp, &temp, path, &rs);
|
bool vflipped = imlib_read_geometry(&fp, &temp, path, &rs);
|
||||||
if (!IM_EQUAL(img, &temp)) {
|
if (!IM_EQUAL(img, &temp)) {
|
||||||
ff_not_equal(&fp);
|
f_close(&fp);
|
||||||
|
nlr_raise(mp_obj_new_exception_msg(&mp_type_OSError, "Images not equal!"));
|
||||||
}
|
}
|
||||||
// When processing vertically flipped images the read function will fill
|
// When processing vertically flipped images the read function will fill
|
||||||
// the window up from the bottom. The read function assumes that the
|
// the window up from the bottom. The read function assumes that the
|
||||||
@ -1007,9 +1011,12 @@ void imlib_image_operation(image_t *img, const char *path, image_t *other, int s
|
|||||||
file_buffer_off(&fp);
|
file_buffer_off(&fp);
|
||||||
file_close(&fp);
|
file_close(&fp);
|
||||||
fb_free();
|
fb_free();
|
||||||
|
#else
|
||||||
|
nlr_raise(mp_obj_new_exception_msg(&mp_type_OSError, "Image I/O is not supported"));
|
||||||
|
#endif
|
||||||
} else if (other) {
|
} else if (other) {
|
||||||
if (!IM_EQUAL(img, other)) {
|
if (!IM_EQUAL(img, other)) {
|
||||||
ff_not_equal(NULL);
|
nlr_raise(mp_obj_new_exception_msg(&mp_type_OSError, "Images not equal!"));
|
||||||
}
|
}
|
||||||
switch (img->bpp) {
|
switch (img->bpp) {
|
||||||
case IMAGE_BPP_BINARY: {
|
case IMAGE_BPP_BINARY: {
|
||||||
@ -1085,6 +1092,7 @@ void imlib_image_operation(image_t *img, const char *path, image_t *other, int s
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if defined(IMLIB_ENABLE_IMAGE_IO)
|
||||||
void imlib_load_image(image_t *img, const char *path)
|
void imlib_load_image(image_t *img, const char *path)
|
||||||
{
|
{
|
||||||
FIL fp;
|
FIL fp;
|
||||||
@ -1147,6 +1155,7 @@ void imlib_save_image(image_t *img, const char *path, rectangle_t *roi, int qual
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#endif //IMLIB_ENABLE_IMAGE_IO
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
|||||||
@ -1290,6 +1290,7 @@ jpeg_overflow:
|
|||||||
}
|
}
|
||||||
#endif //defined OMV_HARDWARE_JPEG
|
#endif //defined OMV_HARDWARE_JPEG
|
||||||
|
|
||||||
|
#if defined(IMLIB_ENABLE_IMAGE_IO)
|
||||||
// This function inits the geometry values of an image.
|
// This function inits the geometry values of an image.
|
||||||
void jpeg_read_geometry(FIL *fp, image_t *img, const char *path, jpg_read_settings_t *rs)
|
void jpeg_read_geometry(FIL *fp, image_t *img, const char *path, jpg_read_settings_t *rs)
|
||||||
{
|
{
|
||||||
@ -1376,3 +1377,4 @@ void jpeg_write(image_t *img, const char *path, int quality)
|
|||||||
}
|
}
|
||||||
file_close(&fp);
|
file_close(&fp);
|
||||||
}
|
}
|
||||||
|
#endif //IMLIB_ENABLE_IMAGE_IO)
|
||||||
|
|||||||
@ -8,9 +8,11 @@
|
|||||||
*
|
*
|
||||||
* A simple MJPEG encoder.
|
* A simple MJPEG encoder.
|
||||||
*/
|
*/
|
||||||
|
#include "imlib.h"
|
||||||
|
#if defined(IMLIB_ENABLE_IMAGE_IO)
|
||||||
|
|
||||||
#include "fb_alloc.h"
|
#include "fb_alloc.h"
|
||||||
#include "ff_wrapper.h"
|
#include "ff_wrapper.h"
|
||||||
#include "imlib.h"
|
|
||||||
|
|
||||||
#define SIZE_OFFSET (1*4)
|
#define SIZE_OFFSET (1*4)
|
||||||
#define MICROS_OFFSET (8*4)
|
#define MICROS_OFFSET (8*4)
|
||||||
@ -149,3 +151,4 @@ void mjpeg_close(FIL *fp, uint32_t *frames, uint32_t *bytes, float fps)
|
|||||||
write_long(fp, 4 + (*frames * 8) + *bytes);
|
write_long(fp, 4 + (*frames * 8) + *bytes);
|
||||||
file_close(fp);
|
file_close(fp);
|
||||||
}
|
}
|
||||||
|
#endif //IMLIB_ENABLE_IMAGE_IO
|
||||||
|
|||||||
@ -704,6 +704,7 @@ int orb_filter_keypoints(array_t *kpts, rectangle_t *r, point_t *c)
|
|||||||
return matches;
|
return matches;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if defined(IMLIB_ENABLE_IMAGE_IO)
|
||||||
int orb_save_descriptor(FIL *fp, array_t *kpts)
|
int orb_save_descriptor(FIL *fp, array_t *kpts)
|
||||||
{
|
{
|
||||||
UINT bytes;
|
UINT bytes;
|
||||||
@ -823,6 +824,7 @@ int orb_load_descriptor(FIL *fp, array_t *kpts)
|
|||||||
error:
|
error:
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
#endif //IMLIB_ENABLE_IMAGE_IO
|
||||||
|
|
||||||
float orb_cluster_dist(int cx, int cy, void *kp_in)
|
float orb_cluster_dist(int cx, int cy, void *kp_in)
|
||||||
{
|
{
|
||||||
|
|||||||
@ -8,11 +8,17 @@
|
|||||||
*
|
*
|
||||||
* PPM/PGM reader/writer.
|
* PPM/PGM reader/writer.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include "imlib.h"
|
||||||
|
#if defined(IMLIB_ENABLE_IMAGE_IO)
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <ff.h>
|
#include "py/obj.h"
|
||||||
#include "ff_wrapper.h"
|
#include "py/nlr.h"
|
||||||
|
|
||||||
#include "xalloc.h"
|
#include "xalloc.h"
|
||||||
#include "imlib.h"
|
#include "imlib.h"
|
||||||
|
#include "ff_wrapper.h"
|
||||||
|
|
||||||
static void read_int_reset(ppm_read_settings_t *rs)
|
static void read_int_reset(ppm_read_settings_t *rs)
|
||||||
{
|
{
|
||||||
@ -120,10 +126,12 @@ void ppm_read(image_t *img, const char *path)
|
|||||||
void ppm_write_subimg(image_t *img, const char *path, rectangle_t *r)
|
void ppm_write_subimg(image_t *img, const char *path, rectangle_t *r)
|
||||||
{
|
{
|
||||||
rectangle_t rect;
|
rectangle_t rect;
|
||||||
if (!rectangle_subimg(img, r, &rect)) ff_no_intersection(NULL);
|
if (!rectangle_subimg(img, r, &rect)) {
|
||||||
|
nlr_raise(mp_obj_new_exception_msg(&mp_type_OSError, "No intersection!"));
|
||||||
|
}
|
||||||
|
|
||||||
FIL fp;
|
FIL fp;
|
||||||
file_write_open(&fp, path);
|
file_write_open(&fp, path);
|
||||||
|
|
||||||
file_buffer_on(&fp);
|
file_buffer_on(&fp);
|
||||||
if (IM_IS_GS(img)) {
|
if (IM_IS_GS(img)) {
|
||||||
char buffer[20]; // exactly big enough for 5-digit w/h
|
char buffer[20]; // exactly big enough for 5-digit w/h
|
||||||
@ -157,3 +165,4 @@ void ppm_write_subimg(image_t *img, const char *path, rectangle_t *r)
|
|||||||
|
|
||||||
file_close(&fp);
|
file_close(&fp);
|
||||||
}
|
}
|
||||||
|
#endif //IMLIB_ENABLE_IMAGE_IO
|
||||||
|
|||||||
@ -26,7 +26,9 @@ typedef struct py_gif_obj {
|
|||||||
int height;
|
int height;
|
||||||
bool color;
|
bool color;
|
||||||
bool loop;
|
bool loop;
|
||||||
|
#if defined(IMLIB_ENABLE_IMAGE_IO)
|
||||||
FIL fp;
|
FIL fp;
|
||||||
|
#endif
|
||||||
} py_gif_obj_t;
|
} py_gif_obj_t;
|
||||||
|
|
||||||
static mp_obj_t py_gif_open(uint n_args, const mp_obj_t *args, mp_map_t *kw_args)
|
static mp_obj_t py_gif_open(uint n_args, const mp_obj_t *args, mp_map_t *kw_args)
|
||||||
@ -38,8 +40,12 @@ static mp_obj_t py_gif_open(uint n_args, const mp_obj_t *args, mp_map_t *kw_args
|
|||||||
gif->loop = py_helper_keyword_int(n_args, args, 4, kw_args, MP_OBJ_NEW_QSTR(MP_QSTR_loop), true);
|
gif->loop = py_helper_keyword_int(n_args, args, 4, kw_args, MP_OBJ_NEW_QSTR(MP_QSTR_loop), true);
|
||||||
gif->base.type = &py_gif_type;
|
gif->base.type = &py_gif_type;
|
||||||
|
|
||||||
|
#if defined(IMLIB_ENABLE_IMAGE_IO)
|
||||||
file_write_open(&gif->fp, mp_obj_str_get_str(args[0]));
|
file_write_open(&gif->fp, mp_obj_str_get_str(args[0]));
|
||||||
gif_open(&gif->fp, gif->width, gif->height, gif->color, gif->loop);
|
gif_open(&gif->fp, gif->width, gif->height, gif->color, gif->loop);
|
||||||
|
#else
|
||||||
|
nlr_raise(mp_obj_new_exception_msg(&mp_type_OSError, "Image I/O is not supported"));
|
||||||
|
#endif
|
||||||
return gif;
|
return gif;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -63,8 +69,12 @@ static mp_obj_t py_gif_format(mp_obj_t gif_obj)
|
|||||||
|
|
||||||
static mp_obj_t py_gif_size(mp_obj_t gif_obj)
|
static mp_obj_t py_gif_size(mp_obj_t gif_obj)
|
||||||
{
|
{
|
||||||
|
#if defined(IMLIB_ENABLE_IMAGE_IO)
|
||||||
py_gif_obj_t *arg_gif = gif_obj;
|
py_gif_obj_t *arg_gif = gif_obj;
|
||||||
return mp_obj_new_int(file_size_w_buf(&arg_gif->fp));
|
return mp_obj_new_int(file_size_w_buf(&arg_gif->fp));
|
||||||
|
#else
|
||||||
|
return mp_obj_new_int(0);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
static mp_obj_t py_gif_loop(mp_obj_t gif_obj)
|
static mp_obj_t py_gif_loop(mp_obj_t gif_obj)
|
||||||
@ -75,6 +85,7 @@ static mp_obj_t py_gif_loop(mp_obj_t gif_obj)
|
|||||||
|
|
||||||
static mp_obj_t py_gif_add_frame(uint n_args, const mp_obj_t *args, mp_map_t *kw_args)
|
static mp_obj_t py_gif_add_frame(uint n_args, const mp_obj_t *args, mp_map_t *kw_args)
|
||||||
{
|
{
|
||||||
|
#if defined(IMLIB_ENABLE_IMAGE_IO)
|
||||||
py_gif_obj_t *arg_gif = args[0];
|
py_gif_obj_t *arg_gif = args[0];
|
||||||
image_t *arg_img = py_image_cobj(args[1]);
|
image_t *arg_img = py_image_cobj(args[1]);
|
||||||
PY_ASSERT_FALSE_MSG(IM_IS_JPEG(arg_img), "Operation not supported on JPEG images.");
|
PY_ASSERT_FALSE_MSG(IM_IS_JPEG(arg_img), "Operation not supported on JPEG images.");
|
||||||
@ -85,13 +96,18 @@ static mp_obj_t py_gif_add_frame(uint n_args, const mp_obj_t *args, mp_map_t *kw
|
|||||||
int delay = py_helper_keyword_int(n_args, args, 2, kw_args, MP_OBJ_NEW_QSTR(MP_QSTR_delay), 10);
|
int delay = py_helper_keyword_int(n_args, args, 2, kw_args, MP_OBJ_NEW_QSTR(MP_QSTR_delay), 10);
|
||||||
|
|
||||||
gif_add_frame(&arg_gif->fp, arg_img, delay);
|
gif_add_frame(&arg_gif->fp, arg_img, delay);
|
||||||
|
#else
|
||||||
|
nlr_raise(mp_obj_new_exception_msg(&mp_type_OSError, "Image I/O is not supported"));
|
||||||
|
#endif
|
||||||
return mp_const_none;
|
return mp_const_none;
|
||||||
}
|
}
|
||||||
|
|
||||||
static mp_obj_t py_gif_close(mp_obj_t gif_obj)
|
static mp_obj_t py_gif_close(mp_obj_t gif_obj)
|
||||||
{
|
{
|
||||||
|
#if defined(IMLIB_ENABLE_IMAGE_IO)
|
||||||
py_gif_obj_t *arg_gif = gif_obj;
|
py_gif_obj_t *arg_gif = gif_obj;
|
||||||
gif_close(&arg_gif->fp);
|
gif_close(&arg_gif->fp);
|
||||||
|
#endif
|
||||||
return mp_const_none;
|
return mp_const_none;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -247,7 +247,8 @@ static const mp_obj_type_t py_kptmatch_type = {
|
|||||||
.locals_dict = (mp_obj_t) &py_kptmatch_locals_dict
|
.locals_dict = (mp_obj_t) &py_kptmatch_locals_dict
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // IMLIB_ENABLE_FIND_KEYPOINTS
|
|
||||||
|
#endif //IMLIB_ENABLE_DESCRIPTOR && IMLIB_ENABLE_FIND_KEYPOINTS
|
||||||
|
|
||||||
// Image //////////////////////////////////////////////////////////////////////
|
// Image //////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
@ -1575,6 +1576,7 @@ static mp_obj_t py_image_crop(uint n_args, const mp_obj_t *args, mp_map_t *kw_ar
|
|||||||
}
|
}
|
||||||
STATIC MP_DEFINE_CONST_FUN_OBJ_KW(py_image_crop_obj, 1, py_image_crop);
|
STATIC MP_DEFINE_CONST_FUN_OBJ_KW(py_image_crop_obj, 1, py_image_crop);
|
||||||
|
|
||||||
|
#if defined(IMLIB_ENABLE_IMAGE_IO)
|
||||||
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]);
|
||||||
@ -1592,6 +1594,7 @@ static mp_obj_t py_image_save(uint n_args, const mp_obj_t *args, mp_map_t *kw_ar
|
|||||||
return args[0];
|
return args[0];
|
||||||
}
|
}
|
||||||
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);
|
||||||
|
#endif //IMLIB_ENABLE_IMAGE_IO
|
||||||
|
|
||||||
static mp_obj_t py_image_flush(mp_obj_t img_obj)
|
static mp_obj_t py_image_flush(mp_obj_t img_obj)
|
||||||
{
|
{
|
||||||
@ -6363,7 +6366,11 @@ static const mp_rom_map_elem_t locals_dict_table[] = {
|
|||||||
{MP_ROM_QSTR(MP_QSTR_copy), MP_ROM_PTR(&py_image_copy_obj)},
|
{MP_ROM_QSTR(MP_QSTR_copy), MP_ROM_PTR(&py_image_copy_obj)},
|
||||||
{MP_ROM_QSTR(MP_QSTR_crop), MP_ROM_PTR(&py_image_crop_obj)},
|
{MP_ROM_QSTR(MP_QSTR_crop), MP_ROM_PTR(&py_image_crop_obj)},
|
||||||
{MP_ROM_QSTR(MP_QSTR_scale), MP_ROM_PTR(&py_image_crop_obj)},
|
{MP_ROM_QSTR(MP_QSTR_scale), MP_ROM_PTR(&py_image_crop_obj)},
|
||||||
|
#if defined(IMLIB_ENABLE_IMAGE_IO)
|
||||||
{MP_ROM_QSTR(MP_QSTR_save), MP_ROM_PTR(&py_image_save_obj)},
|
{MP_ROM_QSTR(MP_QSTR_save), MP_ROM_PTR(&py_image_save_obj)},
|
||||||
|
#else
|
||||||
|
{MP_ROM_QSTR(MP_QSTR_save), MP_ROM_PTR(&py_func_unavailable_obj)},
|
||||||
|
#endif
|
||||||
{MP_ROM_QSTR(MP_QSTR_flush), MP_ROM_PTR(&py_image_flush_obj)},
|
{MP_ROM_QSTR(MP_QSTR_flush), MP_ROM_PTR(&py_image_flush_obj)},
|
||||||
/* Drawing Methods */
|
/* Drawing Methods */
|
||||||
{MP_ROM_QSTR(MP_QSTR_clear), MP_ROM_PTR(&py_image_clear_obj)},
|
{MP_ROM_QSTR(MP_QSTR_clear), MP_ROM_PTR(&py_image_clear_obj)},
|
||||||
@ -6640,6 +6647,7 @@ static const mp_obj_type_t py_image_type = {
|
|||||||
.locals_dict = (mp_obj_t) &locals_dict
|
.locals_dict = (mp_obj_t) &locals_dict
|
||||||
};
|
};
|
||||||
|
|
||||||
|
#if defined(IMLIB_ENABLE_IMAGE_IO)
|
||||||
// ImageWriter Object //
|
// ImageWriter Object //
|
||||||
typedef struct py_imagewriter_obj {
|
typedef struct py_imagewriter_obj {
|
||||||
mp_obj_base_t base;
|
mp_obj_base_t base;
|
||||||
@ -6859,6 +6867,7 @@ mp_obj_t py_image_imagereader(mp_obj_t path)
|
|||||||
return obj;
|
return obj;
|
||||||
}
|
}
|
||||||
STATIC MP_DEFINE_CONST_FUN_OBJ_1(py_image_imagereader_obj, py_image_imagereader);
|
STATIC MP_DEFINE_CONST_FUN_OBJ_1(py_image_imagereader_obj, py_image_imagereader);
|
||||||
|
#endif //IMLIB_ENABLE_IMAGE_IO
|
||||||
|
|
||||||
mp_obj_t py_image_binary_to_grayscale(mp_obj_t arg)
|
mp_obj_t py_image_binary_to_grayscale(mp_obj_t arg)
|
||||||
{
|
{
|
||||||
@ -7128,8 +7137,8 @@ mp_obj_t py_image_load_image(uint n_args, const mp_obj_t *args, mp_map_t *kw_arg
|
|||||||
bool mode = mp_obj_is_integer(args[0]);
|
bool mode = mp_obj_is_integer(args[0]);
|
||||||
const char *path = mode ? NULL : mp_obj_str_get_str(args[0]);
|
const char *path = mode ? NULL : mp_obj_str_get_str(args[0]);
|
||||||
|
|
||||||
mp_obj_t copy_to_fb_obj = py_helper_keyword_object(n_args, args, mode ? 3 : 1,
|
mp_obj_t copy_to_fb_obj = py_helper_keyword_object(n_args, args,
|
||||||
kw_args, MP_OBJ_NEW_QSTR(MP_QSTR_copy_to_fb), NULL);
|
mode ? 3 : 1, kw_args, MP_OBJ_NEW_QSTR(MP_QSTR_copy_to_fb), NULL);
|
||||||
bool copy_to_fb = false;
|
bool copy_to_fb = false;
|
||||||
image_t *arg_other = NULL;
|
image_t *arg_other = NULL;
|
||||||
|
|
||||||
@ -7167,12 +7176,17 @@ mp_obj_t py_image_load_image(uint n_args, const mp_obj_t *args, mp_map_t *kw_arg
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
#if defined(IMLIB_ENABLE_IMAGE_IO)
|
||||||
fb_alloc_mark();
|
fb_alloc_mark();
|
||||||
FIL fp;
|
FIL fp;
|
||||||
img_read_settings_t rs;
|
img_read_settings_t rs;
|
||||||
imlib_read_geometry(&fp, &image, path, &rs);
|
imlib_read_geometry(&fp, &image, path, &rs);
|
||||||
file_buffer_off(&fp);
|
file_buffer_off(&fp);
|
||||||
file_close(&fp);
|
file_close(&fp);
|
||||||
|
#else
|
||||||
|
(void) path;
|
||||||
|
nlr_raise(mp_obj_new_exception_msg(&mp_type_OSError, "Image I/O is not supported"));
|
||||||
|
#endif //IMLIB_ENABLE_IMAGE_IO
|
||||||
}
|
}
|
||||||
|
|
||||||
if (copy_to_fb) {
|
if (copy_to_fb) {
|
||||||
@ -7187,8 +7201,10 @@ mp_obj_t py_image_load_image(uint n_args, const mp_obj_t *args, mp_map_t *kw_arg
|
|||||||
if (mode) {
|
if (mode) {
|
||||||
memset(image.data, 0, image_size(&image));
|
memset(image.data, 0, image_size(&image));
|
||||||
} else {
|
} else {
|
||||||
|
#if defined(IMLIB_ENABLE_IMAGE_IO)
|
||||||
imlib_load_image(&image, path);
|
imlib_load_image(&image, path);
|
||||||
fb_alloc_free_till_mark();
|
fb_alloc_free_till_mark();
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
py_helper_update_framebuffer(&image);
|
py_helper_update_framebuffer(&image);
|
||||||
@ -7233,7 +7249,8 @@ mp_obj_t py_image_load_cascade(uint n_args, const mp_obj_t *args, mp_map_t *kw_a
|
|||||||
}
|
}
|
||||||
STATIC MP_DEFINE_CONST_FUN_OBJ_KW(py_image_load_cascade_obj, 1, py_image_load_cascade);
|
STATIC MP_DEFINE_CONST_FUN_OBJ_KW(py_image_load_cascade_obj, 1, py_image_load_cascade);
|
||||||
|
|
||||||
#ifdef IMLIB_ENABLE_DESCRIPTOR
|
#if defined(IMLIB_ENABLE_DESCRIPTOR)
|
||||||
|
#if defined(IMLIB_ENABLE_IMAGE_IO)
|
||||||
mp_obj_t py_image_load_descriptor(uint n_args, const mp_obj_t *args, mp_map_t *kw_args)
|
mp_obj_t py_image_load_descriptor(uint n_args, const mp_obj_t *args, mp_map_t *kw_args)
|
||||||
{
|
{
|
||||||
FIL fp;
|
FIL fp;
|
||||||
@ -7363,6 +7380,7 @@ error:
|
|||||||
return mp_const_true;
|
return mp_const_true;
|
||||||
}
|
}
|
||||||
STATIC MP_DEFINE_CONST_FUN_OBJ_KW(py_image_save_descriptor_obj, 2, py_image_save_descriptor);
|
STATIC MP_DEFINE_CONST_FUN_OBJ_KW(py_image_save_descriptor_obj, 2, py_image_save_descriptor);
|
||||||
|
#endif //IMLIB_ENABLE_IMAGE_IO
|
||||||
|
|
||||||
static mp_obj_t py_image_match_descriptor(uint n_args, const mp_obj_t *args, mp_map_t *kw_args)
|
static mp_obj_t py_image_match_descriptor(uint n_args, const mp_obj_t *args, mp_map_t *kw_args)
|
||||||
{
|
{
|
||||||
@ -7449,7 +7467,7 @@ static mp_obj_t py_image_match_descriptor(uint n_args, const mp_obj_t *args, mp_
|
|||||||
STATIC MP_DEFINE_CONST_FUN_OBJ_KW(py_image_match_descriptor_obj, 2, py_image_match_descriptor);
|
STATIC MP_DEFINE_CONST_FUN_OBJ_KW(py_image_match_descriptor_obj, 2, py_image_match_descriptor);
|
||||||
#endif //IMLIB_ENABLE_DESCRIPTOR
|
#endif //IMLIB_ENABLE_DESCRIPTOR
|
||||||
|
|
||||||
#if defined(IMLIB_ENABLE_FIND_KEYPOINTS)
|
#if defined(IMLIB_ENABLE_FIND_KEYPOINTS) && defined(IMLIB_ENABLE_IMAGE_IO)
|
||||||
int py_image_descriptor_from_roi(image_t *img, const char *path, rectangle_t *roi)
|
int py_image_descriptor_from_roi(image_t *img, const char *path, rectangle_t *roi)
|
||||||
{
|
{
|
||||||
FIL fp;
|
FIL fp;
|
||||||
@ -7471,7 +7489,7 @@ int py_image_descriptor_from_roi(image_t *img, const char *path, rectangle_t *ro
|
|||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
#endif // IMLIB_ENABLE_KEYPOINTS
|
#endif // IMLIB_ENABLE_KEYPOINTS && IMLIB_ENABLE_IMAGE_IO
|
||||||
|
|
||||||
static const mp_rom_map_elem_t globals_dict_table[] = {
|
static const mp_rom_map_elem_t globals_dict_table[] = {
|
||||||
{MP_ROM_QSTR(MP_QSTR___name__), MP_OBJ_NEW_QSTR(MP_QSTR_image)},
|
{MP_ROM_QSTR(MP_QSTR___name__), MP_OBJ_NEW_QSTR(MP_QSTR_image)},
|
||||||
@ -7522,8 +7540,13 @@ static const mp_rom_map_elem_t globals_dict_table[] = {
|
|||||||
{MP_ROM_QSTR(MP_QSTR_CODE93), MP_ROM_INT(BARCODE_CODE93)},
|
{MP_ROM_QSTR(MP_QSTR_CODE93), MP_ROM_INT(BARCODE_CODE93)},
|
||||||
{MP_ROM_QSTR(MP_QSTR_CODE128), MP_ROM_INT(BARCODE_CODE128)},
|
{MP_ROM_QSTR(MP_QSTR_CODE128), MP_ROM_INT(BARCODE_CODE128)},
|
||||||
#endif
|
#endif
|
||||||
|
#if defined(IMLIB_ENABLE_IMAGE_IO)
|
||||||
{MP_ROM_QSTR(MP_QSTR_ImageWriter), MP_ROM_PTR(&py_image_imagewriter_obj)},
|
{MP_ROM_QSTR(MP_QSTR_ImageWriter), MP_ROM_PTR(&py_image_imagewriter_obj)},
|
||||||
{MP_ROM_QSTR(MP_QSTR_ImageReader), MP_ROM_PTR(&py_image_imagereader_obj)},
|
{MP_ROM_QSTR(MP_QSTR_ImageReader), MP_ROM_PTR(&py_image_imagereader_obj)},
|
||||||
|
#else
|
||||||
|
{MP_ROM_QSTR(MP_QSTR_ImageWriter), MP_ROM_PTR(&py_func_unavailable_obj)},
|
||||||
|
{MP_ROM_QSTR(MP_QSTR_ImageReader), MP_ROM_PTR(&py_func_unavailable_obj)},
|
||||||
|
#endif
|
||||||
{MP_ROM_QSTR(MP_QSTR_binary_to_grayscale), MP_ROM_PTR(&py_image_binary_to_grayscale_obj)},
|
{MP_ROM_QSTR(MP_QSTR_binary_to_grayscale), MP_ROM_PTR(&py_image_binary_to_grayscale_obj)},
|
||||||
{MP_ROM_QSTR(MP_QSTR_binary_to_rgb), MP_ROM_PTR(&py_image_binary_to_rgb_obj)},
|
{MP_ROM_QSTR(MP_QSTR_binary_to_rgb), MP_ROM_PTR(&py_image_binary_to_rgb_obj)},
|
||||||
{MP_ROM_QSTR(MP_QSTR_binary_to_lab), MP_ROM_PTR(&py_image_binary_to_lab_obj)},
|
{MP_ROM_QSTR(MP_QSTR_binary_to_lab), MP_ROM_PTR(&py_image_binary_to_lab_obj)},
|
||||||
@ -7546,13 +7569,16 @@ static const mp_rom_map_elem_t globals_dict_table[] = {
|
|||||||
{MP_ROM_QSTR(MP_QSTR_yuv_to_lab), MP_ROM_PTR(&py_image_yuv_to_lab_obj)},
|
{MP_ROM_QSTR(MP_QSTR_yuv_to_lab), MP_ROM_PTR(&py_image_yuv_to_lab_obj)},
|
||||||
{MP_ROM_QSTR(MP_QSTR_Image), MP_ROM_PTR(&py_image_load_image_obj)},
|
{MP_ROM_QSTR(MP_QSTR_Image), MP_ROM_PTR(&py_image_load_image_obj)},
|
||||||
{MP_ROM_QSTR(MP_QSTR_HaarCascade), MP_ROM_PTR(&py_image_load_cascade_obj)},
|
{MP_ROM_QSTR(MP_QSTR_HaarCascade), MP_ROM_PTR(&py_image_load_cascade_obj)},
|
||||||
#ifdef IMLIB_ENABLE_DESCRIPTOR
|
#if defined(IMLIB_ENABLE_DESCRIPTOR) && defined(IMLIB_ENABLE_IMAGE_IO)
|
||||||
{MP_ROM_QSTR(MP_QSTR_load_descriptor), MP_ROM_PTR(&py_image_load_descriptor_obj)},
|
{MP_ROM_QSTR(MP_QSTR_load_descriptor), MP_ROM_PTR(&py_image_load_descriptor_obj)},
|
||||||
{MP_ROM_QSTR(MP_QSTR_save_descriptor), MP_ROM_PTR(&py_image_save_descriptor_obj)},
|
{MP_ROM_QSTR(MP_QSTR_save_descriptor), MP_ROM_PTR(&py_image_save_descriptor_obj)},
|
||||||
{MP_ROM_QSTR(MP_QSTR_match_descriptor), MP_ROM_PTR(&py_image_match_descriptor_obj)}
|
|
||||||
#else
|
#else
|
||||||
{MP_ROM_QSTR(MP_QSTR_load_descriptor), MP_ROM_PTR(&py_func_unavailable_obj)},
|
{MP_ROM_QSTR(MP_QSTR_load_descriptor), MP_ROM_PTR(&py_func_unavailable_obj)},
|
||||||
{MP_ROM_QSTR(MP_QSTR_save_descriptor), MP_ROM_PTR(&py_func_unavailable_obj)},
|
{MP_ROM_QSTR(MP_QSTR_save_descriptor), MP_ROM_PTR(&py_func_unavailable_obj)},
|
||||||
|
#endif //IMLIB_ENABLE_DESCRIPTOR && IMLIB_ENABLE_IMAGE_IO
|
||||||
|
#if defined(IMLIB_ENABLE_DESCRIPTOR)
|
||||||
|
{MP_ROM_QSTR(MP_QSTR_match_descriptor), MP_ROM_PTR(&py_image_match_descriptor_obj)}
|
||||||
|
#else
|
||||||
{MP_ROM_QSTR(MP_QSTR_match_descriptor), MP_ROM_PTR(&py_func_unavailable_obj)}
|
{MP_ROM_QSTR(MP_QSTR_match_descriptor), MP_ROM_PTR(&py_func_unavailable_obj)}
|
||||||
#endif
|
#endif
|
||||||
};
|
};
|
||||||
|
|||||||
@ -24,7 +24,9 @@ typedef struct py_mjpeg_obj {
|
|||||||
int height;
|
int height;
|
||||||
uint32_t frames;
|
uint32_t frames;
|
||||||
uint32_t bytes;
|
uint32_t bytes;
|
||||||
|
#if defined(IMLIB_ENABLE_IMAGE_IO)
|
||||||
FIL fp;
|
FIL fp;
|
||||||
|
#endif
|
||||||
} py_mjpeg_obj_t;
|
} py_mjpeg_obj_t;
|
||||||
|
|
||||||
static mp_obj_t py_mjpeg_open(uint n_args, const mp_obj_t *args, mp_map_t *kw_args)
|
static mp_obj_t py_mjpeg_open(uint n_args, const mp_obj_t *args, mp_map_t *kw_args)
|
||||||
@ -36,8 +38,12 @@ static mp_obj_t py_mjpeg_open(uint n_args, const mp_obj_t *args, mp_map_t *kw_ar
|
|||||||
mjpeg->bytes = 0; // private
|
mjpeg->bytes = 0; // private
|
||||||
mjpeg->base.type = &py_mjpeg_type;
|
mjpeg->base.type = &py_mjpeg_type;
|
||||||
|
|
||||||
|
#if defined(IMLIB_ENABLE_IMAGE_IO)
|
||||||
file_write_open(&mjpeg->fp, mp_obj_str_get_str(args[0]));
|
file_write_open(&mjpeg->fp, mp_obj_str_get_str(args[0]));
|
||||||
mjpeg_open(&mjpeg->fp, mjpeg->width, mjpeg->height);
|
mjpeg_open(&mjpeg->fp, mjpeg->width, mjpeg->height);
|
||||||
|
#else
|
||||||
|
nlr_raise(mp_obj_new_exception_msg(&mp_type_OSError, "Image I/O is not supported"));
|
||||||
|
#endif
|
||||||
return mjpeg;
|
return mjpeg;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -55,12 +61,17 @@ static mp_obj_t py_mjpeg_height(mp_obj_t mjpeg_obj)
|
|||||||
|
|
||||||
static mp_obj_t py_mjpeg_size(mp_obj_t mjpeg_obj)
|
static mp_obj_t py_mjpeg_size(mp_obj_t mjpeg_obj)
|
||||||
{
|
{
|
||||||
|
#if defined(IMLIB_ENABLE_IMAGE_IO)
|
||||||
py_mjpeg_obj_t *arg_mjpeg = mjpeg_obj;
|
py_mjpeg_obj_t *arg_mjpeg = mjpeg_obj;
|
||||||
return mp_obj_new_int(f_size(&arg_mjpeg->fp));
|
return mp_obj_new_int(f_size(&arg_mjpeg->fp));
|
||||||
|
#else
|
||||||
|
return mp_obj_new_int(0);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
static mp_obj_t py_mjpeg_add_frame(uint n_args, const mp_obj_t *args, mp_map_t *kw_args)
|
static mp_obj_t py_mjpeg_add_frame(uint n_args, const mp_obj_t *args, mp_map_t *kw_args)
|
||||||
{
|
{
|
||||||
|
#if defined(IMLIB_ENABLE_IMAGE_IO)
|
||||||
py_mjpeg_obj_t *arg_mjpeg = args[0];
|
py_mjpeg_obj_t *arg_mjpeg = args[0];
|
||||||
image_t *arg_img = py_image_cobj(args[1]);
|
image_t *arg_img = py_image_cobj(args[1]);
|
||||||
PY_ASSERT_FALSE_MSG((arg_mjpeg->width != arg_img->w)
|
PY_ASSERT_FALSE_MSG((arg_mjpeg->width != arg_img->w)
|
||||||
@ -70,13 +81,18 @@ static mp_obj_t py_mjpeg_add_frame(uint n_args, const mp_obj_t *args, mp_map_t *
|
|||||||
int arg_q = py_helper_keyword_int(n_args, args, 2, kw_args, MP_OBJ_NEW_QSTR(MP_QSTR_quality), 50);
|
int arg_q = py_helper_keyword_int(n_args, args, 2, kw_args, MP_OBJ_NEW_QSTR(MP_QSTR_quality), 50);
|
||||||
arg_q = IM_MIN(IM_MAX(arg_q, 1), 100);
|
arg_q = IM_MIN(IM_MAX(arg_q, 1), 100);
|
||||||
mjpeg_add_frame(&arg_mjpeg->fp, &arg_mjpeg->frames, &arg_mjpeg->bytes, arg_img, arg_q);
|
mjpeg_add_frame(&arg_mjpeg->fp, &arg_mjpeg->frames, &arg_mjpeg->bytes, arg_img, arg_q);
|
||||||
|
#else
|
||||||
|
nlr_raise(mp_obj_new_exception_msg(&mp_type_OSError, "Image I/O is not supported"));
|
||||||
|
#endif
|
||||||
return mp_const_none;
|
return mp_const_none;
|
||||||
}
|
}
|
||||||
|
|
||||||
static mp_obj_t py_mjpeg_close(mp_obj_t mjpeg_obj, mp_obj_t fps_obj)
|
static mp_obj_t py_mjpeg_close(mp_obj_t mjpeg_obj, mp_obj_t fps_obj)
|
||||||
{
|
{
|
||||||
|
#if defined(IMLIB_ENABLE_IMAGE_IO)
|
||||||
py_mjpeg_obj_t *arg_mjpeg = mjpeg_obj;
|
py_mjpeg_obj_t *arg_mjpeg = mjpeg_obj;
|
||||||
mjpeg_close(&arg_mjpeg->fp, &arg_mjpeg->frames, &arg_mjpeg->bytes, mp_obj_get_float(fps_obj));
|
mjpeg_close(&arg_mjpeg->fp, &arg_mjpeg->frames, &arg_mjpeg->bytes, mp_obj_get_float(fps_obj));
|
||||||
|
#endif
|
||||||
return mp_const_none;
|
return mp_const_none;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -140,6 +140,7 @@ STATIC mp_obj_t int_py_tf_load(mp_obj_t path_obj, bool alloc_mode, bool helper_m
|
|||||||
tf_model->model_data = (unsigned char *) g_person_detect_model_data;
|
tf_model->model_data = (unsigned char *) g_person_detect_model_data;
|
||||||
tf_model->model_data_len = g_person_detect_model_data_len;
|
tf_model->model_data_len = g_person_detect_model_data_len;
|
||||||
} else {
|
} else {
|
||||||
|
#if defined(IMLIB_ENABLE_IMAGE_IO)
|
||||||
FIL fp;
|
FIL fp;
|
||||||
file_read_open(&fp, path);
|
file_read_open(&fp, path);
|
||||||
tf_model->model_data_len = f_size(&fp);
|
tf_model->model_data_len = f_size(&fp);
|
||||||
@ -148,6 +149,9 @@ STATIC mp_obj_t int_py_tf_load(mp_obj_t path_obj, bool alloc_mode, bool helper_m
|
|||||||
: xalloc(tf_model->model_data_len);
|
: xalloc(tf_model->model_data_len);
|
||||||
read_data(&fp, tf_model->model_data, tf_model->model_data_len);
|
read_data(&fp, tf_model->model_data, tf_model->model_data_len);
|
||||||
file_close(&fp);
|
file_close(&fp);
|
||||||
|
#else
|
||||||
|
nlr_raise(mp_obj_new_exception_msg(&mp_type_OSError, "Image I/O is not supported"));
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!helper_mode) {
|
if (!helper_mode) {
|
||||||
|
|||||||
@ -500,7 +500,9 @@ soft_reset:
|
|||||||
uart_init0();
|
uart_init0();
|
||||||
sensor_init0();
|
sensor_init0();
|
||||||
fb_alloc_init0();
|
fb_alloc_init0();
|
||||||
|
#ifdef IMLIB_ENABLE_IMAGE_IO
|
||||||
file_buffer_init0();
|
file_buffer_init0();
|
||||||
|
#endif
|
||||||
py_lcd_init0();
|
py_lcd_init0();
|
||||||
py_fir_init0();
|
py_fir_init0();
|
||||||
py_tv_init0();
|
py_tv_init0();
|
||||||
|
|||||||
@ -210,6 +210,7 @@ void usbdbg_data_out(void *buffer, int length)
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case USBDBG_TEMPLATE_SAVE: {
|
case USBDBG_TEMPLATE_SAVE: {
|
||||||
|
#if defined(IMLIB_ENABLE_IMAGE_IO)
|
||||||
image_t image;
|
image_t image;
|
||||||
framebuffer_initialize_image(&image);
|
framebuffer_initialize_image(&image);
|
||||||
|
|
||||||
@ -221,13 +222,16 @@ void usbdbg_data_out(void *buffer, int length)
|
|||||||
char *path = (char*)buffer+sizeof(rectangle_t);
|
char *path = (char*)buffer+sizeof(rectangle_t);
|
||||||
|
|
||||||
imlib_save_image(&image, path, roi, 50);
|
imlib_save_image(&image, path, roi, 50);
|
||||||
|
|
||||||
// raise a flash IRQ to flush image
|
// raise a flash IRQ to flush image
|
||||||
//NVIC->STIR = FLASH_IRQn;
|
//NVIC->STIR = FLASH_IRQn;
|
||||||
|
#endif //IMLIB_ENABLE_IMAGE_IO
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
case USBDBG_DESCRIPTOR_SAVE: {
|
case USBDBG_DESCRIPTOR_SAVE: {
|
||||||
#ifdef IMLIB_ENABLE_KEYPOINTS
|
#if defined(IMLIB_ENABLE_IMAGE_IO)\
|
||||||
|
&& defined(IMLIB_ENABLE_KEYPOINTS)
|
||||||
image_t image;
|
image_t image;
|
||||||
framebuffer_initialize_image(&image);
|
framebuffer_initialize_image(&image);
|
||||||
|
|
||||||
@ -239,7 +243,7 @@ void usbdbg_data_out(void *buffer, int length)
|
|||||||
char *path = (char*)buffer+sizeof(rectangle_t);
|
char *path = (char*)buffer+sizeof(rectangle_t);
|
||||||
|
|
||||||
py_image_descriptor_from_roi(&image, path, roi);
|
py_image_descriptor_from_roi(&image, path, roi);
|
||||||
#endif
|
#endif //IMLIB_ENABLE_IMAGE_IO && IMLIB_ENABLE_KEYPOINTS
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user