I'm new to OpenCV.
Please tell me how to print these objects using std::cout
.
std::vector<std::vector<cv::Point>> contours;
std::vector<cv::Vec4i> hierarchy;
In the for loop, size of vector is calculated for the maximum number of iterations of loop and using at(), the elements are printed. for(int i=0; i < a. size(); i++) std::cout << a.at(i) << ' '; In the main() function, the elements of vector are passed to print them.
Using Iterator We can also use the iterators to print a vector. The idea is to use the constant iterators, returned by cbegin() and cend() , since we're not modifying the vector's contents inside the loop. Before C++11, we can use begin() and end() .
CV_32F : 4-byte floating point ( float ).
To print all elements of a vector in reverse order, we can use two functions 1) vector::begin() and vector::end() functions. vector::begin() function returns an iterator pointing to the first elements of the vector. vector::end() function returns an iterator point to past-the-end element of the vector.
well, one way to do it would be:
for (auto vec : contours)
for (auto v : vec)
std::cout << v << std::endl;
and then for hierarchy:
for (auto vec : hierarchy)
std::cout << vec << std::endl;
The key point is that the OpenCV data structures overload the <<
operator, so you can use them directly with cout
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With