Ask Your Question
0

Is it possible to get a labeled image from a binary image using OpenCV with an in-built C API

asked 2016-06-02 04:24:46 -0500

starlord_1 gravatar image

I am aware of the function connectedComponents in OpenCV library which can give me labeled image from a binary image.

Since i want to write my code purely in C and without any wrappers, is it possible to achieve the same using OpenCV?

I am also aware of functions such as findContours and floodFill, but i am not able to achieve the proper labeling of my binary image which is provided by connectedComponents.

edit retag flag offensive close merge delete

2 answers

Sort by ยป oldest newest most voted
3

answered 2016-06-02 05:52:04 -0500

essamzaky gravatar image

updated 2016-06-02 05:54:05 -0500

alalek is one of OpenCV Team says in one response for a bug the following c API Bug:

"OpenCV is a C++ library now and actively uses C++ features, like exceptions and so on. Direct support for C compilers has been dropped some years ago, so you should not create C applications using OpenCV. "C-API" is not supported and should be removed totally (but we have a lack of resources to port this legacy C code to C++, so some of this code still exists right now). Also huge part of fresh OpenCV functionality is missing in "C-API". There is no plan to fix this in OpenCV directly. If you want to use OpenCV from C application code you need to find some implementation of C bindings which wraps OpenCV C++ functionality (al least these bindings should catch exceptions and return exit codes for user application)."

i think if you want to build c application using openCV dierectly you will lose the support from OpenCV Team , they will advice you to port to c++.

The c wrapper is my the advice for you , may be others have another advice for you.

edit flag offensive delete link more

Comments

Thank you for answering

starlord_1 gravatar imagestarlord_1 ( 2016-06-02 06:45:41 -0500 )edit
2

answered 2016-06-02 06:25:34 -0500

berak gravatar image

updated 2016-06-02 10:01:37 -0500

... purely in C and without any wrappers, is it possible ?

No, it isnt. doing your own C wrapper might be your best bet:

// my_api.h (w/o any opencv headers)

extern "C" {
    int funny( void *there_be_pixels, int w, int h, int type );
}

// my.cpp (you'll have to compile it as c++, seperately from your other C code)

#include "opencv2/opencv.hpp"
#include "my_api.h"

int funny(void *there_be_pixels, int w, int h, int type)
{
    cv::Mat m(h, w, type, (char*)there_be_pixels);
    // do your c++ processing
}

what you should not try is, to use the legacy IplImage based api - i't s dead, does not give you a real 'watershed', also you're only writing more unwanted legecay code this way.

edit flag offensive delete link more

Comments

Thank you for answering. I have already implemented the wrapper using iplImage. But I wanted to know if there is any other way to get only C based solution to this.

starlord_1 gravatar imagestarlord_1 ( 2016-06-02 06:48:05 -0500 )edit

"I have already implemented the wrapper using iplImage." - that's exactly the wrong thing to do.

berak gravatar imageberak ( 2016-06-02 06:53:27 -0500 )edit

but we're preaching deaf ears there.

berak gravatar imageberak ( 2016-06-02 06:56:50 -0500 )edit

So is there a way to implement the same without having any c++ files in my workspace? Because that is precisely the thing i want to avoid.

starlord_1 gravatar imagestarlord_1 ( 2016-06-02 07:03:46 -0500 )edit

you'll have to compile it seperately. (maybe even make a library of it)

berak gravatar imageberak ( 2016-06-02 07:14:36 -0500 )edit

thank you.

starlord_1 gravatar imagestarlord_1 ( 2016-06-02 07:17:25 -0500 )edit
Login/Signup to Answer

Question Tools

1 follower

Stats

Asked: 2016-06-02 04:23:46 -0500

Seen: 220 times

Last updated: Jun 02 '16