Hi Ed,

yes, I have seen Dima's project. It is written for OpenCV v2, which is
quite old and the API changed significantly. Since v4, they dropped the
C interface which complicates matters since there are no direct PDL
bindings to C++, unfortunately.

The problem I try to solve at the moment is to link two pieces of our
code-base, one is a PDL:Graphics:Prima application, the other is
tracking, which is only a tiny subset of OpenCV's capabilities.

I've nailed the problem, I think. I was using Inline::Pdlpp which,
apparently ignored my typemap file for OtherPars.

Thus I work directly with a .pd and MakeMaker, it is recognised and code
compiles. So, progress, yay! Now I'm struggling with passing around the
object pointer. It never makes it to perl and back, unfortunately.

I have created this repo here, please take a look.

https://github.com/fantasma13/PDL-OCV

Please take a look.

Ingo

On 3/4/2022 2:39 PM, Ed . wrote:

Hi Ingo (and Craig!),

May I suggest this be tracked on
https://github.com/PDLPorters/pdl/issues/362, which is presciently an
issue (prompted by the PDLPorters GitHub wiki) prompting the creation
of a PDL interface to OpenCV?

You will see it links to Dima’s prototype
https://github.com/dkogan/PDL-OpenCV, which will provide an excellent
starting-point.

You refer to Inline::C::Struct – I assume you mean
https://metacpan.org/pod/Inline::Struct, now maintained by me. That
would probably indeed make a good entity to pass around, though I
would expect you’d need to make a typemap entry. The “subset” you
refer to from the 2017 paper is simply whatever you choose, as
GenericTypes; recent PDL supports all the primitive C types, from
signed/unsigned char up to complex long double.

Using the technique Craig pointed to is the PDL GSL bindings, see
https://github.com/PDLPorters/pdl/tree/master/Libtmp/GSL/INTERP for a
complete example.

However you decide to proceed, I would urge you to indeed share your
code, possibly on GitHub. It might even make sense for you to fork
Dima’s repo and start from there? Please put the URL and any code so
far on issue #362 :-)

Best regards,

Ed

*From: *Ingo Schmid <mailto:ingo...@gmx.at>
*Sent: *03 March 2022 17:40
*To: *Craig DeForest <mailto:defor...@boulder.swri.edu>
*Cc: *pdl-devel <mailto:pdl-devel@lists.sourceforge.net>; perldl
<mailto:pdl-gene...@lists.sourceforge.net>
*Subject: *Re: [Pdl-devel] [Pdl-general] PP and c++

Hi

would you be so kind of pointing me to a simple working example? My
references look like memory addresses but seem to point to nowhere.

Ingo

On 3/3/2022 3:05 PM, Craig DeForest wrote:

    When I had to do things like that, I would generally cast the
    pointer to an IV and pass it around as an IV ref on the Perl side,
    then manually unwrap it when needed on the C side.  This is the
    approach used by PDL itself.



        On Mar 3, 2022, at 7:55 AM, Ingo Schmid <ingo...@gmx.at> wrote:

        Hi,

        I'm working on PDL bindings (Inline:::Pdlpp) to the OpenCV
        (v4.5) tracking class. I have created a wrapper (see header
        below).

        I would now need to persistently store pointers to MatWrapper
        and TrackerWrapper - which are containers (structs) of the Mat
        and Tracker objects.

        At the moment, I have them declared in the auto_include code
        (struct TrackerWrapper * tw;). This would then prevent me from
        using multiple trackers. I therefore am looking of passing the
        pointer back and forth.

        I tried using

        OtherPars => 'TrackerWrapper * tw, MatWrapper * mw', ..

        this and a typemap file, it is referenced in the TYPEMAPS
        field. However, this results in unknown c type error
        TrackerWrapper when parsing the pd file. I think it is never
        used, following what is said here
        https://arxiv.org/pdf/1702.07753.pdf. Which subset of c-types
        are allowed?

        Is the approach reasonable and I am doing something wrong?
        What is the way to make a c struct persistent and accessible
        with perl/pp?

        There's Inline-C-Struct, does that work with pdl and if so, how?

        Any help is appreciated. I can share the full code (so far)
        upon request but it is work in progress.

        Ingo

        typemap:

        TYPEMAP

        TrackerWrapper  T_PTR

        MatWrapper  T_PTR

        tracker_wrapper.h:


        #ifdef __cplusplus
        extern "C" {
        #endif


        //
        struct cvType {
            int u8c3 ;
                int u8c1 ;
                int f32c3 ;
                int f32c1 ;
        } cvT;

        int  tw_init();
        //struct cvType cvT;
        typedef struct TrackerWrapper TrackerWrapper;
        struct TrackerWrapper * newTracker (int tracker_type);
        int  deleteTracker (struct TrackerWrapper *);

        struct bBox{
            int x; int y; int width; int height;
        };

        typedef struct MatWrapper MatWrapper;
        struct MatWrapper * newMat (const int width, const int height,
        const int type, void * data);
        void * getData (struct MatWrapper * Mat);
        int setData (struct MatWrapper * Mat, const int type, void *
        data);

        int init_tracker(struct TrackerWrapper * Tr, struct MatWrapper
        * frame, const struct bBox * box );
        int update_tracker(struct TrackerWrapper *, struct MatWrapper
        *, struct bBox * box);
        int  show_tracker (struct MatWrapper * frame, struct bBox * roi) ;

        #ifdef __cplusplus
        }
        #endif



        _______________________________________________
        pdl-general mailing list
        pdl-gene...@lists.sourceforge.net
        https://lists.sourceforge.net/lists/listinfo/pdl-general

_______________________________________________
pdl-devel mailing list
pdl-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/pdl-devel

Reply via email to