I have a slightly specific question. I am using C/C++ with OpenCV. My aim to store detected rectangles in a list/array style structure. However, the length is variable for every frame (iteration).
What should I use to store this info? I thought of Linked Lists, however, they are slow to traverse and also if the number of nodes decrease, I will have to manually delete the extra nodes which would take up even more processor time. I discarded Arrays as they are not very flexible in terms of their length. I can do dynamic arrays with malloc but even with that I think I will need to specify the maximum number of elements.
feel free to correct me if i’m wrong somewhere. Also please do share your views and let me know what you think is the best way to go about this?
Thanks
EDIT: I’m not restricted to C (i know i mentioned malloc). I can use C++ features as well as the rest of my program does not use any C specific functions. So do feel free to suggest me any better ways.
I would recommend you to use
std::vector. The elements in astd::vectorare guaranteed by the C++ Standard to be contiguous, just like a C array would be. This allowsstd::vectorto be the interface between C++ data structures and C functions. You can usestd::vector<T>::resizeto make sure there is space allocated before passing it to the OpenCV functions.Oh, to get a pointer to the internal storage of the vector you typically use this notation:
&rectangleCollection[0].Good luck!