yooo123
yooo123

Reputation: 67

using opencv with c++ and c

I want to process a video using opencv and c++ and the speed of execution really matters. But I saw something that might be a problem, for example canny function for C++ is defined as

void Canny(InputArray image, OutputArray edges, double threshold1, double threshold2, int apertureSize=3, bool L2gradient=false )

and the equivalent in C is defined as

void cvCanny(const CvArr* image, CvArr* edges, double threshold1, double threshold2, int aperture_size=3 )

Obviously, if I use C++, the passed to the function image will be copied every time, that makes at least 24 copies per second since I don't use only that function. If I use C function, I will not run into that problem, because no copies will be made. Is there a way to combine for example IplImage and Mat and how much will it cost me when I cast IplImage to Mat after that? And generally, will it be a good idea to use IplImage ?

Upvotes: 1

Views: 572

Answers (1)

PeterT
PeterT

Reputation: 8284

You might be misinterpreting what the C++ code does. If you take a look at the documentation

You will see that InputArray is a const&

typedef const _InputArray& InputArray;

where InputArray is a class that can be constructed from Mat, Mat_<T>, Matx<T, m, n>, std::vector<T>, std::vector<std::vector<T> >, std::vector<Mat>, std::vector<Mat<T> >, UMat, std::vector<UMat> or double. It can also be constructed from a matrix expression.

Upvotes: 4

Related Questions