Ask Your Question

Benjamin M's profile - activity

2016-09-23 04:14:57 -0600 received badge  Enthusiast
2016-09-22 07:45:00 -0600 commented question cv::Mat.forEach - how does position work?

It's not either or, it's both. I want to perform an operation for every element and I need to compare that element to it's neighbors, that's why I want the index. forEach is done in parallel (says the documentation), whereas if I would go through the Matrix via index and .at(), that wouldn't be the case. Also I think forEach + Lambda Expression looks cleaner than explicit loops.

2016-09-21 06:31:36 -0600 received badge  Editor (source)
2016-09-20 04:21:52 -0600 asked a question cv::Mat.forEach - how does position work?

AFAIK the signature of the function param of Mat.forEach is:

void (*)(const T value, const *int pos);

EDIT: Well, according to core/utility.hpp it's more like: (which should go into the documentation, IMHO)

//     (_Tp&, const int*)   <- multidimential
//  or (_Tp&, void*)        <- in case of you don't need current idx.

Now, I'm not sure what the pos argument is and I don't think the documentation is absolutely clear on that. From the documentation, it almost looks like this is the channel of the current element?

I have now used it in my project for a CV_64FC1 Matrix and pos[1] is the current collumn. Since pos[0] is always zero and this is a single row Matrix, I guess it's pos[dimension]?

So when I want to use it with m.at<t>() I need to calculate the index from the pos elments? I would like to better understand this, then I could make a pull request with a documentation improvement. I have looked at the code, but I'm not sure I understand the multidimensional case correctly.

2016-05-30 07:24:38 -0600 received badge  Scholar (source)
2016-05-30 07:24:36 -0600 received badge  Supporter (source)
2016-05-30 07:24:29 -0600 commented answer cv::format using locale decimal mark

TY; Looked at opencv/modules/core/src/out.cpp For sprintf, there is no other way than setting the whole applications locale, which isn't safe. I have some time in a few weeks, maybe I can do it then. I'd love to contribute. Will only have to see, whether locale awerness isn't needed for some cases (e.g., default and CSV). Maybe it should be the default, with changing the format for the pogramming language formats only.

2016-05-30 06:05:11 -0600 received badge  Student (source)
2016-05-29 09:31:43 -0600 asked a question cv::format using locale decimal mark

I'm using OpenCV 3.1 from C++ and I want to store my matrix in Python format:

errfile.open("errs.txt");
errfile << cv::format(errs, cv::Formatter::FMT_PYTHON) << std::endl;
errfile.close();

(errs is of type cv::Mat)

But the output is:

[[1271892,725376768, 65449,68687547074, 9149,382398115458, ... ]]

It seems like OpenCV is using my systems locale number format, using a comma as decimal separator. But Python expects a dot.

Although doing:

errfile << 6.66f << std::endl;

does print "6.66" not "6,66". Using errfile.embue to set the locale for the steam doesn't help either. I have to set the global locale:

std::setlocale(LC_NUMERIC, "en_US.UTF-8");

I don't think it makes sense to apply the locale here, since the format should be the python code format. Is this a bug I should report?

Additional Info: My system uses en_US locale for language, but German (de_AT) locale for numbers.