Reputation: 292
I try to do a queue of Mat images elements, but Visual C++ give me an error about "tipe" of queue.
I want to have an concurrent queue of OpenCV Mat images for use it with multiple threads.
How can I do this?
This is the code of the queue give me error (created about an example see in this forum):
template<data Mat>
class coda_concorr
{
private:
std::queue<Mat> la_coda;
HANDLE mutex;
public:
void push(Mat const& data)
{
WaitForSingleObject(mutex,INFINITE):
la_coda.push(data);
RelaseMutex(mutex);
}
bool vuota() const
{
WaitForSingleObject(mutex,INFINITE);
return la_coda.empty();
ReleaseMutex(mutex);
}
bool try_pop(Mat& popped)
{
WaitForSingleObject(mutex,INFINITE);
if (la_coda.empty())
{
return false;
}
popped = la_coda.front();
la_coda.pop();
return true;
}
void aspetta_per_pop(Mat& popped)
{
WaitForSingleObject(mutex,INFINITE);
while (la_coda.empty())
{
WaitForSingleObject(mutex,INFINITE);
}
popped=la_coda.front();
la_coda.pop();
}
};
I use Visual Studio 2010 and OpenCV 2.4.4
Upvotes: 0
Views: 1391
Reputation: 227468
This is invalid template syntax:
template<data Mat>
class coda_concorr { .... };
You are not using any template parameters in your class, so you could make it a non-template. But it would make more sense to make it a template, and replace Mat
by the template parameter.
template<typename T>
class coda_concorr
{
private:
std::queue<T> la_coda;
....
public:
void push(T const& data) { .... }
};
then, you can instantiate the template for a cv::Mat
:
coda_concorr<cv::Mat> matQueue;
or a different type, this being the point of making the class a template in the first place:
coda_concorr<int> intQueue;
coda_concorr<std::string> stringQueue;
Upvotes: 1
Reputation: 23640
If I were you, I'd use a third-party library for a concurrent queue, because writing efficient thread-safe code is considered hard. I can recommend the PPL library from Microsoft or the TBB library from Intel.
Upvotes: 1