mirror of
https://github.com/openmv/openmv.git
synced 2025-11-04 14:49:50 +08:00
Compare commits
15 Commits
12eb7da2f5
...
e13fc4e4a7
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e13fc4e4a7 | ||
|
|
0dc58f43fa | ||
|
|
476e8d815a | ||
|
|
2edfd62154 | ||
|
|
2783fec7c2 | ||
|
|
0b21fe3a86 | ||
|
|
3eaf280ee2 | ||
|
|
7e59c080df | ||
|
|
6bf3063a71 | ||
|
|
59bfecb2d7 | ||
|
|
bab3d6bba0 | ||
|
|
fff818fa44 | ||
|
|
74f1d07b94 | ||
|
|
f6d183e5c0 | ||
|
|
a3931e04b6 |
2
.github/workflows/code-size-report.yml
vendored
2
.github/workflows/code-size-report.yml
vendored
@ -15,7 +15,7 @@ jobs:
|
||||
runs-on: ubuntu-24.04
|
||||
steps:
|
||||
- name: '↓ Download code size report'
|
||||
uses: actions/download-artifact@v5
|
||||
uses: actions/download-artifact@v6
|
||||
with:
|
||||
name: code-size-report
|
||||
run-id: ${{ github.event.workflow_run.id }}
|
||||
|
||||
10
.github/workflows/firmware.yml
vendored
10
.github/workflows/firmware.yml
vendored
@ -129,7 +129,7 @@ jobs:
|
||||
|
||||
- name: '⬆ Upload artifacts'
|
||||
if: matrix.artifacts
|
||||
uses: actions/upload-artifact@v4
|
||||
uses: actions/upload-artifact@v5
|
||||
with:
|
||||
name: ${{ matrix.target }}
|
||||
path: ${{ matrix.target }}
|
||||
@ -167,7 +167,7 @@ jobs:
|
||||
pip install tabulate==0.9.0
|
||||
|
||||
- name: '↓ Download artifacts'
|
||||
uses: actions/download-artifact@v5
|
||||
uses: actions/download-artifact@v6
|
||||
with:
|
||||
path: new_firmware
|
||||
merge-multiple: false
|
||||
@ -188,7 +188,7 @@ jobs:
|
||||
python tools/code_size.py > ${GITHUB_WORKSPACE}/${{ github.event.pull_request.number }}.md
|
||||
|
||||
- name: '⬆ Upload report'
|
||||
uses: actions/upload-artifact@v4
|
||||
uses: actions/upload-artifact@v5
|
||||
with:
|
||||
overwrite: true
|
||||
name: code-size-report
|
||||
@ -206,7 +206,7 @@ jobs:
|
||||
submodules: false
|
||||
|
||||
- name: '↓ Download artifacts'
|
||||
uses: actions/download-artifact@v5
|
||||
uses: actions/download-artifact@v6
|
||||
with:
|
||||
path: firmware
|
||||
|
||||
@ -250,7 +250,7 @@ jobs:
|
||||
submodules: false
|
||||
|
||||
- name: '↓ Download artifacts'
|
||||
uses: actions/download-artifact@v5
|
||||
uses: actions/download-artifact@v6
|
||||
with:
|
||||
path: firmware
|
||||
|
||||
|
||||
@ -32,12 +32,24 @@
|
||||
"alignment": 16,
|
||||
"optimize": "Performance"
|
||||
},
|
||||
{
|
||||
"type": "tflite",
|
||||
"path": "{TOP}/lib/models/yolov8n_192.tflite",
|
||||
"alignment": 16,
|
||||
"optimize": "Performance"
|
||||
},
|
||||
{
|
||||
"type": "tflite",
|
||||
"path": "{TOP}/lib/models/blazeface_front_128.tflite",
|
||||
"alignment": 16,
|
||||
"optimize": "Performance"
|
||||
},
|
||||
{
|
||||
"type": "tflite",
|
||||
"path": "{TOP}/lib/models/face_landmarks_192.tflite",
|
||||
"alignment": 16,
|
||||
"optimize": "Performance"
|
||||
},
|
||||
{
|
||||
"type": "tflite",
|
||||
"path": "{TOP}/lib/models/palm_detection_full_192.tflite",
|
||||
|
||||
@ -14,12 +14,24 @@
|
||||
"alignment": 32,
|
||||
"profile": "default"
|
||||
},
|
||||
{
|
||||
"type": "tflite",
|
||||
"path": "{TOP}/lib/models/yolov8n_192.tflite",
|
||||
"alignment": 32,
|
||||
"profile": "default"
|
||||
},
|
||||
{
|
||||
"type": "tflite",
|
||||
"path": "{TOP}/lib/models/blazeface_front_128.tflite",
|
||||
"alignment": 32,
|
||||
"profile": "default"
|
||||
},
|
||||
{
|
||||
"type": "tflite",
|
||||
"path": "{TOP}/lib/models/face_landmarks_192.tflite",
|
||||
"alignment": 32,
|
||||
"profile": "default"
|
||||
},
|
||||
{
|
||||
"type": "tflite",
|
||||
"path": "{TOP}/lib/models/palm_detection_full_192.tflite",
|
||||
|
||||
@ -79,7 +79,7 @@ void imlib_edge_canny(image_t *src, rectangle_t *roi, int low_thresh, int high_t
|
||||
// Find magnitude
|
||||
int g = (int) fast_sqrtf(vx * vx + vy * vy);
|
||||
// Find the direction and round angle to 0, 45, 90 or 135
|
||||
int t = (int) fast_fabsf((atan2f(vy, vx) * 180.0f / M_PI));
|
||||
int t = (int) fast_fabsf((atan2f(vy, vx) * 180.0f / IMLIB_PI));
|
||||
if (t < 22) {
|
||||
t = 0;
|
||||
} else if (t < 67) {
|
||||
|
||||
@ -497,7 +497,7 @@ void fft1d_phase(fft1d_controller_t *controller) {
|
||||
for (int i = 0, j = 2 << controller->pow2; i < j; i += 2) {
|
||||
float tmp_r = controller->data[i + 0];
|
||||
float tmp_i = controller->data[i + 1];
|
||||
controller->data[i + 0] = tmp_r ? fast_atan2f(tmp_i, tmp_r) : ((tmp_i < 0) ? (M_PI * 1.5) : (M_PI * 0.5));
|
||||
controller->data[i + 0] = tmp_r ? fast_atan2f(tmp_i, tmp_r) : ((tmp_i < 0) ? (IMLIB_PI * 1.5f) : (IMLIB_PI * 0.5f));
|
||||
controller->data[i + 1] = 0;
|
||||
}
|
||||
}
|
||||
@ -507,7 +507,7 @@ void fft1d_log(fft1d_controller_t *controller) {
|
||||
float tmp_r = controller->data[i + 0];
|
||||
float tmp_i = controller->data[i + 1];
|
||||
controller->data[i + 0] = fast_log(fast_sqrtf((tmp_r * tmp_r) + (tmp_i * tmp_i)));
|
||||
controller->data[i + 1] = tmp_r ? fast_atan2f(tmp_i, tmp_r) : ((tmp_i < 0) ? (M_PI * 1.5) : (M_PI * 0.5));
|
||||
controller->data[i + 1] = tmp_r ? fast_atan2f(tmp_i, tmp_r) : ((tmp_i < 0) ? (IMLIB_PI * 1.5f) : (IMLIB_PI * 0.5f));
|
||||
}
|
||||
}
|
||||
|
||||
@ -629,7 +629,7 @@ void fft2d_phase(fft2d_controller_t *controller) {
|
||||
for (int i = 0, j = (1 << controller->h_pow2) * (1 << controller->w_pow2) * 2; i < j; i += 2) {
|
||||
float tmp_r = controller->data[i + 0];
|
||||
float tmp_i = controller->data[i + 1];
|
||||
controller->data[i + 0] = tmp_r ? fast_atan2f(tmp_i, tmp_r) : ((tmp_i < 0) ? (M_PI * 1.5) : (M_PI * 0.5));
|
||||
controller->data[i + 0] = tmp_r ? fast_atan2f(tmp_i, tmp_r) : ((tmp_i < 0) ? (IMLIB_PI * 1.5f) : (IMLIB_PI * 0.5f));
|
||||
controller->data[i + 1] = 0;
|
||||
}
|
||||
}
|
||||
@ -639,7 +639,7 @@ void fft2d_log(fft2d_controller_t *controller) {
|
||||
float tmp_r = controller->data[i + 0];
|
||||
float tmp_i = controller->data[i + 1];
|
||||
controller->data[i + 0] = fast_log(fast_sqrtf((tmp_r * tmp_r) + (tmp_i * tmp_i)));
|
||||
controller->data[i + 1] = tmp_r ? fast_atan2f(tmp_i, tmp_r) : ((tmp_i < 0) ? (M_PI * 1.5) : (M_PI * 0.5));
|
||||
controller->data[i + 1] = tmp_r ? fast_atan2f(tmp_i, tmp_r) : ((tmp_i < 0) ? (IMLIB_PI * 1.5f) : (IMLIB_PI * 0.5f));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -23,6 +23,7 @@
|
||||
*
|
||||
* Fast approximate math functions.
|
||||
*/
|
||||
#include "imlib.h"
|
||||
#include "fmath.h"
|
||||
|
||||
const float __atanf_lut[4] = {
|
||||
@ -87,11 +88,11 @@ inline float fast_atanf(float xx) {
|
||||
/* range reduction */
|
||||
if (x > 2.414213562373095f) {
|
||||
/* tan 3pi/8 */
|
||||
y = M_PI_2;
|
||||
y = IMLIB_PI_2;
|
||||
x = -(1.0f / x);
|
||||
} else if (x > 0.4142135623730950f) {
|
||||
/* tan pi/8 */
|
||||
y = M_PI_4;
|
||||
y = IMLIB_PI_4;
|
||||
x = (x - 1.0f) / (x + 1.0f);
|
||||
} else {
|
||||
y = 0.0f;
|
||||
@ -117,18 +118,18 @@ float fast_atan2f(float y, float x) {
|
||||
}
|
||||
|
||||
if (x < 0 && y >= 0) {
|
||||
return M_PI - fast_atanf(-y / x);
|
||||
return IMLIB_PI - fast_atanf(-y / x);
|
||||
}
|
||||
|
||||
if (x < 0 && y < 0) {
|
||||
return M_PI + fast_atanf(y / x);
|
||||
return IMLIB_PI + fast_atanf(y / x);
|
||||
}
|
||||
|
||||
if (x > 0 && y < 0) {
|
||||
return 2 * M_PI - fast_atanf(-y / x);
|
||||
return 2 * IMLIB_PI - fast_atanf(-y / x);
|
||||
}
|
||||
|
||||
return (y == 0) ? 0 : ((y > 0) ? M_PI : -M_PI);
|
||||
return (y == 0) ? 0 : ((y > 0) ? IMLIB_PI : -IMLIB_PI);
|
||||
}
|
||||
|
||||
float fast_log2(float x) {
|
||||
|
||||
@ -78,7 +78,7 @@ void imlib_find_hog(image_t *src, rectangle_t *roi, int cell_size) {
|
||||
k += m * m;
|
||||
// Find and quantize gradient degree
|
||||
// TODO atan2f is swapped for visualization
|
||||
int t = ((int) fast_fabsf((atan2f(vx, vy) * 180.0f / M_PI))) / 20;
|
||||
int t = ((int) fast_fabsf((atan2f(vx, vy) * 180.0f / IMLIB_PI))) / 20;
|
||||
t = (t == 9)? 0 : t;
|
||||
|
||||
// hog[((cy/cell_size) * x_cells + (cx/cell_size)) * N_BINS + t] += m;
|
||||
|
||||
@ -52,11 +52,9 @@
|
||||
// Enables 78 TensofFlow Lite operators.
|
||||
#define IMLIB_TF_FULLOPS (2)
|
||||
|
||||
#ifndef M_PI
|
||||
#define M_PI 3.14159265f
|
||||
#define M_PI_2 1.57079632f
|
||||
#define M_PI_4 0.78539816f
|
||||
#endif
|
||||
#define IMLIB_PI 3.14159265358979323846f
|
||||
#define IMLIB_PI_2 1.57079632679489661923f
|
||||
#define IMLIB_PI_4 0.78539816339744830962f
|
||||
|
||||
#define IM_LOG2_2(x) (((x) & 0x2ULL) ? (2) : 1) // NO ({ ... }) !
|
||||
#define IM_LOG2_4(x) (((x) & 0xCULL) ? (2 + IM_LOG2_2((x) >> 2)) : IM_LOG2_2(x)) // NO ({ ... }) !
|
||||
@ -117,8 +115,8 @@
|
||||
#define UINT64_T_MASK (UINT64_T_BITS - 1)
|
||||
#define UINT64_T_SHIFT IM_LOG2(UINT64_T_MASK)
|
||||
|
||||
#define IM_DEG2RAD(x) (((x) * M_PI) / 180)
|
||||
#define IM_RAD2DEG(x) (((x) * 180) / M_PI)
|
||||
#define IM_DEG2RAD(x) (((x) * IMLIB_PI) / 180.0f)
|
||||
#define IM_RAD2DEG(x) (((x) * 180.0f) / IMLIB_PI)
|
||||
|
||||
int imlib_ksize_to_n(int ksize);
|
||||
|
||||
|
||||
@ -342,7 +342,7 @@ static int comp_angle(image_t *img, kp_t *kp, float *a, float *b) {
|
||||
m_01 += v * v_sum;
|
||||
}
|
||||
|
||||
int angle = (int) (atan2f((float) m_01, (float) m_10) * (180.0f / M_PI));
|
||||
int angle = (int) (atan2f((float) m_01, (float) m_10) * (180.0f / IMLIB_PI));
|
||||
if (angle < 0) {
|
||||
angle += 360;
|
||||
}
|
||||
|
||||
@ -35,9 +35,9 @@ void imlib_logpolar_int(image_t *dst, image_t *src, rectangle_t *roi, bool linea
|
||||
if (!linear) {
|
||||
rho_scale = fast_log(rho_scale);
|
||||
}
|
||||
const float m_pi_1_5 = 1.5f * M_PI;
|
||||
const float m_pi_1_5 = 1.5f * IMLIB_PI;
|
||||
const float m_pi_1_5_d = IM_RAD2DEG(m_pi_1_5);
|
||||
const float m_pi_2_0 = 2.0f * M_PI;
|
||||
const float m_pi_2_0 = 2.0f * IMLIB_PI;
|
||||
const float m_pi_2_0_d = IM_RAD2DEG(m_pi_2_0);
|
||||
const int m_pi_2_0_d_i = m_pi_2_0_d;
|
||||
float theta_scale_d = m_pi_2_0_d / (w - 2);
|
||||
@ -423,7 +423,7 @@ void imlib_phasecorrelate(image_t *img0,
|
||||
float w_2 = roi0->w / 2.0f;
|
||||
float h_2 = roi0->h / 2.0f;
|
||||
float rho_scale = fast_log(fast_sqrtf((w_2 * w_2) + (h_2 * h_2))) / roi0->h;
|
||||
float theta_scale = (2 * M_PI) / roi0->w;
|
||||
float theta_scale = (2.0f * IMLIB_PI) / roi0->w;
|
||||
|
||||
*rotation = f_off_x * theta_scale;
|
||||
*scale = (f_off_y * rho_scale) + 1;
|
||||
@ -637,7 +637,7 @@ void imlib_phasecorrelate(image_t *img0,
|
||||
float w_2 = roi0->w / 2.0f;
|
||||
float h_2 = roi0->h / 2.0f;
|
||||
float rho_scale = fast_log(fast_sqrtf((w_2 * w_2) + (h_2 * h_2))) / roi0->h;
|
||||
float theta_scale = (2 * M_PI) / roi0->w;
|
||||
float theta_scale = (2.0f * IMLIB_PI) / roi0->w;
|
||||
|
||||
*rotation = *x_translation * theta_scale;
|
||||
*scale = (*y_translation * rho_scale) + 1;
|
||||
|
||||
BIN
lib/models/face_landmarks_192.tflite
Normal file
BIN
lib/models/face_landmarks_192.tflite
Normal file
Binary file not shown.
BIN
lib/models/yolov8n_192.tflite
Normal file
BIN
lib/models/yolov8n_192.tflite
Normal file
Binary file not shown.
1
lib/models/yolov8n_192.txt
Normal file
1
lib/models/yolov8n_192.txt
Normal file
@ -0,0 +1 @@
|
||||
person
|
||||
@ -1012,8 +1012,8 @@ static mp_obj_t py_omv_csi_ioctl(size_t n_args, const mp_obj_t *args) {
|
||||
case OMV_CSI_IOCTL_LEPTON_SET_RANGE:
|
||||
if (n_args >= 3) {
|
||||
// GCC will not let us pass floats to ... so we have to pass float pointers instead.
|
||||
float min = mp_obj_get_float(args[1]);
|
||||
float max = mp_obj_get_float(args[2]);
|
||||
float min = mp_obj_get_float_to_f(args[1]);
|
||||
float max = mp_obj_get_float_to_f(args[2]);
|
||||
error = omv_csi_ioctl(csi, request, &min, &max);
|
||||
}
|
||||
break;
|
||||
|
||||
@ -1091,8 +1091,8 @@ static mp_obj_t py_csi_ioctl(size_t n_args, const mp_obj_t *args) {
|
||||
case OMV_CSI_IOCTL_LEPTON_SET_RANGE:
|
||||
if (n_args == 2) {
|
||||
// GCC will not let us pass floats to ... so we have to pass float pointers instead.
|
||||
float min = mp_obj_get_float(args[0]);
|
||||
float max = mp_obj_get_float(args[1]);
|
||||
float min = mp_obj_get_float_to_f(args[0]);
|
||||
float max = mp_obj_get_float_to_f(args[1]);
|
||||
error = omv_csi_ioctl(self->csi, request, &min, &max);
|
||||
}
|
||||
break;
|
||||
@ -1238,7 +1238,7 @@ static mp_obj_t py_csi_ioctl(size_t n_args, const mp_obj_t *args) {
|
||||
case OMV_CSI_IOCTL_GENX320_CALIBRATE: {
|
||||
if (n_args == 2) {
|
||||
error = omv_csi_ioctl(self->csi, request, mp_obj_get_int(args[0]),
|
||||
(double) mp_obj_get_float(args[1]));
|
||||
mp_obj_get_float_to_d(args[1]));
|
||||
if (error > 0) {
|
||||
ret_obj = mp_obj_new_int(error);
|
||||
}
|
||||
|
||||
@ -126,7 +126,7 @@ static void fir_fill_image_float_obj(image_t *img, mp_obj_t *data, float min, fl
|
||||
uint8_t *row_pointer = ((uint8_t *) img->data) + row_offset;
|
||||
|
||||
for (int x = 0; x < img->w; x++) {
|
||||
float raw = mp_obj_get_float(raw_row[x]);
|
||||
float raw = mp_obj_get_float_to_f(raw_row[x]);
|
||||
|
||||
if (raw < min) {
|
||||
raw = min;
|
||||
|
||||
@ -162,10 +162,10 @@ rectangle_t py_helper_arg_to_roi(const mp_obj_t arg, const image_t *img) {
|
||||
void py_helper_arg_to_scale(const mp_obj_t arg_x_scale, const mp_obj_t arg_y_scale,
|
||||
float *x_scale, float *y_scale) {
|
||||
if (arg_x_scale != mp_const_none) {
|
||||
*x_scale = mp_obj_get_float(arg_x_scale);
|
||||
*x_scale = mp_obj_get_float_to_f(arg_x_scale);
|
||||
}
|
||||
if (arg_y_scale != mp_const_none) {
|
||||
*y_scale = mp_obj_get_float(arg_y_scale);
|
||||
*y_scale = mp_obj_get_float_to_f(arg_y_scale);
|
||||
}
|
||||
|
||||
if (arg_x_scale == mp_const_none && arg_y_scale != mp_const_none) {
|
||||
@ -183,11 +183,11 @@ void py_helper_arg_to_minmax(const mp_obj_t minmax, float *min, float *max,
|
||||
if (minmax != mp_const_none) {
|
||||
mp_obj_t *arg_scale;
|
||||
mp_obj_get_array_fixed_n(minmax, 2, &arg_scale);
|
||||
min_out = mp_obj_get_float(arg_scale[0]);
|
||||
max_out = mp_obj_get_float(arg_scale[1]);
|
||||
min_out = mp_obj_get_float_to_f(arg_scale[0]);
|
||||
max_out = mp_obj_get_float_to_f(arg_scale[1]);
|
||||
} else if (array && array_size) {
|
||||
for (int i = 0; i < array_size; i++) {
|
||||
float t = mp_obj_get_float(array[i]);
|
||||
float t = mp_obj_get_float_to_f(array[i]);
|
||||
if (t < min_out) {
|
||||
min_out = t;
|
||||
}
|
||||
@ -203,7 +203,7 @@ void py_helper_arg_to_minmax(const mp_obj_t minmax, float *min, float *max,
|
||||
|
||||
float py_helper_arg_to_float(const mp_obj_t arg, float default_value) {
|
||||
if (arg != mp_const_none) {
|
||||
return mp_obj_get_float(arg);
|
||||
return mp_obj_get_float_to_f(arg);
|
||||
}
|
||||
return default_value;
|
||||
}
|
||||
@ -213,7 +213,7 @@ void py_helper_arg_to_float_array(const mp_obj_t arg, float *array, size_t size)
|
||||
mp_obj_t *arg_array;
|
||||
mp_obj_get_array_fixed_n(arg, size, &arg_array);
|
||||
for (int i = 0; i < size; i++) {
|
||||
array[i] = mp_obj_get_float(arg_array[i]);
|
||||
array[i] = mp_obj_get_float_to_f(arg_array[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -303,27 +303,14 @@ float py_helper_keyword_float(size_t n_args, const mp_obj_t *args, size_t arg_in
|
||||
mp_map_elem_t *kw_arg = mp_map_lookup(kw_args, kw, MP_MAP_LOOKUP);
|
||||
|
||||
if (kw_arg) {
|
||||
default_val = mp_obj_get_float(kw_arg->value);
|
||||
default_val = mp_obj_get_float_to_f(kw_arg->value);
|
||||
} else if (n_args > arg_index) {
|
||||
default_val = mp_obj_get_float(args[arg_index]);
|
||||
default_val = mp_obj_get_float_to_f(args[arg_index]);
|
||||
}
|
||||
|
||||
return default_val;
|
||||
}
|
||||
|
||||
bool py_helper_keyword_float_maybe(size_t n_args, const mp_obj_t *args, size_t arg_index,
|
||||
mp_map_t *kw_args, mp_obj_t kw, float *value) {
|
||||
mp_map_elem_t *kw_arg = mp_map_lookup(kw_args, kw, MP_MAP_LOOKUP);
|
||||
|
||||
if (kw_arg) {
|
||||
return mp_obj_get_float_maybe(kw_arg->value, value);
|
||||
} else if (n_args > arg_index) {
|
||||
return mp_obj_get_float_maybe(args[arg_index], value);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
void py_helper_keyword_int_array(size_t n_args, const mp_obj_t *args, size_t arg_index,
|
||||
mp_map_t *kw_args, mp_obj_t kw, int *x, int size) {
|
||||
mp_map_elem_t *kw_arg = mp_map_lookup(kw_args, kw, MP_MAP_LOOKUP);
|
||||
@ -354,8 +341,8 @@ float *py_helper_keyword_corner_array(size_t n_args, const mp_obj_t *args, size_
|
||||
for (int i = 0; i < 4; i++) {
|
||||
mp_obj_t *arg_point;
|
||||
mp_obj_get_array_fixed_n(arg_array[i], 2, &arg_point);
|
||||
corners[(i * 2) + 0] = mp_obj_get_float(arg_point[0]);
|
||||
corners[(i * 2) + 1] = mp_obj_get_float(arg_point[1]);
|
||||
corners[(i * 2) + 0] = mp_obj_get_float_to_f(arg_point[0]);
|
||||
corners[(i * 2) + 1] = mp_obj_get_float_to_f(arg_point[1]);
|
||||
}
|
||||
return corners;
|
||||
} else if (n_args > arg_index) {
|
||||
@ -365,8 +352,8 @@ float *py_helper_keyword_corner_array(size_t n_args, const mp_obj_t *args, size_
|
||||
for (int i = 0; i < 4; i++) {
|
||||
mp_obj_t *arg_point;
|
||||
mp_obj_get_array_fixed_n(arg_array[i], 2, &arg_point);
|
||||
corners[(i * 2) + 0] = mp_obj_get_float(arg_point[0]);
|
||||
corners[(i * 2) + 1] = mp_obj_get_float(arg_point[1]);
|
||||
corners[(i * 2) + 0] = mp_obj_get_float_to_f(arg_point[0]);
|
||||
corners[(i * 2) + 1] = mp_obj_get_float_to_f(arg_point[1]);
|
||||
}
|
||||
return corners;
|
||||
}
|
||||
|
||||
@ -59,8 +59,6 @@ bool py_helper_keyword_int_maybe(size_t n_args, const mp_obj_t *args, size_t arg
|
||||
mp_map_t *kw_args, mp_obj_t kw, int *value);
|
||||
float py_helper_keyword_float(size_t n_args, const mp_obj_t *args, size_t arg_index,
|
||||
mp_map_t *kw_args, mp_obj_t kw, float default_val);
|
||||
bool py_helper_keyword_float_maybe(size_t n_args, const mp_obj_t *args, size_t arg_index,
|
||||
mp_map_t *kw_args, mp_obj_t kw, float *value);
|
||||
void py_helper_keyword_int_array(size_t n_args, const mp_obj_t *args, size_t arg_index,
|
||||
mp_map_t *kw_args, mp_obj_t kw, int *x, int size);
|
||||
void py_helper_keyword_float_array(size_t n_args, const mp_obj_t *args, size_t arg_index,
|
||||
|
||||
@ -1496,10 +1496,10 @@ static mp_obj_t py_image_draw_arrow(size_t n_args, const mp_obj_t *args, mp_map_
|
||||
float vx = -uy;
|
||||
float vy = ux;
|
||||
|
||||
int a0x = fast_roundf(arg_x1 - (arg_s * ux) + (arg_s * vx * 0.5));
|
||||
int a0y = fast_roundf(arg_y1 - (arg_s * uy) + (arg_s * vy * 0.5));
|
||||
int a1x = fast_roundf(arg_x1 - (arg_s * ux) - (arg_s * vx * 0.5));
|
||||
int a1y = fast_roundf(arg_y1 - (arg_s * uy) - (arg_s * vy * 0.5));
|
||||
int a0x = fast_roundf(arg_x1 - (arg_s * ux) + (arg_s * vx * 0.5f));
|
||||
int a0y = fast_roundf(arg_y1 - (arg_s * uy) + (arg_s * vy * 0.5f));
|
||||
int a1x = fast_roundf(arg_x1 - (arg_s * ux) - (arg_s * vx * 0.5f));
|
||||
int a1y = fast_roundf(arg_y1 - (arg_s * uy) - (arg_s * vy * 0.5f));
|
||||
|
||||
imlib_draw_line(arg_img, arg_x0, arg_y0, arg_x1, arg_y1, arg_c, arg_thickness);
|
||||
imlib_draw_line(arg_img, arg_x1, arg_y1, a0x, a0y, arg_c, arg_thickness);
|
||||
@ -1949,7 +1949,7 @@ static mp_obj_t py_ccm(mp_obj_t img_obj, mp_obj_t ccm_obj) {
|
||||
offset = offset || (row_len == 4);
|
||||
if ((row_len == 3) || (row_len == 4)) {
|
||||
for (size_t j = 0; j < row_len; j++) {
|
||||
ccm[(i * 4) + j] = mp_obj_get_float(row_items[j]);
|
||||
ccm[(i * 4) + j] = mp_obj_get_float_to_f(row_items[j]);
|
||||
}
|
||||
} else {
|
||||
mp_raise_msg(&mp_type_ValueError, MP_ERROR_TEXT("Unexpected matrix dimensions!"));
|
||||
@ -1959,7 +1959,7 @@ static mp_obj_t py_ccm(mp_obj_t img_obj, mp_obj_t ccm_obj) {
|
||||
} else if (len == 9) {
|
||||
for (size_t i = 0; i < 3; i++) {
|
||||
for (size_t j = 0; j < 3; j++) {
|
||||
ccm[(i * 4) + j] = mp_obj_get_float(items[(i * 3) + j]);
|
||||
ccm[(i * 4) + j] = mp_obj_get_float_to_f(items[(i * 3) + j]);
|
||||
}
|
||||
}
|
||||
// Form [rr, rg, rb, ro, gr, gg, gb, go, br, bg, bb, bo]
|
||||
@ -1967,7 +1967,7 @@ static mp_obj_t py_ccm(mp_obj_t img_obj, mp_obj_t ccm_obj) {
|
||||
} else if (len == 12 || len == 16) {
|
||||
offset = true;
|
||||
for (size_t i = 0; i < 12; i++) {
|
||||
ccm[i] = mp_obj_get_float(items[i]);
|
||||
ccm[i] = mp_obj_get_float_to_f(items[i]);
|
||||
}
|
||||
} else {
|
||||
mp_raise_msg(&mp_type_ValueError, MP_ERROR_TEXT("Unexpected matrix dimensions!"));
|
||||
@ -2687,10 +2687,10 @@ static void py_similarity_print(const mp_print_t *print, mp_obj_t self_in, mp_pr
|
||||
py_similarity_obj_t *self = self_in;
|
||||
mp_printf(print,
|
||||
"{\"mean\":%f, \"stdev\":%f, \"min\":%f, \"max\":%f}",
|
||||
(double) mp_obj_get_float(self->avg),
|
||||
(double) mp_obj_get_float(self->std),
|
||||
(double) mp_obj_get_float(self->min),
|
||||
(double) mp_obj_get_float(self->max));
|
||||
mp_obj_get_float_to_d(self->avg),
|
||||
mp_obj_get_float_to_d(self->std),
|
||||
mp_obj_get_float_to_d(self->min),
|
||||
mp_obj_get_float_to_d(self->max));
|
||||
}
|
||||
|
||||
static mp_obj_t py_similarity_subscr(mp_obj_t self_in, mp_obj_t index, mp_obj_t value) {
|
||||
@ -3425,19 +3425,19 @@ mp_obj_t py_histogram_get_percentile(mp_obj_t self_in, mp_obj_t percentile) {
|
||||
hist.BBins = fb_alloc(hist.BBinCount * sizeof(float), FB_ALLOC_NO_HINT);
|
||||
|
||||
for (int i = 0; i < hist.LBinCount; i++) {
|
||||
hist.LBins[i] = mp_obj_get_float(((mp_obj_list_t *) ((py_histogram_obj_t *) self_in)->LBins)->items[i]);
|
||||
hist.LBins[i] = mp_obj_get_float_to_f(((mp_obj_list_t *) ((py_histogram_obj_t *) self_in)->LBins)->items[i]);
|
||||
}
|
||||
|
||||
for (int i = 0; i < hist.ABinCount; i++) {
|
||||
hist.ABins[i] = mp_obj_get_float(((mp_obj_list_t *) ((py_histogram_obj_t *) self_in)->ABins)->items[i]);
|
||||
hist.ABins[i] = mp_obj_get_float_to_f(((mp_obj_list_t *) ((py_histogram_obj_t *) self_in)->ABins)->items[i]);
|
||||
}
|
||||
|
||||
for (int i = 0; i < hist.BBinCount; i++) {
|
||||
hist.BBins[i] = mp_obj_get_float(((mp_obj_list_t *) ((py_histogram_obj_t *) self_in)->BBins)->items[i]);
|
||||
hist.BBins[i] = mp_obj_get_float_to_f(((mp_obj_list_t *) ((py_histogram_obj_t *) self_in)->BBins)->items[i]);
|
||||
}
|
||||
|
||||
percentile_t p;
|
||||
imlib_get_percentile(&p, ((py_histogram_obj_t *) self_in)->pixfmt, &hist, mp_obj_get_float(percentile));
|
||||
imlib_get_percentile(&p, ((py_histogram_obj_t *) self_in)->pixfmt, &hist, mp_obj_get_float_to_f(percentile));
|
||||
fb_alloc_free_till_mark();
|
||||
|
||||
py_percentile_obj_t *o = m_new_obj(py_percentile_obj_t);
|
||||
@ -3463,15 +3463,15 @@ mp_obj_t py_histogram_get_threshold(mp_obj_t self_in) {
|
||||
hist.BBins = fb_alloc(hist.BBinCount * sizeof(float), FB_ALLOC_NO_HINT);
|
||||
|
||||
for (int i = 0; i < hist.LBinCount; i++) {
|
||||
hist.LBins[i] = mp_obj_get_float(((mp_obj_list_t *) ((py_histogram_obj_t *) self_in)->LBins)->items[i]);
|
||||
hist.LBins[i] = mp_obj_get_float_to_f(((mp_obj_list_t *) ((py_histogram_obj_t *) self_in)->LBins)->items[i]);
|
||||
}
|
||||
|
||||
for (int i = 0; i < hist.ABinCount; i++) {
|
||||
hist.ABins[i] = mp_obj_get_float(((mp_obj_list_t *) ((py_histogram_obj_t *) self_in)->ABins)->items[i]);
|
||||
hist.ABins[i] = mp_obj_get_float_to_f(((mp_obj_list_t *) ((py_histogram_obj_t *) self_in)->ABins)->items[i]);
|
||||
}
|
||||
|
||||
for (int i = 0; i < hist.BBinCount; i++) {
|
||||
hist.BBins[i] = mp_obj_get_float(((mp_obj_list_t *) ((py_histogram_obj_t *) self_in)->BBins)->items[i]);
|
||||
hist.BBins[i] = mp_obj_get_float_to_f(((mp_obj_list_t *) ((py_histogram_obj_t *) self_in)->BBins)->items[i]);
|
||||
}
|
||||
|
||||
threshold_t t;
|
||||
@ -3501,15 +3501,15 @@ mp_obj_t py_histogram_get_statistics(mp_obj_t self_in) {
|
||||
hist.BBins = fb_alloc(hist.BBinCount * sizeof(float), FB_ALLOC_NO_HINT);
|
||||
|
||||
for (int i = 0; i < hist.LBinCount; i++) {
|
||||
hist.LBins[i] = mp_obj_get_float(((mp_obj_list_t *) ((py_histogram_obj_t *) self_in)->LBins)->items[i]);
|
||||
hist.LBins[i] = mp_obj_get_float_to_f(((mp_obj_list_t *) ((py_histogram_obj_t *) self_in)->LBins)->items[i]);
|
||||
}
|
||||
|
||||
for (int i = 0; i < hist.ABinCount; i++) {
|
||||
hist.ABins[i] = mp_obj_get_float(((mp_obj_list_t *) ((py_histogram_obj_t *) self_in)->ABins)->items[i]);
|
||||
hist.ABins[i] = mp_obj_get_float_to_f(((mp_obj_list_t *) ((py_histogram_obj_t *) self_in)->ABins)->items[i]);
|
||||
}
|
||||
|
||||
for (int i = 0; i < hist.BBinCount; i++) {
|
||||
hist.BBins[i] = mp_obj_get_float(((mp_obj_list_t *) ((py_histogram_obj_t *) self_in)->BBins)->items[i]);
|
||||
hist.BBins[i] = mp_obj_get_float_to_f(((mp_obj_list_t *) ((py_histogram_obj_t *) self_in)->BBins)->items[i]);
|
||||
}
|
||||
|
||||
statistics_t stats;
|
||||
@ -3984,13 +3984,13 @@ static void py_blob_print(const mp_print_t *print, mp_obj_t self_in, mp_print_ki
|
||||
mp_obj_get_int(self->w),
|
||||
mp_obj_get_int(self->h),
|
||||
mp_obj_get_int(self->pixels),
|
||||
fast_roundf(mp_obj_get_float(self->cx)),
|
||||
fast_roundf(mp_obj_get_float(self->cy)),
|
||||
(double) mp_obj_get_float(self->rotation),
|
||||
fast_roundf(mp_obj_get_float_to_f(self->cx)),
|
||||
fast_roundf(mp_obj_get_float_to_f(self->cy)),
|
||||
mp_obj_get_float_to_d(self->rotation),
|
||||
mp_obj_get_int(self->code),
|
||||
mp_obj_get_int(self->count),
|
||||
mp_obj_get_int(self->perimeter),
|
||||
(double) mp_obj_get_float(self->roundness));
|
||||
mp_obj_get_float_to_d(self->roundness));
|
||||
}
|
||||
|
||||
static mp_obj_t py_blob_subscr(mp_obj_t self_in, mp_obj_t index, mp_obj_t value) {
|
||||
@ -4012,8 +4012,8 @@ static mp_obj_t py_blob_subscr(mp_obj_t self_in, mp_obj_t index, mp_obj_t value)
|
||||
case 2: return self->w;
|
||||
case 3: return self->h;
|
||||
case 4: return self->pixels;
|
||||
case 5: return mp_obj_new_int(fast_roundf(mp_obj_get_float(self->cx)));
|
||||
case 6: return mp_obj_new_int(fast_roundf(mp_obj_get_float(self->cy)));
|
||||
case 5: return mp_obj_new_int(fast_roundf(mp_obj_get_float_to_f(self->cx)));
|
||||
case 6: return mp_obj_new_int(fast_roundf(mp_obj_get_float_to_f(self->cy)));
|
||||
case 7: return self->rotation;
|
||||
case 8: return self->code;
|
||||
case 9: return self->count;
|
||||
@ -4068,7 +4068,7 @@ mp_obj_t py_blob_pixels(mp_obj_t self_in) {
|
||||
static MP_DEFINE_CONST_FUN_OBJ_1(py_blob_pixels_obj, py_blob_pixels);
|
||||
|
||||
mp_obj_t py_blob_cx(mp_obj_t self_in) {
|
||||
return mp_obj_new_int(fast_roundf(mp_obj_get_float(((py_blob_obj_t *) self_in)->cx)));
|
||||
return mp_obj_new_int(fast_roundf(mp_obj_get_float_to_f(((py_blob_obj_t *) self_in)->cx)));
|
||||
}
|
||||
static MP_DEFINE_CONST_FUN_OBJ_1(py_blob_cx_obj, py_blob_cx);
|
||||
|
||||
@ -4078,7 +4078,7 @@ mp_obj_t py_blob_cxf(mp_obj_t self_in) {
|
||||
static MP_DEFINE_CONST_FUN_OBJ_1(py_blob_cxf_obj, py_blob_cxf);
|
||||
|
||||
mp_obj_t py_blob_cy(mp_obj_t self_in) {
|
||||
return mp_obj_new_int(fast_roundf(mp_obj_get_float(((py_blob_obj_t *) self_in)->cy)));
|
||||
return mp_obj_new_int(fast_roundf(mp_obj_get_float_to_f(((py_blob_obj_t *) self_in)->cy)));
|
||||
}
|
||||
static MP_DEFINE_CONST_FUN_OBJ_1(py_blob_cy_obj, py_blob_cy);
|
||||
|
||||
@ -4093,7 +4093,7 @@ mp_obj_t py_blob_rotation(mp_obj_t self_in) {
|
||||
static MP_DEFINE_CONST_FUN_OBJ_1(py_blob_rotation_obj, py_blob_rotation);
|
||||
|
||||
mp_obj_t py_blob_rotation_deg(mp_obj_t self_in) {
|
||||
return mp_obj_new_int((mp_int_t) IM_RAD2DEG(mp_obj_get_float(((py_blob_obj_t *) self_in)->rotation)));
|
||||
return mp_obj_new_int((mp_int_t) IM_RAD2DEG(mp_obj_get_float_to_f(((py_blob_obj_t *) self_in)->rotation)));
|
||||
}
|
||||
static MP_DEFINE_CONST_FUN_OBJ_1(py_blob_rotation_deg_obj, py_blob_rotation_deg);
|
||||
|
||||
@ -4123,7 +4123,7 @@ mp_obj_t py_blob_roundness(mp_obj_t self_in) {
|
||||
static MP_DEFINE_CONST_FUN_OBJ_1(py_blob_roundness_obj, py_blob_roundness);
|
||||
|
||||
mp_obj_t py_blob_elongation(mp_obj_t self_in) {
|
||||
return mp_obj_new_float(1 - mp_obj_get_float(((py_blob_obj_t *) self_in)->roundness));
|
||||
return mp_obj_new_float(1 - mp_obj_get_float_to_f(((py_blob_obj_t *) self_in)->roundness));
|
||||
}
|
||||
static MP_DEFINE_CONST_FUN_OBJ_1(py_blob_elongation_obj, py_blob_elongation);
|
||||
|
||||
@ -4146,7 +4146,7 @@ static MP_DEFINE_CONST_FUN_OBJ_1(py_blob_density_obj, py_blob_density);
|
||||
mp_obj_t py_blob_compactness(mp_obj_t self_in) {
|
||||
int pixels = mp_obj_get_int(((py_blob_obj_t *) self_in)->pixels);
|
||||
float perimeter = mp_obj_get_int(((py_blob_obj_t *) self_in)->perimeter);
|
||||
return mp_obj_new_float(IM_DIV((pixels * 4 * M_PI), (perimeter * perimeter)));
|
||||
return mp_obj_new_float(IM_DIV((pixels * 4.0f * IMLIB_PI), (perimeter * perimeter)));
|
||||
}
|
||||
static MP_DEFINE_CONST_FUN_OBJ_1(py_blob_compactness_obj, py_blob_compactness);
|
||||
|
||||
@ -4382,7 +4382,7 @@ mp_obj_t py_blob_enclosed_ellipse(mp_obj_t self_in) {
|
||||
if (l0 >= l1) {
|
||||
r = IM_RAD2DEG(fast_atan2f(m0y - m2y, m0x - m2x));
|
||||
} else {
|
||||
r = IM_RAD2DEG(fast_atan2f(m1y - m3y, m1x - m3x) + M_PI_2);
|
||||
r = IM_RAD2DEG(fast_atan2f(m1y - m3y, m1x - m3x) + IMLIB_PI_2);
|
||||
}
|
||||
|
||||
return mp_obj_new_tuple(5, (mp_obj_t []) {mp_obj_new_int(cx),
|
||||
@ -5193,16 +5193,16 @@ static void py_apriltag_print(const mp_print_t *print, mp_obj_t self_in, mp_prin
|
||||
mp_obj_get_int(self->family),
|
||||
mp_obj_get_int(self->cx),
|
||||
mp_obj_get_int(self->cy),
|
||||
(double) mp_obj_get_float(self->rotation),
|
||||
(double) mp_obj_get_float(self->decision_margin),
|
||||
mp_obj_get_float_to_d(self->rotation),
|
||||
mp_obj_get_float_to_d(self->decision_margin),
|
||||
mp_obj_get_int(self->hamming),
|
||||
(double) mp_obj_get_float(self->goodness),
|
||||
(double) mp_obj_get_float(self->x_translation),
|
||||
(double) mp_obj_get_float(self->y_translation),
|
||||
(double) mp_obj_get_float(self->z_translation),
|
||||
(double) mp_obj_get_float(self->x_rotation),
|
||||
(double) mp_obj_get_float(self->y_rotation),
|
||||
(double) mp_obj_get_float(self->z_rotation));
|
||||
mp_obj_get_float_to_d(self->goodness),
|
||||
mp_obj_get_float_to_d(self->x_translation),
|
||||
mp_obj_get_float_to_d(self->y_translation),
|
||||
mp_obj_get_float_to_d(self->z_translation),
|
||||
mp_obj_get_float_to_d(self->x_rotation),
|
||||
mp_obj_get_float_to_d(self->y_rotation),
|
||||
mp_obj_get_float_to_d(self->z_rotation));
|
||||
}
|
||||
|
||||
static void py_apriltag_attr(mp_obj_t self_in, qstr attr, mp_obj_t *dest) {
|
||||
@ -5272,13 +5272,13 @@ static void py_apriltag_attr(mp_obj_t self_in, qstr attr, mp_obj_t *dest) {
|
||||
}
|
||||
break;
|
||||
case MP_QSTR_cx:
|
||||
dest[0] = mp_obj_new_int(fast_roundf(mp_obj_get_float(self->cx)));
|
||||
dest[0] = mp_obj_new_int(fast_roundf(mp_obj_get_float_to_f(self->cx)));
|
||||
break;
|
||||
case MP_QSTR_cxf:
|
||||
dest[0] = self->cx;
|
||||
break;
|
||||
case MP_QSTR_cy:
|
||||
dest[0] = mp_obj_new_int(fast_roundf(mp_obj_get_float(self->cy)));
|
||||
dest[0] = mp_obj_new_int(fast_roundf(mp_obj_get_float_to_f(self->cy)));
|
||||
break;
|
||||
case MP_QSTR_cyf:
|
||||
dest[0] = self->cy;
|
||||
@ -5422,7 +5422,7 @@ static void py_datamatrix_print(const mp_print_t *print, mp_obj_t self_in, mp_pr
|
||||
mp_obj_get_int(self->w),
|
||||
mp_obj_get_int(self->h),
|
||||
mp_obj_str_get_str(self->payload),
|
||||
(double) mp_obj_get_float(self->rotation),
|
||||
mp_obj_get_float_to_d(self->rotation),
|
||||
mp_obj_get_int(self->rows),
|
||||
mp_obj_get_int(self->columns),
|
||||
mp_obj_get_int(self->capacity),
|
||||
@ -5620,7 +5620,7 @@ static void py_barcode_print(const mp_print_t *print, mp_obj_t self_in, mp_print
|
||||
mp_obj_get_int(self->h),
|
||||
mp_obj_str_get_str(self->payload),
|
||||
mp_obj_get_int(self->type),
|
||||
(double) mp_obj_get_float(self->rotation),
|
||||
mp_obj_get_float_to_d(self->rotation),
|
||||
mp_obj_get_int(self->quality));
|
||||
}
|
||||
|
||||
@ -5789,11 +5789,11 @@ static void py_displacement_print(const mp_print_t *print, mp_obj_t self_in, mp_
|
||||
py_displacement_obj_t *self = self_in;
|
||||
mp_printf(print,
|
||||
"{\"x_translation\":%f, \"y_translation\":%f, \"rotation\":%f, \"scale\":%f, \"response\":%f}",
|
||||
(double) mp_obj_get_float(self->x_translation),
|
||||
(double) mp_obj_get_float(self->y_translation),
|
||||
(double) mp_obj_get_float(self->rotation),
|
||||
(double) mp_obj_get_float(self->scale),
|
||||
(double) mp_obj_get_float(self->response));
|
||||
mp_obj_get_float_to_d(self->x_translation),
|
||||
mp_obj_get_float_to_d(self->y_translation),
|
||||
mp_obj_get_float_to_d(self->rotation),
|
||||
mp_obj_get_float_to_d(self->scale),
|
||||
mp_obj_get_float_to_d(self->response));
|
||||
}
|
||||
|
||||
static mp_obj_t py_displacement_subscr(mp_obj_t self_in, mp_obj_t index, mp_obj_t value) {
|
||||
@ -5904,7 +5904,7 @@ static MP_DEFINE_CONST_FUN_OBJ_KW(py_image_find_displacement_obj, 2, py_image_fi
|
||||
static mp_obj_t py_image_find_template(size_t n_args, const mp_obj_t *args, mp_map_t *kw_args) {
|
||||
image_t *arg_img = py_helper_arg_to_image(args[0], ARG_IMAGE_GRAYSCALE);
|
||||
image_t *arg_template = py_helper_arg_to_image(args[1], ARG_IMAGE_GRAYSCALE);
|
||||
float arg_thresh = mp_obj_get_float(args[2]);
|
||||
float arg_thresh = mp_obj_get_float_to_f(args[2]);
|
||||
|
||||
rectangle_t roi;
|
||||
py_helper_keyword_rectangle_roi(arg_img, n_args, args, 3, kw_args, &roi);
|
||||
|
||||
@ -84,7 +84,7 @@ static void py_ml_process_input(py_ml_model_obj_t *model, mp_obj_t arg) {
|
||||
void *input_buffer = ml_backend_get_input(model, i);
|
||||
size_t input_size = py_ml_tuple_sum(MP_OBJ_TO_PTR(model->input_shape->items[i]));
|
||||
mp_obj_tuple_t *input_shape = MP_OBJ_TO_PTR(model->input_shape->items[i]);
|
||||
float input_scale = 1.0f / mp_obj_get_float(model->input_scale->items[i]);
|
||||
float input_scale = 1.0f / mp_obj_get_float_to_f(model->input_scale->items[i]);
|
||||
int input_zero_point = mp_obj_get_int(model->input_zero_point->items[i]);
|
||||
int input_dtype = mp_obj_get_int(model->input_dtype->items[i]);
|
||||
mp_obj_t input_arg = input_list->items[i];
|
||||
@ -157,7 +157,7 @@ static mp_obj_t py_ml_process_output(py_ml_model_obj_t *model, bool deep_copy) {
|
||||
void *model_output = ml_backend_get_output(model, i);
|
||||
size_t size = py_ml_tuple_sum(MP_OBJ_TO_PTR(model->output_shape->items[i]));
|
||||
mp_obj_tuple_t *output_shape = MP_OBJ_TO_PTR(model->output_shape->items[i]);
|
||||
float output_scale = mp_obj_get_float(model->output_scale->items[i]);
|
||||
float output_scale = mp_obj_get_float_to_f(model->output_scale->items[i]);
|
||||
int output_zero_point = mp_obj_get_int(model->output_zero_point->items[i]);
|
||||
int output_dtype = mp_obj_get_int(model->output_dtype->items[i]);
|
||||
|
||||
|
||||
@ -89,7 +89,7 @@ static void tof_fill_image_float_obj(image_t *img, mp_obj_t *data, float min, fl
|
||||
uint8_t *row_pointer = ((uint8_t *) img->data) + row_offset;
|
||||
|
||||
for (int x = 0; x < img->w; x++) {
|
||||
float raw = mp_obj_get_float(raw_row[x]);
|
||||
float raw = mp_obj_get_float_to_f(raw_row[x]);
|
||||
|
||||
if (raw < min) {
|
||||
raw = min;
|
||||
|
||||
@ -0,0 +1,57 @@
|
||||
# This work is licensed under the MIT license.
|
||||
# Copyright (c) 2013-2025 OpenMV LLC. All rights reserved.
|
||||
# https://github.com/openmv/openmv/blob/master/LICENSE
|
||||
#
|
||||
# This example shows off Google's MediaPipe Face Landmark Detection model for multiple faces.
|
||||
#
|
||||
# NOTE: This exaxmple requires an OpenMV Cam with an NPU like the AE3 or N6 to run real-time.
|
||||
|
||||
import csi
|
||||
import time
|
||||
import ml
|
||||
from ml.preprocessing import Normalization
|
||||
from ml.postprocessing.mediapipe import BlazeFace
|
||||
from ml.postprocessing.mediapipe import FaceLandmarks
|
||||
|
||||
# Initialize the sensor.
|
||||
csi0 = csi.CSI()
|
||||
csi0.reset()
|
||||
csi0.pixformat(csi.RGB565)
|
||||
csi0.framesize(csi.VGA)
|
||||
csi0.window((400, 400))
|
||||
|
||||
# Load built-in face detection model
|
||||
face_detection = ml.Model("/rom/blazeface_front_128.tflite", postprocess=BlazeFace(threshold=0.4))
|
||||
print(face_detection)
|
||||
|
||||
# Load built-in face landmark model
|
||||
face_landmarks = ml.Model("/rom/face_landmarks_192.tflite", postprocess=FaceLandmarks(threshold=0.4))
|
||||
print(face_landmarks)
|
||||
|
||||
clock = time.clock()
|
||||
while True:
|
||||
clock.tick()
|
||||
img = csi0.snapshot()
|
||||
|
||||
# faces is a list of ((x, y, w, h), score, keypoints) tuples
|
||||
faces = face_detection.predict([img])
|
||||
|
||||
if faces:
|
||||
for r, score, keypoints in faces[0]:
|
||||
# rect is (x, y, w, h) - enlarge by 2x for face landmarks model
|
||||
wider_rect = (r[0] - r[2] // 2, r[1] - r[3] // 2, r[2] * 2, r[3] * 2)
|
||||
# Operate on just the ROI of the detected face
|
||||
n = Normalization(roi=wider_rect)
|
||||
|
||||
# marks is a list of ((x, y, w, h), score, keypoints) tuples
|
||||
marks = face_landmarks.predict([n(img)])
|
||||
|
||||
# Draw bounding boxes around the detected faces and keypoints.
|
||||
for i, detections in enumerate(marks):
|
||||
for r, score, keypoints in detections:
|
||||
ml.utils.draw_predictions(img, [r], ("face",), ((0, 0, 255),), format=None)
|
||||
|
||||
# keypoints is a ndarray of shape (468, 3) where each keypoint is (x, y, z)
|
||||
ml.utils.draw_keypoints(img, keypoints, radius=0, color=(255, 0, 0))
|
||||
|
||||
print(clock.fps(), "fps")
|
||||
@ -0,0 +1,75 @@
|
||||
# This work is licensed under the MIT license.
|
||||
# Copyright (c) 2013-2025 OpenMV LLC. All rights reserved.
|
||||
# https://github.com/openmv/openmv/blob/master/LICENSE
|
||||
#
|
||||
# This example shows off Google's MediaPipe Face Landmark Detection model for a single face.
|
||||
#
|
||||
# NOTE: This exaxmple requires an OpenMV Cam with an NPU like the AE3 or N6 to run real-time.
|
||||
|
||||
import csi
|
||||
import time
|
||||
import ml
|
||||
from ml.preprocessing import Normalization
|
||||
from ml.postprocessing.mediapipe import BlazeFace
|
||||
from ml.postprocessing.mediapipe import FaceLandmarks
|
||||
|
||||
# Initialize the sensor.
|
||||
csi0 = csi.CSI()
|
||||
csi0.reset()
|
||||
csi0.pixformat(csi.RGB565)
|
||||
csi0.framesize(csi.VGA)
|
||||
csi0.window((400, 400))
|
||||
|
||||
# Load built-in face detection model
|
||||
face_detection = ml.Model("/rom/blazeface_front_128.tflite", postprocess=BlazeFace(threshold=0.4))
|
||||
print(face_detection)
|
||||
|
||||
# Load built-in face landmark model
|
||||
face_landmarks = ml.Model("/rom/face_landmarks_192.tflite", postprocess=FaceLandmarks(threshold=0.4))
|
||||
print(face_landmarks)
|
||||
|
||||
# Tracking vars.
|
||||
n = None
|
||||
|
||||
clock = time.clock()
|
||||
while True:
|
||||
clock.tick()
|
||||
img = csi0.snapshot()
|
||||
|
||||
if n is None:
|
||||
# faces is a list of ((x, y, w, h), score, keypoints) tuples
|
||||
faces = face_detection.predict([img])
|
||||
|
||||
if faces:
|
||||
for r, score, keypoints in faces[0]:
|
||||
# rect is (x, y, w, h) - enlarge by 2x for face landmarks model
|
||||
wider_rect = (r[0] - r[2] // 2, r[1] - r[3] // 2, r[2] * 2, r[3] * 2)
|
||||
# Operate on just the ROI of the detected face
|
||||
n = Normalization(roi=wider_rect)
|
||||
|
||||
else:
|
||||
# marks is a list of ((x, y, w, h), score, keypoints) tuples
|
||||
marks = face_landmarks.predict([n(img)])
|
||||
|
||||
# No faces detected, reset the tracker.
|
||||
if not marks:
|
||||
n = None
|
||||
continue
|
||||
|
||||
# Draw bounding boxes around the detected faces and keypoints.
|
||||
for i, detections in enumerate(marks):
|
||||
for r, score, keypoints in detections:
|
||||
ml.utils.draw_predictions(img, [r], ("face",), ((0, 0, 255),), format=None)
|
||||
|
||||
# keypoints is a ndarray of shape (468, 3) where each keypoint is (x, y, z)
|
||||
ml.utils.draw_keypoints(img, keypoints, radius=0, color=(255, 0, 0))
|
||||
|
||||
# Center new_wider_rect on face for tracking
|
||||
new_wider_rect = (r[0] + (r[2] // 2) - (wider_rect[2] // 2),
|
||||
r[1] + (r[3] // 2) - (wider_rect[3] // 2),
|
||||
wider_rect[2],
|
||||
wider_rect[3])
|
||||
# Operate on just the ROI of the detected face
|
||||
n = Normalization(roi=new_wider_rect)
|
||||
|
||||
print(clock.fps(), "fps")
|
||||
@ -0,0 +1,46 @@
|
||||
# This work is licensed under the MIT license.
|
||||
# Copyright (c) 2013-2025 OpenMV LLC. All rights reserved.
|
||||
# https://github.com/openmv/openmv/blob/master/LICENSE
|
||||
#
|
||||
# TensorFlow Lite YOLO V8 Example
|
||||
#
|
||||
# This example runs a YOLO V8 person detection model.
|
||||
#
|
||||
# NOTE: This exaxmple requires an OpenMV Cam with an NPU like the AE3 or N6 to run real-time.
|
||||
|
||||
import csi
|
||||
import time
|
||||
import ml
|
||||
from ml.postprocessing.ultralytics import YoloV8
|
||||
|
||||
# Initialize the sensor.
|
||||
csi0 = csi.CSI()
|
||||
csi0.reset()
|
||||
csi0.pixformat(csi.RGB565)
|
||||
csi0.framesize(csi.VGA)
|
||||
csi0.window((400, 400))
|
||||
|
||||
# Load YOLO V8 model from ROM FS.
|
||||
model = ml.Model("/rom/yolov8n_192.tflite", postprocess=YoloV8(threshold=0.4))
|
||||
print(model)
|
||||
|
||||
# Visualization parameters.
|
||||
n = len(model.labels)
|
||||
model_class_colors = [(int(255 * i // n), int(255 * (n - i - 1) // n), 255) for i in range(n)]
|
||||
|
||||
clock = time.clock()
|
||||
while True:
|
||||
clock.tick()
|
||||
img = csi0.snapshot()
|
||||
|
||||
# boxes is a list of list per class of ((x, y, w, h), score) tuples
|
||||
boxes = model.predict([img])
|
||||
|
||||
# Draw bounding boxes around the detected objects
|
||||
for i, class_detections in enumerate(boxes):
|
||||
rects = [r for r, score in class_detections]
|
||||
labels = [model.labels[i] for j in range(len(rects))]
|
||||
colors = [model_class_colors[i] for j in range(len(rects))]
|
||||
ml.utils.draw_predictions(img, rects, labels, colors, format=None)
|
||||
|
||||
print(clock.fps(), "fps")
|
||||
@ -173,3 +173,35 @@ class HandLandmarks:
|
||||
|
||||
nms.add_bounding_box(xmin, ymin, xmax, ymax, score, left_right, keypoints=keypoints)
|
||||
return nms.get_bounding_boxes(threshold=self.nms_threshold, sigma=self.nms_sigma)
|
||||
|
||||
|
||||
class FaceLandmarks:
|
||||
def __init__(self, threshold=0.6, nms_threshold=0.1, nms_sigma=0.1):
|
||||
self.threshold = threshold
|
||||
self.nms_threshold = nms_threshold
|
||||
self.nms_sigma = nms_sigma
|
||||
|
||||
def __call__(self, model, inputs, outputs):
|
||||
ib, ih, iw, ic = model.input_shape[0]
|
||||
nms = NMS(iw, ih, inputs[0].roi)
|
||||
|
||||
score = sigmoid(outputs[1][0, 0, 0, 0])
|
||||
if score < self.threshold:
|
||||
return _NO_DETECTION
|
||||
|
||||
cords = outputs[0][0, 0, 0, :]
|
||||
|
||||
# Get the keypoint information
|
||||
keypoints = np.empty((len(cords) // 3, 3))
|
||||
keypoints[:, 0] = cords[0::3]
|
||||
keypoints[:, 1] = cords[1::3]
|
||||
keypoints[:, 2] = cords[2::3]
|
||||
|
||||
# Get bounding box information
|
||||
xmin = np.min(keypoints[:, 0])
|
||||
ymin = np.min(keypoints[:, 1])
|
||||
xmax = np.max(keypoints[:, 0])
|
||||
ymax = np.max(keypoints[:, 1])
|
||||
|
||||
nms.add_bounding_box(xmin, ymin, xmax, ymax, score, 0, keypoints=keypoints)
|
||||
return nms.get_bounding_boxes(threshold=self.nms_threshold, sigma=self.nms_sigma)
|
||||
|
||||
@ -8,7 +8,7 @@ def unittest(data_path, temp_path):
|
||||
and lines[0][0:] == (24, 74, 56, 74, 32, 18, 90, 74)
|
||||
and lines[1][0:] == (54, 38, 26, 38, 28, 13, 90, 38)
|
||||
and lines[2][0:] == (104, 70, 114, 76, 12, 2, 121, 6)
|
||||
and lines[3][0:] == (109, 37, 100, 46, 13, 14, 45, 103)
|
||||
and lines[4][0:] == (135, 44, 128, 37, 10, 1, 135, -64)
|
||||
and lines[5][0:] == (129, 73, 137, 64, 12, 8, 42, 145)
|
||||
and lines[3][0:] == (139, 51, 133, 41, 12, 2, 149, -93)
|
||||
and lines[4][0:] == (109, 37, 100, 46, 13, 14, 45, 103)
|
||||
and lines[5][0:] == (129, 73, 137, 64, 12, 6, 42, 145)
|
||||
)
|
||||
|
||||
Loading…
Reference in New Issue
Block a user