Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to print vector-values in OpenCV

Tags:

c++

opencv

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;
like image 245
Taketo Sano Avatar asked Jun 01 '13 03:06

Taketo Sano


People also ask

How to print values of vector?

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.

How do I print a vector iterator?

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() .

What is CV_32F?

CV_32F : 4-byte floating point ( float ).

How do I print a vector backwards?

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.


1 Answers

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.

like image 57
alrikai Avatar answered Oct 12 '22 15:10

alrikai