Help on using C modules

Discussion related to "under the hood" OpenMV topics.
ciVic
Posts: 2
Joined: Sat Feb 22, 2020 6:51 am

Help on using C modules

Postby ciVic » Sat Feb 22, 2020 7:01 am

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:

Code: Select all

from cnn import cnn

...

img = sensor.snapshot()
cnn(img)
The C function is:

Code: Select all

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!
User avatar
kwagyeman
Posts: 4271
Joined: Sun May 24, 2015 2:10 pm

Re: Help on using C modules

Postby kwagyeman » Sat Feb 22, 2020 11:33 am

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.
Nyamekye,
User avatar
iabdalkader
Posts: 1193
Joined: Sun May 24, 2015 3:53 pm

Re: Help on using C modules

Postby iabdalkader » Sat Feb 22, 2020 11:54 am

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.
ciVic
Posts: 2
Joined: Sat Feb 22, 2020 6:51 am

Re: Help on using C modules

Postby ciVic » Sun Feb 23, 2020 12:12 pm

Thx guys I'll try it.

Return to “Technical Discussion”

Who is online

Users browsing this forum: No registered users and 7 guests