1
0
mirror of https://github.com/opencv/opencv.git synced 2026-07-30 15:53:03 +04:00

Merge pull request #26334 from gursimarsingh:dnn_engine_change

Modify DNN Samples to use ENGINE_CLASSIC for Non-Default Back-end or Target #26334

PR resolves #26325 regarding fall-back to ENGINE_CLASSIC if non-default back-end or target is passed by user.
### Pull Request Readiness Checklist

See details at https://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request

- [x] I agree to contribute to the project under Apache 2 License.
- [x] To the best of my knowledge, the proposed patch is not based on a code under GPL or another license that is incompatible with OpenCV
- [x] The PR is proposed to the proper branch
- [x] There is a reference to the original bug report and related work
- [x] There is accuracy test, performance test and test data in opencv_extra repository, if applicable
      Patch to opencv_extra has the same branch name.
- [x] The feature is well documented and sample code can be built with the project CMake
This commit is contained in:
Gursimar Singh
2024-11-08 11:28:35 +05:30
committed by GitHub
parent 1ae304bb83
commit 979428d590
9 changed files with 39 additions and 19 deletions
+8 -4
View File
@@ -29,8 +29,8 @@ static void applyCanny(const Mat& image, Mat& result) {
}
// Load Model
static void loadModel(const string modelPath, String backend, String target, Net &net){
net = readNetFromONNX(modelPath);
static void loadModel(const string modelPath, String backend, String target, Net &net, EngineType engine){
net = readNetFromONNX(modelPath, engine);
net.setPreferableBackend(getBackendID(backend));
net.setPreferableTarget(getTargetID(target));
}
@@ -159,6 +159,10 @@ int main(int argc, char** argv) {
string method = parser.get<String>("method");
String sha1 = parser.get<String>("sha1");
string model = findModel(parser.get<String>("model"), sha1);
EngineType engine = ENGINE_AUTO;
if (backend != "default" || target != "cpu"){
engine = ENGINE_CLASSIC;
}
parser.about(about);
VideoCapture cap;
@@ -179,7 +183,7 @@ int main(int argc, char** argv) {
}
if (method == "dexined") {
loadModel(model, backend, target, net);
loadModel(model, backend, target, net, engine);
}
else{
Mat dummy = Mat::zeros(512, 512, CV_8UC3);
@@ -218,7 +222,7 @@ int main(int argc, char** argv) {
if (!model.empty()){
method = "dexined";
if (net.empty())
loadModel(model, backend, target, net);
loadModel(model, backend, target, net, engine);
destroyWindow("Output");
namedWindow("Input", WINDOW_AUTOSIZE);
namedWindow("Output", WINDOW_AUTOSIZE);