ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

What is your use case?

The image.ptr<float>(i) gives you a pointer to the first element (element at position zero) in the i'th row.

The call Di[j] gives you a read/write reference to the element j positions "behind" where Di is pointing.

Basically this is how element access in OpenCV could be done with pointers. However, OpenCV2 provides you more convienient way to access your elements such as the cv::Mat::at<T>() method (slow but convenient if you just need to modifiy a couple of pixels) or the cv::MatIterator<T> (the proper way to iterate all elements of your matrix)...

See OpenCV Doc:

http://docs.opencv.org/modules/core/doc/basic_structures.html?highlight=mat%3A%3Aptr#template%3Ctypename%20_Tp%3E%20_Tp*%20Mat::ptr%28int%20i0%29

http://docs.opencv.org/modules/core/doc/basic_structures.html?highlight=mat%3A%3Aat#template%3Ctypename%20T%3E%20T&%20Mat::at%28int%20i%29%20const

http://docs.opencv.org/modules/core/doc/basic_structures.html?highlight=matiterator#template%3Ctypename%20_Tp%3E%20MatIterator_%3C_Tp%3E%20Mat::begin%28%29