opecv4.0.1 dnn 运行报错

开源环境 vs2015 + opencv4.0.1

代码片段

void init()
{
// 初始化网络
	Net net = readNetFromCaffe(modelDesc, modelBinary);
	Net netRecogn = readNetFromTorch(facemodel);
	net.setPreferableBackend(DNN_BACKEND_OPENCV);
//	net.setPreferableBackend(DNN_BACKEND_INFERENCE_ENGINE);
	net.setPreferableTarget(DNN_TARGET_CPU);

	netRecogn.setPreferableBackend(DNN_BACKEND_OPENCV);
	//netRecogn.setPreferableBackend(DNN_BACKEND_INFERENCE_ENGINE);
	netRecogn.setPreferableTarget(DNN_TARGET_CPU);

}


void recognize_face(Mat &face, Net net, vector &fv) 
{
	Mat blob = blobFromImage(face, 1.0/255.0, Size(96, 96), Scalar(0, 0, 0), true, false);
	net.setInput(blob);
	Mat probMat = net.forward();
	Mat vec = probMat.reshape(1, 1);
	printf("vec rows : %d, vec cols : %d \n", vec.rows, vec.cols);
	for (int i = 0; i < vec.cols; i++) 
    {
		float value = vec.at(0, i);
		fv.push_back(value);
	}
}

 

在 Mat probMat = net.forward() 语句中 运行报错

 OpenCV(4.0.1) Error: Assertion failed (haveInfEngine()) in cv::dnn::dnn4_v20181221::wrapMat, file C:\build\master_winpack-build-win64-vc14\opencv\modules\dnn\src\dnn.cpp, line 997

 

出错原因是运行环境的opencv 没有安装IE 库(Intel's Inference Engine library )。

将 net.setPreferableBackend(DNN_BACKEND_INFERENCE_ENGINE); 换成 net.setPreferableBackend(DNN_BACKEND_OPENCV); 即可
 

DNN 后台枚举:


enum Backend 
{ //! DNN_BACKEND_DEFAULT equals to DNN_BACKEND_INFERENCE_ENGINE if
 //! OpenCV is built with Intel's Inference Engine library or 
//! DNN_BACKEND_OPENCV otherwise. DNN_BACKEND_DEFAULT, 

DNN_BACKEND_HALIDE,
 DNN_BACKEND_INFERENCE_ENGINE, 
DNN_BACKEND_OPENCV, 
DNN_BACKEND_VKCOM 
};

 

你可能感兴趣的:(opencv)