屏幕截图:返回错误的getBlob结果:这是附加代码:
resize(img,img,Size(224,224));
dnn :: Blob inputBlob = dnn :: Blob :: fromImages(img);net.setBlob(“。data”,inputBlob);净….
我认为这是因为你处理4D blob,而不是矩阵,大小存储在size数组中(见下面的例子)。 尝试使用此代码段提取平面:
//------------------------------------------------------- // Extract plane with defined n and c from nchw blob //------------------------------------------------------- void mtcnn::extractPlane(Mat &src, int n, int ch, Mat &dst) { const int rows = src.size[2]; const int cols = src.size[3]; dst = cv::Mat::zeros(rows, cols, CV_32FC1); for (int row = 0; row < rows; row++) { const float *ptrsrc = src.ptr<float>(n, ch, row); float *ptrdst = dst.ptr<float>(row); for (int col = 0; col < cols; col++) { ptrdst[col] = ptrsrc[col]; } } }
希望你使用这样的东西来设置输入数据:
inputBlob = blobFromImage(img, 0.0078125, Size(ws, hs), Scalar(127.5, 127.5, 127.5)); //Convert Mat to batch of images p_net.setInput(inputBlob, "data"); //set the network input