UrielCh / opencv-sandbox

sandbox to prototype a new N-API binding for openCV
5 stars 0 forks source link

Typings for Algorithm are borken #11

Open piercus opened 1 year ago

piercus commented 1 year ago

realted to :

After 7da7678c82a142c7903c91556ab29717aa8887a9

Actual

    class Algorithm{
        constructor();
        clear(): null;
        write(fs: FileStorage): null;fs: FileStorage, name: String): null;
        read(fn: FileNode): null;
        empty(): boolean;
        save(filename: String): null;
        getDefaultName(): String;
    }

Expected

To be clarified :

    class Algorithm{
        constructor();
        clear(): null;
        write(fs: FileStorage): null;
        read(fn: FileNode): null;
        empty(): boolean;
        save(filename: String): null;
        getDefaultName(): String;
    }
UrielCh commented 1 year ago

As I always say: code never lies:

I'm checking the function names: static Napi::Value jsopencv_cv_Algorithm_write(const Napi::CallbackInfo &info) from jsopencv_generated_types_content.h

    Napi::Value* jsobj_fs = NULL;
    Ptr<cv::FileStorage> fs;
    const char* keywords[] = { "fs", NULL };
    if (JsArg_ParseTupleAndKeywords(info, "O:Algorithm.write", (char**)keywords, &jsobj_fs) &&
        jsopencv_to_safe(jsobj_fs, fs, ArgInfo("fs", 0))) {
        ERRWRAP2_NAPI(env, _self_->write(*fs));
        return env.Null();;
    }```
this call is: Algorithm.write(fs: FileStorage): null;
next down the lines:
```c++
    Napi::Value* jsobj_fs = NULL;
    Ptr<cv::FileStorage> fs;
    Napi::Value* jsobj_name = NULL;
    String name;

    const char* keywords[] = { "fs", "name", NULL };
    if (JsArg_ParseTupleAndKeywords(info, "OO:Algorithm.write", (char**)keywords, &jsobj_fs, &jsobj_name) &&
        jsopencv_to_safe(jsobj_fs, fs, ArgInfo("fs", 0)) &&
        jsopencv_to_safe(jsobj_name, name, ArgInfo("name", 0)))
    {
        ERRWRAP2_NAPI(env, _self_->write(*fs, name));
        return env.Null();;
    }

or: Algorithm.write(fs: FileStorage, name: string): null;

so the expected interface looks like:


class Algorithm{
...
  write(fs: FileStorage): null;
  write(fs: FileStorage, name: string): null;
...
}

Even if the current implementation of JsArg_ParseTupleAndKeywords will not offer the correct behavior, I will fix that user's small case.

With the current version the second parameter will be ignore, but it easy to fix.
UrielCh commented 1 year ago

To answer your question FileStorage will stay as FileStorage, and so on for FileNode

to check that open the current jsopencv_generated_types_content.h and look for the section starting with:

//================================================================================
// FileStorage (Generic)
//================================================================================

and

//================================================================================
// FileNode (Generic)
//================================================================================

as I told you before, I prefer to generate a pair or file for each class to improve the development experience and merge them all for the production stage.

A sample class implementation is available in cc-obj/AKAZE.cpp and cc-obj/AKAZE.h in the branch named class.

piercus commented 1 year ago

@UrielCh typings should now be ok in the typings branch, please review #10

Create/constructor

The create/constructor convention in opencv is quite obscure for me

I found all versions of it, examples are :

No constructor constructor
no Create Abstract Class like DenseOpticalFlow BOWKMeansTrainer
create DescriptorMatcher or AKAZE BFMatcher

I'm not sure if those behavior can be the same is js, for now i consider it will be the same. How will new AKAZE() behave ?