open cv binding for c++ <> c [closed]

asked 2018-05-28 06:12:10 -0500

holger gravatar image

Hello, i have a stupdid question as i really new to c++ / c development. I am doing it now since 2 days. I managed to pass the class cv::Mat around from one c++ dll to another - great.

Now i have a c dll which expects type CvMat. From my understanding this is the c representation of the cv::Mat class. Are these two object compatible to each other - can i convert the c++ cv::Mat to a c CvMat object? I have the memory adress of the CMat object.

Hmm i hope this makes any sense. Any help on this is highly welcome.

Thank you + Greetings, Holger

edit retag flag offensive reopen merge delete

Closed for the following reason the question is answered, right answer was accepted by holger
close date 2018-05-28 07:57:56.865546

Comments

AVOID anything written in opencv's c-api. it's dead, no more maintained since 2010, and may be gone in a few weeks

berak gravatar imageberak ( 2018-05-28 06:19:35 -0500 )edit

Oh well the code base i am dealing with is using the c CvMat class, sadly. Any hope for me to get the c++ open cv lib with the c open cv lib working together?

If not i would need to port the code - ouch. If i get it right - i could write a c++ code expecting of type cv:Mat and then calling the c code?

holger gravatar imageholger ( 2018-05-28 06:36:43 -0500 )edit

there are conversion functions but you have to be VERY careful about data ownership, releasing / allocating c-structures. not at all suitable for a beginner !

if that was written in c, it's probably stone-age. (or written by a moron..).

again, rather avoid or replace it, or it will seep into your code.

berak gravatar imageberak ( 2018-05-28 06:45:06 -0500 )edit

find an alternative to that codebase, which is better maintained. anything else will be a waste of time

berak gravatar imageberak ( 2018-05-28 06:46:27 -0500 )edit

...if that was written in c, it's probably stone-age. (or written by a moron..)...

Well that guy is a chaotic guy imho - https://pjreddie.com/ But hes also good, from an algorithmic point of view. And i found nothing which could compare with the performance on cuda. Not tensorflow, not deeplearning4j or any other lib i tried out.

That the thing about darknet yolo - its poorly written and hard to embed in your app but has best performance for interference. Maybe i write my own mat class for passing data around. I am already at the point on which i dont care anymore - only worrying about code maintanance - feeling like 1970.

Anyway - Thank you for you help - this make things a bit more clear for me.

holger gravatar imageholger ( 2018-05-28 07:51:02 -0500 )edit

oh, you can be a genius and a moron at the same time, no problem ;)

and with darknet: you can build that without using opencv, and later write your own c++ wrappers around the io parts. that should be much easier (or at least cleaner), than using opencv's deprecated IplImage* things.

berak gravatar imageberak ( 2018-05-28 08:03:25 -0500 )edit

Yes you are right on both: 1) the moron <> genius thing (haha) and the 2) custom wrapper around the io classes darknet uses. And yes darknet yolo uses IplImage/CvMat for loading the image.

So instead of trying old style open cv classes and try to pass them around- i agree its easier to pass the new style classes (Mat or custom class ) to a c++ wrapper which will convert them into the c type and do the final call(hope this makes sense - my head say yes). The open cv layer on darknet is very very thing anyway. As you already mentioned you can get it even working without open cv.

Thx for you help / comments - helps me getting through this stuff and keeping my sanity XD.

holger gravatar imageholger ( 2018-05-28 08:20:02 -0500 )edit