Hey so im trying to translate some python code to C++ and i run into this code:
self.net = cv.dnn.readNetFromDarknet(cfg_file, weights_file)
self.net.setPreferableBackend(cv.dnn.DNN_BACKEND_OPENCV)
self.ln = self.net.getLayerNames()
self.ln = [self.ln[i-1] for i in self.net.getUnconnectedOutLayers()]
...
blob = cv.dnn.blobFromImage(img, 1/255.0, (416, 416), swapRB=True, crop=False)
self.net.setInput(blob)
outputs = self.net.forward(self.ln)
outputs = np.vstack(outputs)
as you can see the code is taking the output from net forward from the unconnected layer names that are specified in self.ln. Now here is my C++ code:
static Mat blobFromImg;
bool swapRB = true;
blobFromImage(img, blobFromImg, 1/255.0, Size(416, 416), Scalar(), swapRB, false);
network.setInput(blobFromImg);
Mat outMat;
network.forward(outMat , network.getUnconnectedOutLayersNames());
vconcat(outMat, outMat);
As you can see i am using vconcat in place of np.vstack and instead of making a new vector<<cv::String>> to pass to network.forward() i use getUnconnectedOutLayersNames(). Yet i get this error:
OpenCV(4.8.0) Error: The function/feature is not implemented () in cv::debug_build_guard::_OutputArray::assign, file D:vcpkgbuildtreesopencv4src4.8.0-2bf495557d.cleanmodulescoresrcmatrix_wrap.cpp, line 2052
The line that where the exception occurs is network.forward(). It is because of this method because network.getUnconnectedOutLayersNames(); doesnt give the exception by itself.
If i do:
std::vector<cv::String> ln;
auto layers = network.getLayerNames();
for (auto i : network.getUnconnectedOutLayers()){
ln.push_back(layers[i-1]);
}
...
network.setInput(blobFromImg);
Mat outMat;
network.forward(outMat , ln);
vconcat(outMat, outMat);
I get the same result.
Why is the function not implemented? Why does python have this implementation.
Note: I am using darknet/yolo.