Ask Your Question

Revision history [back]

Is Opencv dnn module thread-safe

I want to deploy an image classification application with opencv dnn module. here's some logic code:

inputBlob = cv::dnn::blobFromImage(img); 
this->caffeNet.setInput(inputBlob, "data");
probMat = this->caffeNet.forward("prob").reshape(1, 1); 
cv::minMaxLoc(probMat, NULL, NULL, NULL, &classNumber);

if it's not thread-safe, where should I add lock?? like this?

mtx.lock();
probMat = this->caffeNet.forward("prob").reshape(1, 1); 
mtx.unlock();