mirror of
https://github.com/opencv/opencv.git
synced 2026-07-29 07:13:02 +04:00
Merge pull request #27246 from gursimarsingh:bug_fix/mcc_dnn_dependency
Fix hard dependency of dnn for mcc module. #27246 Currently building objdetect module without dnn fails due to mcc module. This PR makes the dependency optional, by checking if DNN is available in mcc module. ### 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 - [ ] There is a reference to the original bug report and related work - [ ] There is accuracy test, performance test and test data in opencv_extra repository, if applicable Patch to opencv_extra has the same branch name. - [ ] The feature is well documented and sample code can be built with the project CMake
This commit is contained in:
@@ -1,32 +1,48 @@
|
||||
#include <opencv2/core.hpp>
|
||||
#include <opencv2/highgui.hpp>
|
||||
#include <opencv2/objdetect.hpp>
|
||||
#ifdef HAVE_OPENCV_DNN
|
||||
#include <opencv2/dnn.hpp>
|
||||
#include <iostream>
|
||||
#include "../dnn/common.hpp"
|
||||
#endif
|
||||
#include <iostream>
|
||||
|
||||
using namespace std;
|
||||
using namespace cv;
|
||||
#ifdef HAVE_OPENCV_DNN
|
||||
using namespace cv::dnn;
|
||||
#endif
|
||||
using namespace mcc;
|
||||
|
||||
const string about =
|
||||
"This sample demonstrates mcc checker detection with DNN based model and thresholding (default) techniques.\n\n"
|
||||
"To run default:\n"
|
||||
"\t ./example_cpp_macbeth_chart_detection --input=path/to/your/input/image/or/video (don't give --input flag if want to use device camera)\n"
|
||||
#ifdef HAVE_OPENCV_DNN
|
||||
"With DNN model:\n"
|
||||
"\t ./example_cpp_macbeth_chart_detection mcc --input=path/to/your/input/image/or/video\n\n"
|
||||
"Model path can also be specified using --model argument. And config path can be specified using --config. Download it using python download_models.py mcc from dnn samples directory\n\n";
|
||||
"Model path can also be specified using --model argument. And config path can be specified using --config. Download it using python download_models.py mcc from dnn samples directory\n\n"
|
||||
#else
|
||||
"Note: DNN-based detection is not available in this build.\n\n"
|
||||
#endif
|
||||
;
|
||||
|
||||
const string param_keys =
|
||||
"{ help h | | Print help message. }"
|
||||
#ifdef HAVE_OPENCV_DNN
|
||||
"{ @alias | | An alias name of model to extract preprocessing parameters from models.yml file. }"
|
||||
"{ zoo | ../dnn/models.yml | An optional path to file with preprocessing parameters }"
|
||||
#endif
|
||||
"{ input i | | Path to input image or video file. Skip this argument to capture frames from a camera.}"
|
||||
"{ type | 0 | chartType: 0-Standard, 1-DigitalSG, 2-Vinyl, default:0 }"
|
||||
"{ num_charts | 1 | Maximum number of charts in the image }"
|
||||
#ifdef HAVE_OPENCV_DNN
|
||||
"{ model | | Path to the model file for using dnn model. }";
|
||||
#else
|
||||
;
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_OPENCV_DNN
|
||||
const string backend_keys = format(
|
||||
"{ backend | default | Choose one of computation backends: "
|
||||
"default: automatically (by default), "
|
||||
@@ -45,8 +61,15 @@ const string target_keys = format(
|
||||
"vulkan: Vulkan, "
|
||||
"cuda: CUDA, "
|
||||
"cuda_fp16: CUDA fp16 (half-float preprocess) }");
|
||||
#endif
|
||||
|
||||
string keys = param_keys + backend_keys + target_keys;
|
||||
// Initialize keys before use
|
||||
string keys = param_keys;
|
||||
static void initKeys() {
|
||||
#ifdef HAVE_OPENCV_DNN
|
||||
keys += backend_keys + target_keys;
|
||||
#endif
|
||||
}
|
||||
|
||||
static bool processFrame(const Mat& frame, Ptr<CCheckerDetector> detector, Mat& src, Mat& tgt, int nc){
|
||||
Mat imageCopy = frame.clone();
|
||||
@@ -67,6 +90,7 @@ static bool processFrame(const Mat& frame, Ptr<CCheckerDetector> detector, Mat&
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
initKeys();
|
||||
CommandLineParser parser(argc, argv, keys);
|
||||
parser.about(about);
|
||||
|
||||
@@ -76,6 +100,8 @@ int main(int argc, char *argv[])
|
||||
parser.printMessage();
|
||||
return -1;
|
||||
}
|
||||
|
||||
#ifdef HAVE_OPENCV_DNN
|
||||
string modelName = parser.get<String>("@alias");
|
||||
string zooFile = parser.get<String>("zoo");
|
||||
const char* path = getenv("OPENCV_SAMPLES_DATA_PATH");
|
||||
@@ -88,22 +114,26 @@ int main(int argc, char *argv[])
|
||||
|
||||
keys += genPreprocArguments(modelName, zooFile);
|
||||
parser = CommandLineParser(argc, argv, keys);
|
||||
#endif
|
||||
|
||||
int t = parser.get<int>("type");
|
||||
|
||||
CV_Assert(0 <= t && t <= 2);
|
||||
ColorChart chartType = ColorChart(t);
|
||||
|
||||
#ifdef HAVE_OPENCV_DNN
|
||||
const string sha1 = parser.get<String>("sha1");
|
||||
const string model_path = findModel(parser.get<string>("model"), sha1);
|
||||
const string config_sha1 = parser.get<String>("config_sha1");
|
||||
const string pbtxt_path = findModel(parser.get<string>("config"), config_sha1);
|
||||
const string backend = parser.get<String>("backend");
|
||||
const string target = parser.get<String>("target");
|
||||
#endif
|
||||
|
||||
int nc = parser.get<int>("num_charts");
|
||||
|
||||
Ptr<CCheckerDetector> detector;
|
||||
#ifdef HAVE_OPENCV_DNN
|
||||
if (model_path != "" && pbtxt_path != ""){
|
||||
EngineType engine = ENGINE_AUTO;
|
||||
if (backend != "default" || target != "cpu"){
|
||||
@@ -119,6 +149,9 @@ int main(int argc, char *argv[])
|
||||
else{
|
||||
detector = CCheckerDetector::create();
|
||||
}
|
||||
#else
|
||||
detector = CCheckerDetector::create();
|
||||
#endif
|
||||
detector->setColorChartType(chartType);
|
||||
|
||||
bool isVideo = true;
|
||||
|
||||
Reference in New Issue
Block a user