Ask Your Question
5

Which one is preferred to use? C or C++

asked 2012-12-22 04:00:52 -0600

vanangamudi gravatar image

updated 2012-12-22 18:30:15 -0600

SR gravatar image

I'm a C programmer. I prefer C over C++ most of the time but I have seen benchmarks of OpenCV performing well when C++ is used. Why should I choose C++ and why is it faster than C? When I say C++ is faster than C, the scope is confined to OpenCV. Do the C portions of OpenCV become deprecated??

edit retag flag offensive close merge delete

3 answers

Sort by ยป oldest newest most voted
4

answered 2012-12-22 11:12:07 -0600

updated 2013-01-01 15:35:06 -0600

SR gravatar image

C API was present in OpenCV 1.x. Now it is supported for backward compatibility only. It is deprecated and may be removed in the future.

edit flag offensive delete link more

Comments

how soon can we expect for C interface to disappear. coz I love C for its simplicity, which C++ ultimately lacks

vanangamudi gravatar imagevanangamudi ( 2012-12-22 12:31:56 -0600 )edit

c is simplistic but not simplicity, it lacks too many abstraction power to create clean codes like c++.The opencv api of c++ are much more cleaner and easier to use

stereomatching gravatar imagestereomatching ( 2013-10-27 05:28:43 -0600 )edit

the only issue is that C is still much more compatible with other high-level languages, many support only interfacing with C and not C++. it would be nice to have an automatically generated C API, the same way that the Python, Java and MATLAB bindings are generated.

glopes gravatar imageglopes ( 2014-08-31 07:42:00 -0600 )edit
3

answered 2012-12-25 03:38:04 -0600

rics gravatar image

There is a similar question - including python - on stackoverflow with similar conclusion to Alexander's.

May be the benchmark what you mention is Shervin Emami's. To summarize he has created a speed comparison of C and C++ interface using different OpenCV versions. His conclusion is that the new C interface is slower than both the old C and the new C++. Moreover the new C++ interface is almost as fast as the old C interface. The slowness of the new C interface can be a consequence of the deprication, in other words the aim of the development is backward compatibility only and not performance.

So far I have used the C interface but as I see from the examples, the C++ part is more user friendly and cleaner.

Anyway the second edition of the really useful book, Learning OpenCV has just come out. As the subtitle (Computer Vision in C++ with the OpenCV Library) suggests it deals with C++ mainly.

edit flag offensive delete link more
3

answered 2012-12-22 07:10:58 -0600

SR gravatar image

updated 2012-12-22 18:27:58 -0600

The C interface of OpenCV is nowadays a wrapper around the C++ core and calls these functions internally. However, there are some old functions that still use C code only but this is not standard.

Thus, in many cases there is little difference in calling the C vs. the C++ version of a certain function.

edit flag offensive delete link more

Comments

what does it has to do with C++ performance? is the C++ codes are getting optimized, and C portions are left to die?

vanangamudi gravatar imagevanangamudi ( 2012-12-22 12:30:51 -0600 )edit

Question Tools

Stats

Asked: 2012-12-22 04:00:52 -0600

Seen: 6,802 times

Last updated: Jan 01 '13