Thread overview
OpenCV bindings for D
Mar 21, 2016
wobbles
Mar 21, 2016
Guillaume Piolat
Mar 21, 2016
wobbles
Mar 21, 2016
poliklosio
Mar 21, 2016
Suliman
March 21, 2016
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!
March 21, 2016
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.

- First check in code.dlang.org or https://github.com/D-Programming-Deimos it doesn't not already exist.

- Choose to create a static or dynamic bindings. For multiplatform a dynamic loader will be easier dependency-wise, for *nix systems static linking may be easier.

- When porting C headers, there is a few gotchas: https://p0nce.github.io/d-idioms/#Porting-from-C-gotchas

- Take inspiraton at either Deimos or Derelict to create either.
March 21, 2016
Try to look at https://github.com/ljubobratovicrelja/dcv
March 21, 2016
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?
March 21, 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.
April 04
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.
>
> [...]

this is now on: https://github.com/aferust/opencvd