Help on using C modules

Hi all,

for our machine learning project I’m following the natmod/features2 example to create a C module that can be used with micropython. I would like to pass a frame buffer containing the actual data to a C function:

from cnn import cnn


img = sensor.snapshot()

The C function is:

STATIC mp_obj_t cnn(mp_obj_fun_bc_t *self, size_t n_args, size_t n_kw, mp_obj_t *args) {

I have to questions:

  1. Running the code above leads to: “TypeError: function doesn’t take keyword arguments.” There is no keyword argument?
  2. I know img is not the frame buffer. How can I get it?

Thx in advance!

Hi, you should really look at the very numerous code examples all over in the firmware on how this is done and the few posts on the forum where we explain this.

For your above example, I can’t tell exactly what your error is… But, if you look at our code base you’ll see how to pass arguments correctly.

The image pixels point to the frame buffer, and if you read the code you’ll find many examples for what you want to to do. Just copy any function and add your code or replace an existing function.

Thx guys I’ll try it.