I'm porting a ComputerVision project to OpenFrameworks right now and part of it is emulating some small parts of a library, for which I'm writing my own, much more lightweight helper class.
I have Vectors and Matrices for which I use the OpenCV classes cv::Vec
and cv::Matx
. They're simple containers with little functionality, but that's fine for the most part.
The function I try to mock is a slice function. Basically take a row of a Matrix and return a Vector, or take a subset of a vector and return that smaller vector. Right now I have something like this:
template<typename Precision, int Start, int Length, int X>
cv::Vec<Precision, Length> slice(cv::Vec<Precision, X> v)
{
assert(Start >= 0);
assert((Start+Length) <= X);
cv::Vec<Precision, Length> temp;
for (int i = 0; i < Length; i++)
temp[i] = v[Start+i];
return temp;
}
And I would use it like this:
cv::Vec<double, 3> newVector = ImpUtil::slice<double, 3, 3, VectorLength>(vector);
cv::Vec
does not have a member telling your long it is, so I have to pass the length over anyway right now. This is one reason why I plan to write my own class for this at some point.
The problem is that I'm using a template function that uses a template class. The int X
/VectorLength
part of the whole function is purely for the class however, and I was wondering if I could drop it somehow (and yes, this would mean dropping the 'assert' for now). The function should work with vectors of any length and besides the assert (which I may get from the vector at some point) it has no use within the function.