Creating a class in native module

Discussion about programs, libraries and tools that work with MicroPython. Mostly these are provided by a third party.
Target audience: All users and developers of MicroPython.
Post Reply
tecdroid
Posts: 27
Joined: Thu Apr 08, 2021 6:22 am

Creating a class in native module

Post by tecdroid » Thu Apr 08, 2021 6:40 am

Hi there,

i want to create a simple image class as native module which is capable of performing image filtering (sobel operators, etc.) and transformation(eg. hough, color to gray, etc.) Both are basically a function which returns a new image.
imagine the api like

Code: Select all

image = Image(camera.capture(), 320, 240, Image.RGB565)
gray = image.transform(Image.grayscale)
edges = gray.filter(Image.sobel3)
in short, it should be possible to do this:

Code: Select all

edges = Image(camera.capture(), 320, 240, Image.RGB565).transform(Image.grayscale).filter(Image.sobel3)
To me it makes sense to implement this as image class but since native module development isn't well documented (sadly, source code isn't, too - no offense), I don't know how to start..

My image should look at least like this in c:

Code: Select all

typedef struct s_image_t {
   unsigned int width; 
   unsigned int height;
   unsigned int type;
   char const *buffer;
}
I've seen modframebuffer which has basically a cool design (lookup table for called function by frame format etc.) but it's a slightly heavy example to find out what i really have to do.. and it's no native module and I don't know what exactly has to be changed betweent both..

Can someone give me some hints here?

Post Reply