OpenCV bindings for D

poliklosio via Digitalmars-d digitalmars-d at puremagic.com
Mon Mar 21 13:52:30 PDT 2016


On Monday, 21 March 2016 at 19:16:16 UTC, wobbles wrote:
> On Monday, 21 March 2016 at 16:01:59 UTC, Guillaume Piolat 
> wrote:
>> On Monday, 21 March 2016 at 15:45:36 UTC, wobbles wrote:
>>> Hi Folks,
>>>
>>> I have a project in mind that I'd like to run on my new 
>>> Raspberry Pi 3.
>>> Essentially a security camera that will only record when it 
>>> detects changes between frames.
>>> Now, this is already a solved problem I believe, however in 
>>> the interest of learning I want to do it myself.
>>>
>>> Ideally, I'd compare two images using the OpenCV library, and 
>>> ideally I'd do that from D code.
>>>
>>> However, there exists no OpenCV binding for D that I can 
>>> find. Is there a technical reason for this?
>>>
>>> I understand the OpenCV C api is quite old and dated, and 
>>> it's recommended to use the C++ one as a result.
>>> On that, where is C++ / D linkage at?
>>>
>>> I know very little about linking the two, but it's something 
>>> I'd like to learn more about and see this as an opportunity 
>>> for that - before I sink a load of time into it, however, 
>>> it'd be good to know if it's even feasibly possible to do so.
>>>
>>> Thanks!
>>
>> It's quite easy to write bindings for libraries that have a C 
>> interface (ie most), if only a bit boring.
>
> That's the thing, it doesn't have a C interface (or more 
> correctly, it's modern versions don't have a C interface as it 
> has been deprecated since I think version 2.4. OpenCV is at 3.4 
> now).
>
> I was wondering if there was any difficulties interfacing D to 
> the C++ API?

I don't have much experience with D, but I have with OpenCV. The 
key class in OpenCV is cv::Mat, which is used to represent images 
as arguments and return values of almost every OpenCV algorithm. 
It is kind of a handle class - it optionally owns image data and 
manages its lifetime through reference counting and RAII. The 
sheer number of constructors is a bit overwhelming.
See
http://docs.opencv.org/2.4/modules/core/doc/basic_structures.html#mat-mat

I would be interested to see what D experts would say about 
interfacing such class.
My guess would be that you may have trouble exposing this 
directly to the D side in a useful way. You may have to write 
some helpers or even a wrapper on the C++ side.


More information about the Digitalmars-d mailing list