mercredi 10 juillet 2019

How to open multiple VideoCapture simultaneously with opencv?

Create and open video capture from ip camera take about 2 seconds. I want to open over 10 video captures and for better performance i want to do this work by creating video captures in different thread. But video capture create sequentially.

I saw source of opencv and found this peace of code when opencv create a capture in backend_plugin.cpp file.

void initBackend()
{
    AutoLock lock(getInitializationMutex());
    try {
        if (!initialized)
            loadPlugin();
    }

Is this code prevent my code to be concurrent ? or i have a mistake ?

this is my sample code used for create video captures.

I used std::thread and std::future but result was same.

vector<VideoCapture> captureList;
std::vector<std::thread> threads;

for (auto &it : urlList) {

  string url = it;

  threads.push_back(thread([](string url) {
      cout << "*********** : " << url << endl;
      VideoCapture& cap = VideoCapture(url);
      captureList.push_back(cap);

  }, it));
}

for (auto& thread : threads) {
  thread.join();
}

How can i do this work ?

Aucun commentaire:

Enregistrer un commentaire