0

I am trying to compile a opencv program and I am getting the error

invalid initialization of reference of type ‘cv::InputArray {aka const cv::_InputArray&}’ from expression of type ‘std::vector<double, std::allocator<double> >::const_iterator 

(strangely I only get this error when building it in my Jetson Xavier. When I build it in my PC no problem arises)

The problematic code is

unordered_map<string, vector> timers;

for (auto const& timer : timers)
    {
        cout << "- " << timer.first << " : " << accumulate(timer.second.begin(), timer.second.end(), 0.0) << " seconds"<< endl;
    }

The problem is in timer.second.begin(). I think timer.second is a vector<doubles>. I don't understand where this cv::InputArray comes.

Edit

The MRE is

#include <iostream>
#include <unordered_map>

#include <opencv2/core.hpp>
#include <opencv2/imgproc.hpp>
#include <opencv2/highgui.hpp>
#include <opencv2/videoio.hpp>
#include <opencv2/video.hpp>
#include <opencv2/cudaarithm.hpp>
#include <opencv2/cudaimgproc.hpp>
#include <opencv2/cudawarping.hpp>
#include <opencv2/cudaoptflow.hpp>

using namespace cv;
using namespace cv::cuda;
using namespace std;

int main( int argc, const char** argv )
{

unordered_map<string, vector<double>> timers;

timers["one"].push_back(10001.00);
timers["two"].push_back(20002.00);
timers["three"].push_back(30003.00);

for (auto const& timer : timers)
    {
    cout << "- " << timer.first << " : " << accumulate(timer.second.begin(), timer.second.end(), 0.0) << " seconds"<< endl;
    }
}
halfer
  • 19,824
  • 17
  • 99
  • 186
KansaiRobot
  • 7,564
  • 11
  • 71
  • 150
  • 1
    Can we get a [mre]? – NathanOliver May 13 '21 at 12:34
  • @NathanOliver I added the MRE as requested – KansaiRobot May 13 '21 at 12:51
  • 1
    The `accumulate` is a `cv::accumulate`, and I guess you wanted `std::accumulate`. This is because of the `using namespace cv;` etc. which is a [bad idea](https://stackoverflow.com/questions/1452721/why-is-using-namespace-std-considered-bad-practice) – Dan Mašek May 13 '21 at 12:52
  • Please don"t close this question since it is a valid question. I would like to get help learning this – KansaiRobot May 13 '21 at 12:53
  • 1
    This is now basically a dupe of [this](https://stackoverflow.com/questions/1452721/why-is-using-namespace-std-considered-bad-practice). Basically, with `using namespace std;` and `using namespace cv;` your pulling in functions named `accumulate` from each namespace. Get rid of the using statements and start qualifying your function calls, ie `std::accumulate(timer.second.begin(), timer.second.end(), 0.0)` – NathanOliver May 13 '21 at 12:53
  • @DanMašek Interesting. I will try that now. The strange thing is that this error does not happen in my PC, only in the ARM platform – KansaiRobot May 13 '21 at 12:54
  • Also, if you want to use `std::accumulate`, you need to include `algorithm` as that is where the standard algorithms live. – NathanOliver May 13 '21 at 12:55
  • so there is a `cv::acumulate` too? Does it behaves differently? – KansaiRobot May 13 '21 at 12:56
  • Yes, and yes: https://docs.opencv.org/4.5.2/d7/df3/group__imgproc__motion.html#ga1a567a79901513811ff3b9976923b199 – Dan Mašek May 13 '21 at 12:59

0 Answers0