Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Error when create map with pointer to function to cv

Good morning, I would like to create map with pointer function with tracking functions, i tried many solution but aren't working :/

I would like to avoid many if like :

cv::Ptr<cv::Tracker>
TestTrackingVideo::createTrackerByName(std::string &trackerType) {
  cv::Ptr<cv::Tracker> tracker;
  if (trackerType == trackerTypes[0])
    tracker = cv::TrackerBoosting::create();
  else if (trackerType == trackerTypes[1])
    tracker = cv::TrackerMIL::create();
  else if (trackerType == trackerTypes[2])
    tracker = cv::TrackerKCF::create();
  else if (trackerType == trackerTypes[3])
    tracker = cv::TrackerTLD::create();
  else if (trackerType == trackerTypes[4])
    tracker = cv::TrackerMedianFlow::create();
  else if (trackerType == trackerTypes[5])
    tracker = cv::TrackerGOTURN::create();
  else if (trackerType == trackerTypes[6])
    tracker = cv::TrackerMOSSE::create();
  else if (trackerType == trackerTypes[7])
    tracker = cv::TrackerCSRT::create();
  else {
    std::cout << "Incorrect tracker name" << std::endl;
    std::cout << "Available trackers are: " << std::endl;
    for (std::vector<std::string>::iterator it = trackerTypes.begin();
         it != trackerTypes.end(); ++it)
      std::cout << " " << *it << std::endl;
  }
  return tracker;
}

I would like to create map with pointer to function like :

  std::map<std::string, cv::Ptr<cv::Ptr<cv::Tracker>> (*)()> trackerTypes_map =
      {{"BOOSTINGS", &cv::TrackerBoosting::create},
       {"MIL", &cv::TrackerMIL::create}};

And call it :

auto &iter = this->trackerTypes_map.find(str);
if (iter == this->trackerTypes_map.end()) {
   return nullptr;
}
return (this->trackerTypes_map.second)();

When i tried to compile, i have this error :

error : could not convert '{{"BOOSTINGS", (& cv::TrackerBoosting::create)}, {"BOOSTING", (& cv::TrackerBoosting::create)}}' from '<brace-enclosed initializer list>' to 'std::map<std::__cxx11::basic_string<char>, cv::Ptr<cv::Ptr<cv::TrackerBoosting> > (*)()>'
                           {"BOOSTING", &cv::TrackerBoosting::create}};
                                                                 ^

I don't know why isn't working, is something missing ? Wrong type ?

Error when create map with pointer to function to cv

Good morning, I would like to create map with pointer function with tracking functions, i tried many solution but aren't working :/

I would like to avoid many if like :

cv::Ptr<cv::Tracker>
TestTrackingVideo::createTrackerByName(std::string &trackerType) {
  cv::Ptr<cv::Tracker> tracker;
  if (trackerType == trackerTypes[0])
    tracker = cv::TrackerBoosting::create();
  else if (trackerType == trackerTypes[1])
    tracker = cv::TrackerMIL::create();
  else if (trackerType == trackerTypes[2])
    tracker = cv::TrackerKCF::create();
  else if (trackerType == trackerTypes[3])
    tracker = cv::TrackerTLD::create();
  else if (trackerType == trackerTypes[4])
    tracker = cv::TrackerMedianFlow::create();
  else if (trackerType == trackerTypes[5])
    tracker = cv::TrackerGOTURN::create();
  else if (trackerType == trackerTypes[6])
    tracker = cv::TrackerMOSSE::create();
  else if (trackerType == trackerTypes[7])
    tracker = cv::TrackerCSRT::create();
  else {
    std::cout << "Incorrect tracker name" << std::endl;
    std::cout << "Available trackers are: " << std::endl;
    for (std::vector<std::string>::iterator it = trackerTypes.begin();
         it != trackerTypes.end(); ++it)
      std::cout << " " << *it << std::endl;
  }
  return tracker;
}

I would like to create map with pointer to function like :

  std::map<std::string, cv::Ptr<cv::Ptr<cv::Tracker>> (*)()> trackerTypes_map =
      {{"BOOSTINGS", &cv::TrackerBoosting::create},
       {"MIL", &cv::TrackerMIL::create}};

And call it :

auto &iter = this->trackerTypes_map.find(str);
if (iter == this->trackerTypes_map.end()) {
   return nullptr;
}
return (this->trackerTypes_map.second)();

When i tried to compile, i have this error :

error : could not convert '{{"BOOSTINGS", (& cv::TrackerBoosting::create)}, {"BOOSTING", (& cv::TrackerBoosting::create)}}' from '<brace-enclosed initializer list>' to 'std::map<std::__cxx11::basic_string<char>, cv::Ptr<cv::Ptr<cv::TrackerBoosting> > (*)()>'
                           {"BOOSTING", &cv::TrackerBoosting::create}};
                                                                 ^

I don't know why isn't working, is something missing ? Wrong type ?

Error when create map with pointer to function to cv

Good morning, I would like to create map with pointer function with tracking functions, i tried many solution but aren't working :/

I would like to avoid many if like :

cv::Ptr<cv::Tracker>
TestTrackingVideo::createTrackerByName(std::string &trackerType) {
  cv::Ptr<cv::Tracker> tracker;
  if (trackerType == trackerTypes[0])
    tracker = cv::TrackerBoosting::create();
  else if (trackerType == trackerTypes[1])
    tracker = cv::TrackerMIL::create();
  else if (trackerType == trackerTypes[2])
    tracker = cv::TrackerKCF::create();
  else if (trackerType == trackerTypes[3])
    tracker = cv::TrackerTLD::create();
  else if (trackerType == trackerTypes[4])
    tracker = cv::TrackerMedianFlow::create();
  else if (trackerType == trackerTypes[5])
    tracker = cv::TrackerGOTURN::create();
  else if (trackerType == trackerTypes[6])
    tracker = cv::TrackerMOSSE::create();
  else if (trackerType == trackerTypes[7])
    tracker = cv::TrackerCSRT::create();
  else {
    std::cout << "Incorrect tracker name" << std::endl;
    std::cout << "Available trackers are: " << std::endl;
    for (std::vector<std::string>::iterator it = trackerTypes.begin();
         it != trackerTypes.end(); ++it)
      std::cout << " " << *it << std::endl;
  }
  return tracker;
}

I would like to create map with pointer to function like :

  std::map<std::string, cv::Ptr<cv::Ptr<cv::Tracker>> (*)()> trackerTypes_map =
      {{"BOOSTINGS", &cv::TrackerBoosting::create},
       {"MIL", &cv::TrackerMIL::create}};

And call it :

auto &iter = this->trackerTypes_map.find(str);
if (iter == this->trackerTypes_map.end()) {
   return nullptr;
}
return (this->trackerTypes_map.second)();

When i tried to compile, i have this error :

error : could not convert '{{"BOOSTINGS", (& cv::TrackerBoosting::create)}, {"BOOSTING", (& cv::TrackerBoosting::create)}}' from '<brace-enclosed initializer list>' to 'std::map<std::__cxx11::basic_string<char>, cv::Ptr<cv::Ptr<cv::TrackerBoosting> > (*)()>'
                           {"BOOSTING", &cv::TrackerBoosting::create}};
                                                                 ^

I don't know why isn't working, is something missing ? Wrong type ?

Error when create map with pointer to function to cvcv tracking

Good morning, I would like to create map with pointer function with tracking functions, i tried many solution but aren't working :/

I would like to avoid many if like :

cv::Ptr<cv::Tracker>
TestTrackingVideo::createTrackerByName(std::string &trackerType) {
  cv::Ptr<cv::Tracker> tracker;
  if (trackerType == trackerTypes[0])
    tracker = cv::TrackerBoosting::create();
  else if (trackerType == trackerTypes[1])
    tracker = cv::TrackerMIL::create();
  else if (trackerType == trackerTypes[2])
    tracker = cv::TrackerKCF::create();
  else if (trackerType == trackerTypes[3])
    tracker = cv::TrackerTLD::create();
  else if (trackerType == trackerTypes[4])
    tracker = cv::TrackerMedianFlow::create();
  else if (trackerType == trackerTypes[5])
    tracker = cv::TrackerGOTURN::create();
  else if (trackerType == trackerTypes[6])
    tracker = cv::TrackerMOSSE::create();
  else if (trackerType == trackerTypes[7])
    tracker = cv::TrackerCSRT::create();
  else {
    std::cout << "Incorrect tracker name" << std::endl;
    std::cout << "Available trackers are: " << std::endl;
    for (std::vector<std::string>::iterator it = trackerTypes.begin();
         it != trackerTypes.end(); ++it)
      std::cout << " " << *it << std::endl;
  }
  return tracker;
}

I would like to create map with pointer to function like :

  std::map<std::string, cv::Ptr<cv::Ptr<cv::Tracker>> (*)()> trackerTypes_map =
      {{"BOOSTINGS", &cv::TrackerBoosting::create},
       {"MIL", &cv::TrackerMIL::create}};

And call it :

auto &iter = this->trackerTypes_map.find(str);
if (iter == this->trackerTypes_map.end()) {
   return nullptr;
throw "tracker type not found !";
}
return (this->trackerTypes_map.second)();

When i tried to compile, i have this error :

error : could not convert '{{"BOOSTINGS", (& cv::TrackerBoosting::create)}, {"BOOSTING", (& cv::TrackerBoosting::create)}}' from '<brace-enclosed initializer list>' to 'std::map<std::__cxx11::basic_string<char>, cv::Ptr<cv::Ptr<cv::TrackerBoosting> > (*)()>'
                           {"BOOSTING", &cv::TrackerBoosting::create}};
                                                                 ^

I don't know why isn't working, is something missing ? Wrong type ?

Error when create map with pointer to function to cv tracking

Good morning, I would like to create map with pointer function with tracking functions, i tried many solution but aren't working :/

I would like to avoid many if like :

cv::Ptr<cv::Tracker>
TestTrackingVideo::createTrackerByName(std::string &trackerType) {
  cv::Ptr<cv::Tracker> tracker;
  if (trackerType == trackerTypes[0])
    tracker = cv::TrackerBoosting::create();
  else if (trackerType == trackerTypes[1])
    tracker = cv::TrackerMIL::create();
  else if (trackerType == trackerTypes[2])
    tracker = cv::TrackerKCF::create();
  else if (trackerType == trackerTypes[3])
    tracker = cv::TrackerTLD::create();
  else if (trackerType == trackerTypes[4])
    tracker = cv::TrackerMedianFlow::create();
  else if (trackerType == trackerTypes[5])
    tracker = cv::TrackerGOTURN::create();
  else if (trackerType == trackerTypes[6])
    tracker = cv::TrackerMOSSE::create();
  else if (trackerType == trackerTypes[7])
    tracker = cv::TrackerCSRT::create();
  else {
    std::cout << "Incorrect tracker name" << std::endl;
    std::cout << "Available trackers are: " << std::endl;
    for (std::vector<std::string>::iterator it = trackerTypes.begin();
         it != trackerTypes.end(); ++it)
      std::cout << " " << *it << std::endl;
  }
  return tracker;
}

I would like to create map with pointer to function like :

  std::map<std::string, cv::Ptr<cv::Ptr<cv::Tracker>> cv::Ptr<cv::Tracker> (*)()> trackerTypes_map =
      {{"BOOSTINGS", &cv::TrackerBoosting::create},
       {"MIL", &cv::TrackerMIL::create}};

And call it :

auto &iter = this->trackerTypes_map.find(str);
if (iter == this->trackerTypes_map.end()) {
   throw "tracker type not found !";
}
return (this->trackerTypes_map.second)();

When i tried to compile, i have this error :

error : could not convert '{{"BOOSTINGS", (& cv::TrackerBoosting::create)}, {"BOOSTING", (& cv::TrackerBoosting::create)}}' from '<brace-enclosed initializer list>' to 'std::map<std::__cxx11::basic_string<char>, cv::Ptr<cv::Ptr<cv::TrackerBoosting> > (*)()>'
                           {"BOOSTING", &cv::TrackerBoosting::create}};
                                                                 ^

I don't know why isn't working, is something missing ? Wrong type ?

Error when create map with pointer to function to cv tracking

Good morning, I would like to create map with pointer function with tracking functions, i tried many solution but aren't working :/

I would like to avoid many if like :

cv::Ptr<cv::Tracker>
TestTrackingVideo::createTrackerByName(std::string &trackerType) {
  cv::Ptr<cv::Tracker> tracker;
  if (trackerType == trackerTypes[0])
    tracker = cv::TrackerBoosting::create();
  else if (trackerType == trackerTypes[1])
    tracker = cv::TrackerMIL::create();
  else if (trackerType == trackerTypes[2])
    tracker = cv::TrackerKCF::create();
  else if (trackerType == trackerTypes[3])
    tracker = cv::TrackerTLD::create();
  else if (trackerType == trackerTypes[4])
    tracker = cv::TrackerMedianFlow::create();
  else if (trackerType == trackerTypes[5])
    tracker = cv::TrackerGOTURN::create();
  else if (trackerType == trackerTypes[6])
    tracker = cv::TrackerMOSSE::create();
  else if (trackerType == trackerTypes[7])
    tracker = cv::TrackerCSRT::create();
  else {
    std::cout << "Incorrect tracker name" << std::endl;
    std::cout << "Available trackers are: " << std::endl;
    for (std::vector<std::string>::iterator it = trackerTypes.begin();
         it != trackerTypes.end(); ++it)
      std::cout << " " << *it << std::endl;
  }
  return tracker;
}

I would like to create map with pointer to function like :

  std::map<std::string, cv::Ptr<cv::Tracker> (*)()> trackerTypes_map =
      {{"BOOSTINGS", &cv::TrackerBoosting::create},
       {"MIL", &cv::TrackerMIL::create}};

And call it :

cv::Ptr<cv::Tracker>
createTrackerByName(std::string &trackerType) {
   auto &iter = this->trackerTypes_map.find(str);
this->trackerTypes_map.find(trackerType);
   if (iter == this->trackerTypes_map.end()) {
    throw "tracker type not found !";
 }
 return (this->trackerTypes_map.second)();
}

When i tried to compile, i have this error :

error : could not convert '{{"BOOSTINGS", (& cv::TrackerBoosting::create)}, {"BOOSTING", (& cv::TrackerBoosting::create)}}' from '<brace-enclosed initializer list>' to 'std::map<std::__cxx11::basic_string<char>, cv::Ptr<cv::Ptr<cv::TrackerBoosting> > (*)()>'
                           {"BOOSTING", &cv::TrackerBoosting::create}};
                                                                 ^

I don't know why isn't working, is something missing ? Wrong type ?

Error when create map with pointer to function to cv tracking

Good morning, I would like to create map with pointer function with tracking functions, i tried many solution but aren't working :/

I would like to avoid many if like :

cv::Ptr<cv::Tracker>
TestTrackingVideo::createTrackerByName(std::string &trackerType) {
  cv::Ptr<cv::Tracker> tracker;
  if (trackerType == trackerTypes[0])
    tracker = cv::TrackerBoosting::create();
  else if (trackerType == trackerTypes[1])
    tracker = cv::TrackerMIL::create();
  else if (trackerType == trackerTypes[2])
    tracker = cv::TrackerKCF::create();
  else if (trackerType == trackerTypes[3])
    tracker = cv::TrackerTLD::create();
  else if (trackerType == trackerTypes[4])
    tracker = cv::TrackerMedianFlow::create();
  else if (trackerType == trackerTypes[5])
    tracker = cv::TrackerGOTURN::create();
  else if (trackerType == trackerTypes[6])
    tracker = cv::TrackerMOSSE::create();
  else if (trackerType == trackerTypes[7])
    tracker = cv::TrackerCSRT::create();
  else {
    std::cout << "Incorrect tracker name" << std::endl;
    std::cout << "Available trackers are: " << std::endl;
    for (std::vector<std::string>::iterator it = trackerTypes.begin();
         it != trackerTypes.end(); ++it)
      std::cout << " " << *it << std::endl;
  }
  return tracker;
}

I would like to create map with pointer to function like :

  std::map<std::string, cv::Ptr<cv::Tracker> (*)()> trackerTypes_map =
      {{"BOOSTINGS", &cv::TrackerBoosting::create},
       {"MIL", &cv::TrackerMIL::create}};

And call it :

cv::Ptr<cv::Tracker>
createTrackerByName(std::string &trackerType) {
   auto &iter = this->trackerTypes_map.find(trackerType);
   if (iter == this->trackerTypes_map.end()) {
      throw "tracker type not found !";
   }
   return (this->trackerTypes_map.second)();
}

When i tried to compile, i have this error :

error : could not convert '{{"BOOSTINGS", (& cv::TrackerBoosting::create)}, {"BOOSTING", (& cv::TrackerBoosting::create)}}' from '<brace-enclosed initializer list>' to 'std::map<std::__cxx11::basic_string<char>, cv::Ptr<cv::Ptr<cv::TrackerBoosting> > cv::Ptr<cv::TrackerBoosting> (*)()>'
                           {"BOOSTING", &cv::TrackerBoosting::create}};
                                                                 ^

I don't know why isn't working, is something missing ? Wrong type ?

Error when create map with pointer to function to cv tracking

Good morning, I would like to create map with pointer function with tracking functions, i tried many solution but aren't working :/

I would like to avoid many if like :

cv::Ptr<cv::Tracker>
TestTrackingVideo::createTrackerByName(std::string &trackerType) {
  cv::Ptr<cv::Tracker> tracker;
  if (trackerType == trackerTypes[0])
    tracker = cv::TrackerBoosting::create();
  else if (trackerType == trackerTypes[1])
    tracker = cv::TrackerMIL::create();
  else if (trackerType == trackerTypes[2])
    tracker = cv::TrackerKCF::create();
  else if (trackerType == trackerTypes[3])
    tracker = cv::TrackerTLD::create();
  else if (trackerType == trackerTypes[4])
    tracker = cv::TrackerMedianFlow::create();
  else if (trackerType == trackerTypes[5])
    tracker = cv::TrackerGOTURN::create();
  else if (trackerType == trackerTypes[6])
    tracker = cv::TrackerMOSSE::create();
  else if (trackerType == trackerTypes[7])
    tracker = cv::TrackerCSRT::create();
  else {
    std::cout << "Incorrect tracker name" << std::endl;
    std::cout << "Available trackers are: " << std::endl;
    for (std::vector<std::string>::iterator it = trackerTypes.begin();
         it != trackerTypes.end(); ++it)
      std::cout << " " << *it << std::endl;
  }
  return tracker;
}

I would like to create map with pointer to function like :

  std::map<std::string, cv::Ptr<cv::Tracker> (*)()> trackerTypes_map =
      {{"BOOSTINGS", &cv::TrackerBoosting::create},
       {"MIL", &cv::TrackerMIL::create}};

And call it :

cv::Ptr<cv::Tracker>
createTrackerByName(std::string &trackerType) {
   auto &iter = this->trackerTypes_map.find(trackerType);
   if (iter == this->trackerTypes_map.end()) {
      throw "tracker type not found !";
   }
   return (this->trackerTypes_map.second)();
}

When i tried to compile, i have this error :

error : could not convert '{{"BOOSTINGS", (& cv::TrackerBoosting::create)}, {"BOOSTING", (& cv::TrackerBoosting::create)}}' from '<brace-enclosed initializer list>' to 'std::map<std::__cxx11::basic_string<char>, cv::Ptr<cv::TrackerBoosting> (*)()>'
                           {"BOOSTING", &cv::TrackerBoosting::create}};
                                                                 ^

I don't know why isn't working, is something missing ? Wrong type ?

Error when How to create map with pointer to function to cv trackingtracking ?

Good morning, I would like to create map with pointer function with tracking functions, i tried many solution but aren't working :/

I would like to avoid many if like :

cv::Ptr<cv::Tracker>
TestTrackingVideo::createTrackerByName(std::string &trackerType) {
  cv::Ptr<cv::Tracker> tracker;
  if (trackerType == trackerTypes[0])
    tracker = cv::TrackerBoosting::create();
  else if (trackerType == trackerTypes[1])
    tracker = cv::TrackerMIL::create();
  else if (trackerType == trackerTypes[2])
    tracker = cv::TrackerKCF::create();
  else if (trackerType == trackerTypes[3])
    tracker = cv::TrackerTLD::create();
  else if (trackerType == trackerTypes[4])
    tracker = cv::TrackerMedianFlow::create();
  else if (trackerType == trackerTypes[5])
    tracker = cv::TrackerGOTURN::create();
  else if (trackerType == trackerTypes[6])
    tracker = cv::TrackerMOSSE::create();
  else if (trackerType == trackerTypes[7])
    tracker = cv::TrackerCSRT::create();
  else {
    std::cout << "Incorrect tracker name" << std::endl;
    std::cout << "Available trackers are: " << std::endl;
    for (std::vector<std::string>::iterator it = trackerTypes.begin();
         it != trackerTypes.end(); ++it)
      std::cout << " " << *it << std::endl;
  }
  return tracker;
}

I would like to create map with pointer to function like :

  std::map<std::string, cv::Ptr<cv::Tracker> (*)()> trackerTypes_map =
      {{"BOOSTINGS", &cv::TrackerBoosting::create},
       {"MIL", &cv::TrackerMIL::create}};

And call it :

cv::Ptr<cv::Tracker>
createTrackerByName(std::string &trackerType) {
   auto &iter = this->trackerTypes_map.find(trackerType);
   if (iter == this->trackerTypes_map.end()) {
      throw "tracker type not found !";
   }
   return (this->trackerTypes_map.second)();
}

When i tried to compile, i have this error :

error : could not convert '{{"BOOSTINGS", (& cv::TrackerBoosting::create)}, {"BOOSTING", (& cv::TrackerBoosting::create)}}' from '<brace-enclosed initializer list>' to 'std::map<std::__cxx11::basic_string<char>, cv::Ptr<cv::TrackerBoosting> (*)()>'
                           {"BOOSTING", &cv::TrackerBoosting::create}};
                                                                 ^

I don't know why isn't working, is something missing ? Wrong type ?

How to create map with pointer to function to cv tracking ?

Good morning, I would like to create map with pointer function with tracking functions, i tried many solution but aren't working :/

I would like to avoid many if like :

cv::Ptr<cv::Tracker>
TestTrackingVideo::createTrackerByName(std::string &trackerType) {
  cv::Ptr<cv::Tracker> tracker;
  if (trackerType == trackerTypes[0])
    tracker = cv::TrackerBoosting::create();
  else if (trackerType == trackerTypes[1])
    tracker = cv::TrackerMIL::create();
  else if (trackerType == trackerTypes[2])
    tracker = cv::TrackerKCF::create();
  else if (trackerType == trackerTypes[3])
    tracker = cv::TrackerTLD::create();
  else if (trackerType == trackerTypes[4])
    tracker = cv::TrackerMedianFlow::create();
  else if (trackerType == trackerTypes[5])
    tracker = cv::TrackerGOTURN::create();
  else if (trackerType == trackerTypes[6])
    tracker = cv::TrackerMOSSE::create();
  else if (trackerType == trackerTypes[7])
    tracker = cv::TrackerCSRT::create();
  else {
    std::cout << "Incorrect tracker name" << std::endl;
    std::cout << "Available trackers are: " << std::endl;
    for (std::vector<std::string>::iterator it = trackerTypes.begin();
         it != trackerTypes.end(); ++it)
      std::cout << " " << *it << std::endl;
  }
  return tracker;
}

I would like to create map with pointer to function like :

  std::map<std::string, cv::Ptr<cv::Tracker> (*)()> trackerTypes_map =
      {{"BOOSTINGS", &cv::TrackerBoosting::create},
       {"MIL", &cv::TrackerMIL::create}};

And call it :

cv::Ptr<cv::Tracker>
createTrackerByName(std::string &trackerType) {
   auto &iter = this->trackerTypes_map.find(trackerType);
   if (iter == this->trackerTypes_map.end()) {
      throw "tracker type not found !";
   }
   return (this->trackerTypes_map.second)();
}

When i tried to compile, i have this error :

error : could not convert '{{"BOOSTINGS", (& cv::TrackerBoosting::create)}, {"BOOSTING", (& cv::TrackerBoosting::create)}}' from '<brace-enclosed initializer list>' to 'std::map<std::__cxx11::basic_string<char>, cv::Ptr<cv::TrackerBoosting> (*)()>'
                           {"BOOSTING", &cv::TrackerBoosting::create}};
                                                                 ^

I don't know why isn't working, is something missing ? Wrong type ?