OpenCV: Is it a bad idea to use C++ classes with the C API?
For example I have a method that takes:
(CvRect rect, CvMemStorage* storage)
And another:
(CvSubdiv2D* subdiv, 开发者_如何学GoCvPoint2D32f pt)
So I was thinking of using the cv::Rect
class instead of CvRect
, and the cv::Point2d
instead of CvPoint2D32f
(though maybe using cv::Point2f
instead of cv::Point2d
would be more adequate, assuming any of this is adequate at all).
Anyway, I could create a class to encapsulate the C versions instead and behave accordingly I guess, but I'm just wondering if this would be disastrous? I didn't get any compiler errors with either method, using -Wall -Wextra
.
That's not a good idea. Each interface has it's own types and many of these are not supported by the other. You will find yourself having to convert between types to be able use the C and C++ interfaces more often than you would imagine, and these task also brings a performance cost to your application.
I don't recommend mixing the interfaces together. In terms of core functionality, they were developed to support the same Image/Video processing operations. Right now I can't see a reason that justifies mixing them.
It most likely won't create any runtime diffences compared to running the thing in a C application.
So it's mostly a question of style. What you want to do is to write a couple of Wrapper functions which is completely fine.
I have done something similar with WinAPI and OpenGL in both cases replacing their point structs with basic_Point2D and basic_Point2D. System works fine in every aspect as both structs are binary compatible with the others.
精彩评论