Skip to content

Commit 3f609aa

Browse files
authored
Move objdetect HaarCascadeClassifier and HOGDescriptor to contrib xobjdetect (#3692)
* Move objdetect parts to contrib * Move objdetect parts to contrib * Fix errors from CI build. * Minor fixes.
1 parent 8f3a61b commit 3f609aa

File tree

150 files changed

+758910
-78
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

150 files changed

+758910
-78
lines changed

modules/cudalegacy/CMakeLists.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,4 @@ if(ENABLE_CUDA_FIRST_CLASS_LANGUAGE)
99
ocv_module_include_directories(${CUDAToolkit_INCLUDE_DIRS})
1010
endif()
1111
ocv_define_module(cudalegacy opencv_core opencv_video
12-
OPTIONAL opencv_objdetect opencv_imgproc opencv_3d opencv_stereo opencv_calib opencv_cudaarithm opencv_cudafilters opencv_cudaimgproc)
12+
OPTIONAL opencv_objdetect opencv_xobjdetect opencv_imgproc opencv_3d opencv_stereo opencv_calib opencv_cudaarithm opencv_cudafilters opencv_cudaimgproc)

modules/cudalegacy/src/NCV.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -737,12 +737,12 @@ struct RectConvert
737737

738738
static void groupRectangles(std::vector<NcvRect32u> &hypotheses, int groupThreshold, double eps, std::vector<Ncv32u> *weights)
739739
{
740-
#ifndef HAVE_OPENCV_OBJDETECT
740+
#ifndef HAVE_OPENCV_XOBJDETECT
741741
CV_UNUSED(hypotheses);
742742
CV_UNUSED(groupThreshold);
743743
CV_UNUSED(eps);
744744
CV_UNUSED(weights);
745-
CV_Error(cv::Error::StsNotImplemented, "This functionality requires objdetect module");
745+
CV_Error(cv::Error::StsNotImplemented, "This functionality requires xobjdetect module");
746746
#else
747747
std::vector<cv::Rect> rects(hypotheses.size());
748748
std::transform(hypotheses.begin(), hypotheses.end(), rects.begin(), RectConvert());

modules/cudalegacy/src/cuda/NCVHaarObjectDetection.cu

+45-45
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,8 @@
6464

6565
#include "opencv2/opencv_modules.hpp"
6666

67-
#ifdef HAVE_OPENCV_OBJDETECT
68-
# include "opencv2/objdetect.hpp"
67+
#ifdef HAVE_OPENCV_XOBJDETECT
68+
# include "opencv2/xobjdetect.hpp"
6969
//# include "opencv2/objdetect/objdetect_c.h"
7070
#endif
7171

@@ -1843,16 +1843,16 @@ static NCVStatus loadFromXML(const cv::String &filename,
18431843
std::vector<HaarClassifierNode128> &haarClassifierNodes,
18441844
std::vector<HaarFeature64> &haarFeatures)
18451845
{
1846-
const char *CUDA_CC_SIZE = "size";
1847-
const char *CUDA_CC_STAGES = "stages";
1848-
const char *CUDA_CC_STAGE_THRESHOLD = "stage_threshold";
1849-
const char *CUDA_CC_TREES = "trees";
1850-
const char *CUDA_CC_FEATURE = "feature";
1851-
const char *CUDA_CC_RECT = "rects";
1852-
const char *CUDA_CC_TILTED = "tilted";
1853-
const char *CUDA_CC_THRESHOLD = "threshold";
1846+
const char *CUDA_CC_SIZE = "size";
1847+
const char *CUDA_CC_STAGES = "stages";
1848+
const char *CUDA_CC_STAGE_THRESHOLD = "stage_threshold";
1849+
const char *CUDA_CC_TREES = "trees";
1850+
const char *CUDA_CC_FEATURE = "feature";
1851+
const char *CUDA_CC_RECT = "rects";
1852+
const char *CUDA_CC_TILTED = "tilted";
1853+
const char *CUDA_CC_THRESHOLD = "threshold";
18541854
const char *CUDA_CC_LEFT_VAL = "left_val";
1855-
const char *CUDA_CC_RIGHT_VAL = "right_val";
1855+
const char *CUDA_CC_RIGHT_VAL = "right_val";
18561856
const char *CUDA_CC_LEFT_NODE = "left_node";
18571857
const char *CUDA_CC_RIGHT_NODE = "right_node";
18581858

@@ -1873,60 +1873,60 @@ static NCVStatus loadFromXML(const cv::String &filename,
18731873
haarClassifierNodes.resize(0);
18741874
haarFeatures.resize(0);
18751875

1876-
cv::FileStorage fs(filename, cv::FileStorage::READ | cv::FileStorage::FORMAT_XML);
1877-
1878-
if (!fs.isOpened())
1876+
cv::FileStorage fs(filename, cv::FileStorage::READ | cv::FileStorage::FORMAT_XML);
1877+
1878+
if (!fs.isOpened())
18791879
return NCV_FILE_ERROR;
18801880

1881-
const cv::FileNode &root = fs.getFirstTopLevelNode();
1881+
const cv::FileNode &root = fs.getFirstTopLevelNode();
18821882
const cv::FileNode &fnSize = root[CUDA_CC_SIZE];
18831883

18841884
// collect the cascade classifier window size
18851885
haar.ClassifierSize.width = (int)fnSize[CUDA_CC_SIZE_W];
18861886
haar.ClassifierSize.height = (int)fnSize[CUDA_CC_SIZE_H];
18871887
CV_Assert(haar.ClassifierSize.height > 0 && haar.ClassifierSize.width > 0);
18881888

1889-
const cv::FileNode &fnStages = root[CUDA_CC_STAGES];
1889+
const cv::FileNode &fnStages = root[CUDA_CC_STAGES];
18901890
cv::FileNodeIterator it = fnStages.begin(), it_end = fnStages.end();
18911891

1892-
for (; it != it_end; ++it) // by stages
1893-
{
1894-
cv::FileNode fnStage = *it;
1892+
for (; it != it_end; ++it) // by stages
1893+
{
1894+
cv::FileNode fnStage = *it;
18951895
HaarStage64 curStage;
18961896

1897-
curStage.setStartClassifierRootNodeOffset(static_cast<Ncv32u>(haarClassifierNodes.size()));
1897+
curStage.setStartClassifierRootNodeOffset(static_cast<Ncv32u>(haarClassifierNodes.size()));
18981898
curStage.setStageThreshold((float)fnStage[CUDA_CC_STAGE_THRESHOLD]);
18991899

1900-
// iterate over the trees
1901-
const cv::FileNode &fnTrees = fnStage[CUDA_CC_TREES];
1902-
cv::FileNodeIterator it1 = fnTrees.begin(), it1_end = fnTrees.end();
1903-
1904-
for (; it1 != it1_end; ++it1) // by trees
1905-
{
1906-
cv::FileNode tree = *it1;
1907-
Ncv32u nodeId = (size_t)0;
1908-
HaarClassifierNode128 curNode;
1909-
1910-
curNode.setThreshold((float)tree[0][CUDA_CC_THRESHOLD]);
1911-
1912-
NcvBool bIsLeftNodeLeaf = false;
1913-
NcvBool bIsRightNodeLeaf = false;
1914-
1900+
// iterate over the trees
1901+
const cv::FileNode &fnTrees = fnStage[CUDA_CC_TREES];
1902+
cv::FileNodeIterator it1 = fnTrees.begin(), it1_end = fnTrees.end();
1903+
1904+
for (; it1 != it1_end; ++it1) // by trees
1905+
{
1906+
cv::FileNode tree = *it1;
1907+
Ncv32u nodeId = (size_t)0;
1908+
HaarClassifierNode128 curNode;
1909+
1910+
curNode.setThreshold((float)tree[0][CUDA_CC_THRESHOLD]);
1911+
1912+
NcvBool bIsLeftNodeLeaf = false;
1913+
NcvBool bIsRightNodeLeaf = false;
1914+
19151915
HaarClassifierNodeDescriptor32 nodeLeft;
19161916

19171917
cv::FileNode leftNode = tree[0][CUDA_CC_LEFT_NODE];
19181918

19191919
if (leftNode.fs == NULL)
19201920
{
1921-
Ncv32f leftVal = tree[0][CUDA_CC_LEFT_VAL];
1922-
ncvStat = nodeLeft.create(leftVal);
1921+
Ncv32f leftVal = tree[0][CUDA_CC_LEFT_VAL];
1922+
ncvStat = nodeLeft.create(leftVal);
19231923
ncvAssertReturn(ncvStat == NCV_SUCCESS, ncvStat);
19241924
bIsLeftNodeLeaf = true;
19251925
}
19261926
else
19271927
{
1928-
Ncv32u leftNodeOffset = (int)tree[0][CUDA_CC_LEFT_NODE];
1929-
nodeLeft.create((Ncv32u)(h_TmpClassifierNotRootNodes.size() + leftNodeOffset - 1));
1928+
Ncv32u leftNodeOffset = (int)tree[0][CUDA_CC_LEFT_NODE];
1929+
nodeLeft.create((Ncv32u)(h_TmpClassifierNotRootNodes.size() + leftNodeOffset - 1));
19301930
haar.bHasStumpsOnly = false;
19311931
}
19321932

@@ -1937,15 +1937,15 @@ static NCVStatus loadFromXML(const cv::String &filename,
19371937

19381938
if (rightNode.fs == NULL)
19391939
{
1940-
Ncv32f rightVal = tree[0][CUDA_CC_RIGHT_VAL];
1941-
ncvStat = nodeRight.create(rightVal);
1940+
Ncv32f rightVal = tree[0][CUDA_CC_RIGHT_VAL];
1941+
ncvStat = nodeRight.create(rightVal);
19421942
ncvAssertReturn(ncvStat == NCV_SUCCESS, ncvStat);
19431943
bIsRightNodeLeaf = true;
19441944
}
19451945
else
19461946
{
1947-
Ncv32u rightNodeOffset = (int)tree[0][CUDA_CC_RIGHT_NODE];
1948-
nodeRight.create((Ncv32u)(h_TmpClassifierNotRootNodes.size() + rightNodeOffset - 1));
1947+
Ncv32u rightNodeOffset = (int)tree[0][CUDA_CC_RIGHT_NODE];
1948+
nodeRight.create((Ncv32u)(h_TmpClassifierNotRootNodes.size() + rightNodeOffset - 1));
19491949
haar.bHasStumpsOnly = false;
19501950
}
19511951

@@ -1955,9 +1955,9 @@ static NCVStatus loadFromXML(const cv::String &filename,
19551955
Ncv32u tiltedVal = (int)fnFeature[CUDA_CC_TILTED];
19561956
haar.bNeedsTiltedII = (tiltedVal != 0);
19571957

1958-
cv::FileNodeIterator it2 = fnFeature[CUDA_CC_RECT].begin(), it2_end = fnFeature[CUDA_CC_RECT].end();
1958+
cv::FileNodeIterator it2 = fnFeature[CUDA_CC_RECT].begin(), it2_end = fnFeature[CUDA_CC_RECT].end();
19591959

1960-
Ncv32u featureId = 0;
1960+
Ncv32u featureId = 0;
19611961
for (; it2 != it2_end; ++it2) // by feature
19621962
{
19631963
cv::FileNode rect = *it2;

modules/cudalegacy/src/precomp.hpp

+4
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,10 @@
6363
# include "opencv2/objdetect.hpp"
6464
#endif
6565

66+
#ifdef HAVE_OPENCV_XOBJDETECT
67+
# include "opencv2/xobjdetect.hpp"
68+
#endif
69+
6670
#ifdef HAVE_OPENCV_3D
6771
# include "opencv2/3d.hpp"
6872
#endif

modules/cudaobjdetect/CMakeLists.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,4 @@ set(the_description "CUDA-accelerated Object Detection")
66

77
ocv_warnings_disable(CMAKE_CXX_FLAGS /wd4127 /wd4324 /wd4512 -Wundef -Wmissing-declarations -Wshadow -Wstrict-aliasing)
88

9-
ocv_define_module(cudaobjdetect opencv_objdetect opencv_cudaarithm opencv_cudawarping OPTIONAL opencv_cudalegacy WRAP python)
9+
ocv_define_module(cudaobjdetect opencv_objdetect opencv_xobjdetect opencv_cudaarithm opencv_cudawarping OPTIONAL opencv_cudalegacy WRAP python)

modules/cudaobjdetect/include/opencv2/cudaobjdetect.hpp

+6-6
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@
4848
#endif
4949

5050
#include "opencv2/core/cuda.hpp"
51-
#include "opencv2/objdetect.hpp"
51+
#include "opencv2/xobjdetect.hpp"
5252

5353
/**
5454
@addtogroup cuda
@@ -70,11 +70,11 @@ namespace cv { namespace cuda {
7070
7171
@note
7272
- An example applying the HOG descriptor for people detection can be found at
73-
opencv_source_code/samples/cpp/peopledetect.cpp
73+
xobjdetect_module/samples/peopledetect.cpp
7474
- A CUDA example applying the HOG descriptor for people detection can be found at
75-
opencv_source_code/samples/gpu/hog.cpp
75+
xobjdetect_module/samples/gpu/hog.cpp
7676
- (Python) An example applying the HOG descriptor for people detection can be found at
77-
opencv_source_code/samples/python/peopledetect.py
77+
xobjdetect_module/samples/python/peopledetect.py
7878
*/
7979
class CV_EXPORTS_W HOG : public Algorithm
8080
{
@@ -222,8 +222,8 @@ class CV_EXPORTS_W HOG : public Algorithm
222222
/** @brief Cascade classifier class used for object detection. Supports HAAR and LBP cascades. :
223223
224224
@note
225-
- A cascade classifier example can be found at
226-
opencv_source_code/samples/gpu/cascadeclassifier.cpp
225+
- A cascade classifier example can be found at
226+
xobjdetect_module/samples/gpu/cascadeclassifier.cpp
227227
- A Nvidea API specific cascade classifier example can be found at
228228
opencv_source_code/samples/gpu/cascadeclassifier_nvidia_api.cpp
229229
*/

modules/cudaobjdetect/perf/perf_precomp.hpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646
#include "opencv2/ts/cuda_perf.hpp"
4747

4848
#include "opencv2/cudaobjdetect.hpp"
49-
#include "opencv2/objdetect.hpp"
49+
#include "opencv2/xobjdetect.hpp"
5050

5151
namespace opencv_test { using namespace perf; }
5252

modules/cudaobjdetect/src/precomp.hpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@
4848
#include "opencv2/cudaobjdetect.hpp"
4949
#include "opencv2/cudaarithm.hpp"
5050
#include "opencv2/cudawarping.hpp"
51-
#include "opencv2/objdetect.hpp"
51+
#include "opencv2/xobjdetect.hpp"
5252

5353
#include "opencv2/core/private.cuda.hpp"
5454
#include "opencv2/core/utility.hpp"

modules/cudaobjdetect/test/test_precomp.hpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@
4848
#include "opencv2/ts/cuda_test.hpp"
4949

5050
#include "opencv2/cudaobjdetect.hpp"
51-
#include "opencv2/objdetect.hpp"
51+
#include "opencv2/xobjdetect.hpp"
5252

5353
#include "cvconfig.h"
5454

modules/face/CMakeLists.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
set(the_description "Face recognition etc")
22
ocv_define_module(face opencv_core
33
opencv_imgproc
4-
opencv_objdetect
4+
opencv_xobjdetect
55
opencv_3d # estimateAffinePartial2D() (trainFacemark)
66
opencv_photo # seamlessClone() (face_swap sample)
77
WRAP python java objc

modules/face/include/opencv2/face/facemark_train.hpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ Mentor: Delia Passalacqua
1313
#define __OPENCV_FACELANDMARKTRAIN_HPP__
1414

1515
#include "opencv2/face/facemark.hpp"
16-
#include "opencv2/objdetect.hpp"
16+
#include "opencv2/xobjdetect.hpp"
1717
#include <vector>
1818
#include <string>
1919

modules/face/samples/CMakeLists.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ add_executable(facerec_demo facerec_demo.cpp)
1313
target_link_libraries(facerec_demo opencv_core opencv_face opencv_imgproc opencv_highgui)
1414

1515
add_executable(facerec_video facerec_video.cpp)
16-
target_link_libraries(facerec_video opencv_face opencv_core opencv_imgproc opencv_highgui opencv_objdetect opencv_imgproc)
16+
target_link_libraries(facerec_video opencv_face opencv_core opencv_imgproc opencv_highgui opencv_xobjdetect opencv_imgproc)
1717

1818
add_executable(facerec_eigenfaces facerec_eigenfaces.cpp)
1919
target_link_libraries(facerec_eigenfaces opencv_face opencv_core opencv_imgproc opencv_highgui)

modules/face/samples/Facemark.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import org.opencv.face.*;
33
import org.opencv.imgcodecs.*;
44
import org.opencv.imgproc.*;
5-
import org.opencv.objdetect.*;
5+
import org.opencv.xobjdetect.*;
66
import java.util.*;
77

88

modules/face/samples/facerec_video.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
#include "opencv2/face.hpp"
2121
#include "opencv2/highgui.hpp"
2222
#include "opencv2/imgproc.hpp"
23-
#include "opencv2/objdetect.hpp"
23+
#include "opencv2/xobjdetect.hpp"
2424

2525
#include <iostream>
2626
#include <fstream>

modules/face/samples/mace_webcam.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
#include "opencv2/videoio.hpp"
66
#include "opencv2/highgui.hpp"
77
#include "opencv2/imgproc.hpp"
8-
#include "opencv2/objdetect.hpp"
8+
#include "opencv2/xobjdetect.hpp"
99
#include "opencv2/face/mace.hpp"
1010
#include <iostream>
1111
using namespace cv;

modules/face/samples/sampleDetectLandmarks.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
#include "opencv2/videoio.hpp"
33
#include "opencv2/highgui.hpp"
44
#include "opencv2/imgcodecs.hpp"
5-
#include "opencv2/objdetect.hpp"
5+
#include "opencv2/xobjdetect.hpp"
66
#include "opencv2/imgproc.hpp"
77
#include <iostream>
88
#include <vector>

modules/face/samples/sampleDetectLandmarksvideo.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
#include "opencv2/imgcodecs.hpp"
44
#include "opencv2/imgproc.hpp"
55
#include "opencv2/videoio.hpp"
6-
#include "opencv2/objdetect.hpp"
6+
#include "opencv2/xobjdetect.hpp"
77
#include <iostream>
88
#include <vector>
99
#include <string>

modules/face/samples/sample_face_swapping.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
#include "opencv2/imgproc.hpp"
33
#include "opencv2/imgcodecs.hpp"
44
#include "opencv2/highgui.hpp"
5-
#include "opencv2/objdetect.hpp"
5+
#include "opencv2/xobjdetect.hpp"
66
#include "opencv2/photo.hpp" // seamlessClone()
77
#include <iostream>
88
using namespace cv;

modules/face/samples/sample_train_landmark_detector.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#include "opencv2/face.hpp"
22
#include "opencv2/highgui.hpp"
33
#include "opencv2/imgcodecs.hpp"
4-
#include "opencv2/objdetect.hpp"
4+
#include "opencv2/xobjdetect.hpp"
55
#include "opencv2/imgproc.hpp"
66
#include <iostream>
77
#include <vector>

modules/face/samples/sample_train_landmark_detector2.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
#include "opencv2/highgui.hpp"
2424
#include "opencv2/imgproc.hpp"
2525
#include "opencv2/imgcodecs.hpp"
26-
#include "opencv2/objdetect.hpp"
26+
#include "opencv2/xobjdetect.hpp"
2727
#include <iostream>
2828
#include <vector>
2929
#include <string>

modules/face/test/test_precomp.hpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
#include "opencv2/ts.hpp"
88
#include "opencv2/imgproc.hpp"
9-
#include "opencv2/objdetect.hpp"
9+
#include "opencv2/xobjdetect.hpp"
1010
#include "opencv2/face.hpp"
1111
#include "opencv2/face/bif.hpp"
1212

modules/julia/gen/cpp_files/jlcv.hpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,9 @@ typedef KAZE::DiffusivityType KAZE_DiffusivityType;
5151
typedef ORB::ScoreType ORB_ScoreType;
5252
#endif
5353

54-
#ifdef HAVE_OPENCV_OBJDETECT
54+
#ifdef HAVE_OPENCV_XOBJDETECT
5555

56-
#include <opencv2/objdetect.hpp>
56+
#include <opencv2/xobjdetect.hpp>
5757

5858
typedef HOGDescriptor::HistogramNormType HOGDescriptor_HistogramNormType;
5959
typedef HOGDescriptor::DescriptorStorageFormat HOGDescriptor_DescriptorStorageFormat;

modules/xobjdetect/CMakeLists.txt

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
set(the_description "Object detection algorithms")
2-
ocv_define_module(xobjdetect opencv_core opencv_imgproc opencv_objdetect opencv_imgcodecs WRAP python)
2+
ocv_define_module(xobjdetect opencv_core opencv_imgproc opencv_imgcodecs opencv_features2d WRAP python java objc js)
33
if (BUILD_opencv_apps AND NOT APPLE_FRAMEWORK)
44
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/tools ${CMAKE_CURRENT_BINARY_DIR}/tools)
55
endif()
6+
add_subdirectory(data)
+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
file(GLOB HAAR_CASCADES haarcascades/*.xml)
2+
file(GLOB LBP_CASCADES lbpcascades/*.xml)
3+
4+
install(FILES ${HAAR_CASCADES} DESTINATION ${OPENCV_OTHER_INSTALL_PATH}/haarcascades COMPONENT libs)
5+
install(FILES ${LBP_CASCADES} DESTINATION ${OPENCV_OTHER_INSTALL_PATH}/lbpcascades COMPONENT libs)
6+
7+
if(INSTALL_TESTS AND OPENCV_TEST_DATA_PATH)
8+
install(DIRECTORY "${OPENCV_TEST_DATA_PATH}/" DESTINATION "${OPENCV_TEST_DATA_INSTALL_PATH}" COMPONENT "tests")
9+
endif()

0 commit comments

Comments
 (0)