mirror of
https://github.com/opencv/opencv.git
synced 2026-07-30 07:43:03 +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:
@@ -29,7 +29,9 @@
|
||||
#ifndef OPENCV_OBJDETECT_MCC_CHECKER_DETECTOR_HPP
|
||||
#define OPENCV_OBJDETECT_MCC_CHECKER_DETECTOR_HPP
|
||||
#include <opencv2/core.hpp>
|
||||
#ifdef HAVE_OPENCV_DNN
|
||||
#include <opencv2/dnn.hpp>
|
||||
#endif
|
||||
#include <opencv2/imgproc.hpp>
|
||||
|
||||
//---------------------------------------------------------------
|
||||
@@ -241,7 +243,9 @@ public:
|
||||
*
|
||||
*/
|
||||
CV_WRAP static Ptr<CCheckerDetector> create();
|
||||
/** @brief Set the net which will be used to find the approximate
|
||||
|
||||
#ifdef HAVE_OPENCV_DNN
|
||||
/** @brief Set the net which will be used to find the approximate
|
||||
* bounding boxes for the color charts. And returns the implementation of the CCheckerDetector.
|
||||
*
|
||||
* It is not necessary to use this, but this usually results in
|
||||
@@ -251,6 +255,7 @@ public:
|
||||
* the function will return false.
|
||||
*/
|
||||
CV_WRAP static Ptr<CCheckerDetector> create(const dnn::Net &net);
|
||||
#endif
|
||||
|
||||
/** @brief Draws the checker to the given image.
|
||||
* @param img image in color space BGR
|
||||
@@ -280,6 +285,7 @@ public:
|
||||
|
||||
CV_WRAP virtual void setColorChartType(ColorChart chartType) = 0;
|
||||
|
||||
#ifdef HAVE_OPENCV_DNN
|
||||
/** @brief Enables or disables the use of the neural network for detection.
|
||||
* @param useDnn Boolean flag to indicate whether to use neural network (true) or not (false).
|
||||
*/
|
||||
@@ -287,6 +293,7 @@ public:
|
||||
CV_WRAP virtual void setUseDnnModel(bool useDnn) = 0;
|
||||
|
||||
CV_WRAP virtual bool getUseDnnModel() const = 0;
|
||||
#endif
|
||||
|
||||
CV_WRAP virtual const DetectorParametersMCC& getDetectionParams() const = 0;
|
||||
|
||||
|
||||
@@ -1,4 +0,0 @@
|
||||
#include "opencv2/objdetect/mcc_checker_detector.hpp"
|
||||
|
||||
typedef std::vector<cv::Ptr<mcc::CChecker>> vector_Ptr_CChecker;
|
||||
typedef dnn::Net dnn_Net;
|
||||
@@ -3,5 +3,9 @@
|
||||
#include "opencv2/objdetect.hpp"
|
||||
|
||||
typedef QRCodeEncoder::Params QRCodeEncoder_Params;
|
||||
typedef std::vector<cv::Ptr<mcc::CChecker>> vector_Ptr_CChecker;
|
||||
#ifdef HAVE_OPENCV_DNN
|
||||
typedef dnn::Net dnn_Net;
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
@@ -44,10 +44,13 @@ Ptr<CCheckerDetector> CCheckerDetector::create()
|
||||
{
|
||||
return makePtr<CCheckerDetectorImpl>();
|
||||
}
|
||||
|
||||
#ifdef HAVE_OPENCV_DNN
|
||||
Ptr<CCheckerDetector> CCheckerDetector::create(const dnn::Net& net)
|
||||
{
|
||||
return makePtr<CCheckerDetectorImpl>(net);
|
||||
}
|
||||
#endif
|
||||
|
||||
CCheckerDetectorImpl::
|
||||
CCheckerDetectorImpl()
|
||||
@@ -251,6 +254,7 @@ bool CCheckerDetectorImpl::
|
||||
{
|
||||
m_checkers.clear();
|
||||
|
||||
#ifdef HAVE_OPENCV_DNN
|
||||
if (this->net.empty() || !m_useDnn)
|
||||
{
|
||||
return _no_net_process(image, nc, regionsOfInterest);
|
||||
@@ -471,6 +475,9 @@ bool CCheckerDetectorImpl::
|
||||
m_checkers.resize(min(nc, (int)m_checkers.size()));
|
||||
|
||||
return !m_checkers.empty();
|
||||
#else
|
||||
return _no_net_process(image, nc, regionsOfInterest);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
@@ -491,7 +498,7 @@ void CCheckerDetectorImpl::setColorChartType(ColorChart chartType)
|
||||
{
|
||||
this->m_chartType = chartType;
|
||||
}
|
||||
|
||||
#ifdef HAVE_OPENCV_DNN
|
||||
void CCheckerDetectorImpl::setUseDnnModel(bool useDnn)
|
||||
{
|
||||
this->m_useDnn = useDnn;
|
||||
@@ -501,7 +508,7 @@ bool CCheckerDetectorImpl::getUseDnnModel() const
|
||||
{
|
||||
return m_useDnn;
|
||||
}
|
||||
|
||||
#endif
|
||||
const DetectorParametersMCC& CCheckerDetectorImpl::getDetectionParams() const
|
||||
{
|
||||
return m_params;
|
||||
@@ -1428,8 +1435,6 @@ void CCheckerDetectorImpl::
|
||||
{
|
||||
// color chart classic model
|
||||
CChartModel cccm(m_chartType);
|
||||
Mat lab;
|
||||
size_t N;
|
||||
std::vector<Point2f> fbox = cccm.box;
|
||||
std::vector<Point2f> cellchart = cccm.cellchart;
|
||||
|
||||
@@ -1439,7 +1444,7 @@ void CCheckerDetectorImpl::
|
||||
Mat mask(im_rgb.size(), CV_8U);
|
||||
mask.setTo(Scalar::all(0));
|
||||
std::vector<Point2f> bch(4), bcht(4);
|
||||
N = cellchart.size() / 4;
|
||||
size_t N = cellchart.size() / 4;
|
||||
|
||||
// Create table charts information
|
||||
// |p_size|average|stddev|max|min|
|
||||
|
||||
@@ -45,9 +45,11 @@ class CCheckerDetectorImpl : public CCheckerDetector
|
||||
|
||||
public:
|
||||
CCheckerDetectorImpl();
|
||||
#ifdef HAVE_OPENCV_DNN
|
||||
CCheckerDetectorImpl(const dnn::Net& _net){
|
||||
net = _net;
|
||||
}
|
||||
#endif
|
||||
virtual ~CCheckerDetectorImpl();
|
||||
|
||||
bool process(InputArray image, const std::vector<Rect> ®ionsOfInterest,
|
||||
@@ -72,9 +74,11 @@ public:
|
||||
|
||||
virtual void setColorChartType(ColorChart chartType) CV_OVERRIDE;
|
||||
|
||||
#ifdef HAVE_OPENCV_DNN
|
||||
virtual void setUseDnnModel(bool useDnn) CV_OVERRIDE;
|
||||
|
||||
virtual bool getUseDnnModel() const CV_OVERRIDE;
|
||||
#endif
|
||||
|
||||
virtual const DetectorParametersMCC& getDetectionParams() const CV_OVERRIDE;
|
||||
|
||||
@@ -164,10 +168,14 @@ protected: // methods pipeline
|
||||
|
||||
protected:
|
||||
std::vector<Ptr<CChecker>> m_checkers;
|
||||
#ifdef HAVE_OPENCV_DNN
|
||||
dnn::Net net;
|
||||
bool m_useDnn = true;
|
||||
#else
|
||||
bool m_useDnn = false;
|
||||
#endif
|
||||
DetectorParametersMCC m_params = DetectorParametersMCC();
|
||||
ColorChart m_chartType;
|
||||
bool m_useDnn = true;
|
||||
|
||||
private: // methods aux
|
||||
void get_subbox_chart_physical(
|
||||
|
||||
@@ -34,7 +34,9 @@
|
||||
#include <opencv2/core.hpp>
|
||||
#include <opencv2/imgproc.hpp>
|
||||
#include <opencv2/3d.hpp>
|
||||
#ifdef HAVE_OPENCV_DNN
|
||||
#include <opencv2/dnn.hpp>
|
||||
#endif
|
||||
|
||||
#include <vector>
|
||||
#include <string>
|
||||
|
||||
Reference in New Issue
Block a user