Skip to content

Commit

Permalink
Move objdetect HaarCascadeClassifier and HOGDescriptor to contrib xob…
Browse files Browse the repository at this point in the history
…jdetect (#3692)

* Move objdetect parts to contrib

* Move objdetect parts to contrib

* Fix errors from CI build.

* Minor fixes.
  • Loading branch information
kaingwade authored Mar 21, 2024
1 parent 8f3a61b commit 3f609aa
Show file tree
Hide file tree
Showing 150 changed files with 758,910 additions and 78 deletions.
2 changes: 1 addition & 1 deletion modules/cudalegacy/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ if(ENABLE_CUDA_FIRST_CLASS_LANGUAGE)
ocv_module_include_directories(${CUDAToolkit_INCLUDE_DIRS})
endif()
ocv_define_module(cudalegacy opencv_core opencv_video
OPTIONAL opencv_objdetect opencv_imgproc opencv_3d opencv_stereo opencv_calib opencv_cudaarithm opencv_cudafilters opencv_cudaimgproc)
OPTIONAL opencv_objdetect opencv_xobjdetect opencv_imgproc opencv_3d opencv_stereo opencv_calib opencv_cudaarithm opencv_cudafilters opencv_cudaimgproc)
4 changes: 2 additions & 2 deletions modules/cudalegacy/src/NCV.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -737,12 +737,12 @@ struct RectConvert

static void groupRectangles(std::vector<NcvRect32u> &hypotheses, int groupThreshold, double eps, std::vector<Ncv32u> *weights)
{
#ifndef HAVE_OPENCV_OBJDETECT
#ifndef HAVE_OPENCV_XOBJDETECT
CV_UNUSED(hypotheses);
CV_UNUSED(groupThreshold);
CV_UNUSED(eps);
CV_UNUSED(weights);
CV_Error(cv::Error::StsNotImplemented, "This functionality requires objdetect module");
CV_Error(cv::Error::StsNotImplemented, "This functionality requires xobjdetect module");
#else
std::vector<cv::Rect> rects(hypotheses.size());
std::transform(hypotheses.begin(), hypotheses.end(), rects.begin(), RectConvert());
Expand Down
90 changes: 45 additions & 45 deletions modules/cudalegacy/src/cuda/NCVHaarObjectDetection.cu
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@

#include "opencv2/opencv_modules.hpp"

#ifdef HAVE_OPENCV_OBJDETECT
# include "opencv2/objdetect.hpp"
#ifdef HAVE_OPENCV_XOBJDETECT
# include "opencv2/xobjdetect.hpp"
//# include "opencv2/objdetect/objdetect_c.h"
#endif

Expand Down Expand Up @@ -1843,16 +1843,16 @@ static NCVStatus loadFromXML(const cv::String &filename,
std::vector<HaarClassifierNode128> &haarClassifierNodes,
std::vector<HaarFeature64> &haarFeatures)
{
const char *CUDA_CC_SIZE = "size";
const char *CUDA_CC_STAGES = "stages";
const char *CUDA_CC_STAGE_THRESHOLD = "stage_threshold";
const char *CUDA_CC_TREES = "trees";
const char *CUDA_CC_FEATURE = "feature";
const char *CUDA_CC_RECT = "rects";
const char *CUDA_CC_TILTED = "tilted";
const char *CUDA_CC_THRESHOLD = "threshold";
const char *CUDA_CC_SIZE = "size";
const char *CUDA_CC_STAGES = "stages";
const char *CUDA_CC_STAGE_THRESHOLD = "stage_threshold";
const char *CUDA_CC_TREES = "trees";
const char *CUDA_CC_FEATURE = "feature";
const char *CUDA_CC_RECT = "rects";
const char *CUDA_CC_TILTED = "tilted";
const char *CUDA_CC_THRESHOLD = "threshold";
const char *CUDA_CC_LEFT_VAL = "left_val";
const char *CUDA_CC_RIGHT_VAL = "right_val";
const char *CUDA_CC_RIGHT_VAL = "right_val";
const char *CUDA_CC_LEFT_NODE = "left_node";
const char *CUDA_CC_RIGHT_NODE = "right_node";

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

cv::FileStorage fs(filename, cv::FileStorage::READ | cv::FileStorage::FORMAT_XML);

if (!fs.isOpened())
cv::FileStorage fs(filename, cv::FileStorage::READ | cv::FileStorage::FORMAT_XML);

if (!fs.isOpened())
return NCV_FILE_ERROR;

const cv::FileNode &root = fs.getFirstTopLevelNode();
const cv::FileNode &root = fs.getFirstTopLevelNode();
const cv::FileNode &fnSize = root[CUDA_CC_SIZE];

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

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

for (; it != it_end; ++it) // by stages
{
cv::FileNode fnStage = *it;
for (; it != it_end; ++it) // by stages
{
cv::FileNode fnStage = *it;
HaarStage64 curStage;

curStage.setStartClassifierRootNodeOffset(static_cast<Ncv32u>(haarClassifierNodes.size()));
curStage.setStartClassifierRootNodeOffset(static_cast<Ncv32u>(haarClassifierNodes.size()));
curStage.setStageThreshold((float)fnStage[CUDA_CC_STAGE_THRESHOLD]);

// iterate over the trees
const cv::FileNode &fnTrees = fnStage[CUDA_CC_TREES];
cv::FileNodeIterator it1 = fnTrees.begin(), it1_end = fnTrees.end();

for (; it1 != it1_end; ++it1) // by trees
{
cv::FileNode tree = *it1;
Ncv32u nodeId = (size_t)0;
HaarClassifierNode128 curNode;

curNode.setThreshold((float)tree[0][CUDA_CC_THRESHOLD]);

NcvBool bIsLeftNodeLeaf = false;
NcvBool bIsRightNodeLeaf = false;

// iterate over the trees
const cv::FileNode &fnTrees = fnStage[CUDA_CC_TREES];
cv::FileNodeIterator it1 = fnTrees.begin(), it1_end = fnTrees.end();

for (; it1 != it1_end; ++it1) // by trees
{
cv::FileNode tree = *it1;
Ncv32u nodeId = (size_t)0;
HaarClassifierNode128 curNode;

curNode.setThreshold((float)tree[0][CUDA_CC_THRESHOLD]);

NcvBool bIsLeftNodeLeaf = false;
NcvBool bIsRightNodeLeaf = false;

HaarClassifierNodeDescriptor32 nodeLeft;

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

if (leftNode.fs == NULL)
{
Ncv32f leftVal = tree[0][CUDA_CC_LEFT_VAL];
ncvStat = nodeLeft.create(leftVal);
Ncv32f leftVal = tree[0][CUDA_CC_LEFT_VAL];
ncvStat = nodeLeft.create(leftVal);
ncvAssertReturn(ncvStat == NCV_SUCCESS, ncvStat);
bIsLeftNodeLeaf = true;
}
else
{
Ncv32u leftNodeOffset = (int)tree[0][CUDA_CC_LEFT_NODE];
nodeLeft.create((Ncv32u)(h_TmpClassifierNotRootNodes.size() + leftNodeOffset - 1));
Ncv32u leftNodeOffset = (int)tree[0][CUDA_CC_LEFT_NODE];
nodeLeft.create((Ncv32u)(h_TmpClassifierNotRootNodes.size() + leftNodeOffset - 1));
haar.bHasStumpsOnly = false;
}

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

if (rightNode.fs == NULL)
{
Ncv32f rightVal = tree[0][CUDA_CC_RIGHT_VAL];
ncvStat = nodeRight.create(rightVal);
Ncv32f rightVal = tree[0][CUDA_CC_RIGHT_VAL];
ncvStat = nodeRight.create(rightVal);
ncvAssertReturn(ncvStat == NCV_SUCCESS, ncvStat);
bIsRightNodeLeaf = true;
}
else
{
Ncv32u rightNodeOffset = (int)tree[0][CUDA_CC_RIGHT_NODE];
nodeRight.create((Ncv32u)(h_TmpClassifierNotRootNodes.size() + rightNodeOffset - 1));
Ncv32u rightNodeOffset = (int)tree[0][CUDA_CC_RIGHT_NODE];
nodeRight.create((Ncv32u)(h_TmpClassifierNotRootNodes.size() + rightNodeOffset - 1));
haar.bHasStumpsOnly = false;
}

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

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

Ncv32u featureId = 0;
Ncv32u featureId = 0;
for (; it2 != it2_end; ++it2) // by feature
{
cv::FileNode rect = *it2;
Expand Down
4 changes: 4 additions & 0 deletions modules/cudalegacy/src/precomp.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,10 @@
# include "opencv2/objdetect.hpp"
#endif

#ifdef HAVE_OPENCV_XOBJDETECT
# include "opencv2/xobjdetect.hpp"
#endif

#ifdef HAVE_OPENCV_3D
# include "opencv2/3d.hpp"
#endif
Expand Down
2 changes: 1 addition & 1 deletion modules/cudaobjdetect/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ set(the_description "CUDA-accelerated Object Detection")

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

ocv_define_module(cudaobjdetect opencv_objdetect opencv_cudaarithm opencv_cudawarping OPTIONAL opencv_cudalegacy WRAP python)
ocv_define_module(cudaobjdetect opencv_objdetect opencv_xobjdetect opencv_cudaarithm opencv_cudawarping OPTIONAL opencv_cudalegacy WRAP python)
12 changes: 6 additions & 6 deletions modules/cudaobjdetect/include/opencv2/cudaobjdetect.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
#endif

#include "opencv2/core/cuda.hpp"
#include "opencv2/objdetect.hpp"
#include "opencv2/xobjdetect.hpp"

/**
@addtogroup cuda
Expand All @@ -70,11 +70,11 @@ namespace cv { namespace cuda {
@note
- An example applying the HOG descriptor for people detection can be found at
opencv_source_code/samples/cpp/peopledetect.cpp
xobjdetect_module/samples/peopledetect.cpp
- A CUDA example applying the HOG descriptor for people detection can be found at
opencv_source_code/samples/gpu/hog.cpp
xobjdetect_module/samples/gpu/hog.cpp
- (Python) An example applying the HOG descriptor for people detection can be found at
opencv_source_code/samples/python/peopledetect.py
xobjdetect_module/samples/python/peopledetect.py
*/
class CV_EXPORTS_W HOG : public Algorithm
{
Expand Down Expand Up @@ -222,8 +222,8 @@ class CV_EXPORTS_W HOG : public Algorithm
/** @brief Cascade classifier class used for object detection. Supports HAAR and LBP cascades. :
@note
- A cascade classifier example can be found at
opencv_source_code/samples/gpu/cascadeclassifier.cpp
- A cascade classifier example can be found at
xobjdetect_module/samples/gpu/cascadeclassifier.cpp
- A Nvidea API specific cascade classifier example can be found at
opencv_source_code/samples/gpu/cascadeclassifier_nvidia_api.cpp
*/
Expand Down
2 changes: 1 addition & 1 deletion modules/cudaobjdetect/perf/perf_precomp.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
#include "opencv2/ts/cuda_perf.hpp"

#include "opencv2/cudaobjdetect.hpp"
#include "opencv2/objdetect.hpp"
#include "opencv2/xobjdetect.hpp"

namespace opencv_test { using namespace perf; }

Expand Down
2 changes: 1 addition & 1 deletion modules/cudaobjdetect/src/precomp.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
#include "opencv2/cudaobjdetect.hpp"
#include "opencv2/cudaarithm.hpp"
#include "opencv2/cudawarping.hpp"
#include "opencv2/objdetect.hpp"
#include "opencv2/xobjdetect.hpp"

#include "opencv2/core/private.cuda.hpp"
#include "opencv2/core/utility.hpp"
Expand Down
2 changes: 1 addition & 1 deletion modules/cudaobjdetect/test/test_precomp.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
#include "opencv2/ts/cuda_test.hpp"

#include "opencv2/cudaobjdetect.hpp"
#include "opencv2/objdetect.hpp"
#include "opencv2/xobjdetect.hpp"

#include "cvconfig.h"

Expand Down
2 changes: 1 addition & 1 deletion modules/face/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
set(the_description "Face recognition etc")
ocv_define_module(face opencv_core
opencv_imgproc
opencv_objdetect
opencv_xobjdetect
opencv_3d # estimateAffinePartial2D() (trainFacemark)
opencv_photo # seamlessClone() (face_swap sample)
WRAP python java objc
Expand Down
2 changes: 1 addition & 1 deletion modules/face/include/opencv2/face/facemark_train.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ Mentor: Delia Passalacqua
#define __OPENCV_FACELANDMARKTRAIN_HPP__

#include "opencv2/face/facemark.hpp"
#include "opencv2/objdetect.hpp"
#include "opencv2/xobjdetect.hpp"
#include <vector>
#include <string>

Expand Down
2 changes: 1 addition & 1 deletion modules/face/samples/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ add_executable(facerec_demo facerec_demo.cpp)
target_link_libraries(facerec_demo opencv_core opencv_face opencv_imgproc opencv_highgui)

add_executable(facerec_video facerec_video.cpp)
target_link_libraries(facerec_video opencv_face opencv_core opencv_imgproc opencv_highgui opencv_objdetect opencv_imgproc)
target_link_libraries(facerec_video opencv_face opencv_core opencv_imgproc opencv_highgui opencv_xobjdetect opencv_imgproc)

add_executable(facerec_eigenfaces facerec_eigenfaces.cpp)
target_link_libraries(facerec_eigenfaces opencv_face opencv_core opencv_imgproc opencv_highgui)
Expand Down
2 changes: 1 addition & 1 deletion modules/face/samples/Facemark.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import org.opencv.face.*;
import org.opencv.imgcodecs.*;
import org.opencv.imgproc.*;
import org.opencv.objdetect.*;
import org.opencv.xobjdetect.*;
import java.util.*;


Expand Down
2 changes: 1 addition & 1 deletion modules/face/samples/facerec_video.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
#include "opencv2/face.hpp"
#include "opencv2/highgui.hpp"
#include "opencv2/imgproc.hpp"
#include "opencv2/objdetect.hpp"
#include "opencv2/xobjdetect.hpp"

#include <iostream>
#include <fstream>
Expand Down
2 changes: 1 addition & 1 deletion modules/face/samples/mace_webcam.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#include "opencv2/videoio.hpp"
#include "opencv2/highgui.hpp"
#include "opencv2/imgproc.hpp"
#include "opencv2/objdetect.hpp"
#include "opencv2/xobjdetect.hpp"
#include "opencv2/face/mace.hpp"
#include <iostream>
using namespace cv;
Expand Down
2 changes: 1 addition & 1 deletion modules/face/samples/sampleDetectLandmarks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#include "opencv2/videoio.hpp"
#include "opencv2/highgui.hpp"
#include "opencv2/imgcodecs.hpp"
#include "opencv2/objdetect.hpp"
#include "opencv2/xobjdetect.hpp"
#include "opencv2/imgproc.hpp"
#include <iostream>
#include <vector>
Expand Down
2 changes: 1 addition & 1 deletion modules/face/samples/sampleDetectLandmarksvideo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#include "opencv2/imgcodecs.hpp"
#include "opencv2/imgproc.hpp"
#include "opencv2/videoio.hpp"
#include "opencv2/objdetect.hpp"
#include "opencv2/xobjdetect.hpp"
#include <iostream>
#include <vector>
#include <string>
Expand Down
2 changes: 1 addition & 1 deletion modules/face/samples/sample_face_swapping.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#include "opencv2/imgproc.hpp"
#include "opencv2/imgcodecs.hpp"
#include "opencv2/highgui.hpp"
#include "opencv2/objdetect.hpp"
#include "opencv2/xobjdetect.hpp"
#include "opencv2/photo.hpp" // seamlessClone()
#include <iostream>
using namespace cv;
Expand Down
2 changes: 1 addition & 1 deletion modules/face/samples/sample_train_landmark_detector.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#include "opencv2/face.hpp"
#include "opencv2/highgui.hpp"
#include "opencv2/imgcodecs.hpp"
#include "opencv2/objdetect.hpp"
#include "opencv2/xobjdetect.hpp"
#include "opencv2/imgproc.hpp"
#include <iostream>
#include <vector>
Expand Down
2 changes: 1 addition & 1 deletion modules/face/samples/sample_train_landmark_detector2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
#include "opencv2/highgui.hpp"
#include "opencv2/imgproc.hpp"
#include "opencv2/imgcodecs.hpp"
#include "opencv2/objdetect.hpp"
#include "opencv2/xobjdetect.hpp"
#include <iostream>
#include <vector>
#include <string>
Expand Down
2 changes: 1 addition & 1 deletion modules/face/test/test_precomp.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

#include "opencv2/ts.hpp"
#include "opencv2/imgproc.hpp"
#include "opencv2/objdetect.hpp"
#include "opencv2/xobjdetect.hpp"
#include "opencv2/face.hpp"
#include "opencv2/face/bif.hpp"

Expand Down
4 changes: 2 additions & 2 deletions modules/julia/gen/cpp_files/jlcv.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,9 @@ typedef KAZE::DiffusivityType KAZE_DiffusivityType;
typedef ORB::ScoreType ORB_ScoreType;
#endif

#ifdef HAVE_OPENCV_OBJDETECT
#ifdef HAVE_OPENCV_XOBJDETECT

#include <opencv2/objdetect.hpp>
#include <opencv2/xobjdetect.hpp>

typedef HOGDescriptor::HistogramNormType HOGDescriptor_HistogramNormType;
typedef HOGDescriptor::DescriptorStorageFormat HOGDescriptor_DescriptorStorageFormat;
Expand Down
3 changes: 2 additions & 1 deletion modules/xobjdetect/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
set(the_description "Object detection algorithms")
ocv_define_module(xobjdetect opencv_core opencv_imgproc opencv_objdetect opencv_imgcodecs WRAP python)
ocv_define_module(xobjdetect opencv_core opencv_imgproc opencv_imgcodecs opencv_features2d WRAP python java objc js)
if (BUILD_opencv_apps AND NOT APPLE_FRAMEWORK)
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/tools ${CMAKE_CURRENT_BINARY_DIR}/tools)
endif()
add_subdirectory(data)
9 changes: 9 additions & 0 deletions modules/xobjdetect/data/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
file(GLOB HAAR_CASCADES haarcascades/*.xml)
file(GLOB LBP_CASCADES lbpcascades/*.xml)

install(FILES ${HAAR_CASCADES} DESTINATION ${OPENCV_OTHER_INSTALL_PATH}/haarcascades COMPONENT libs)
install(FILES ${LBP_CASCADES} DESTINATION ${OPENCV_OTHER_INSTALL_PATH}/lbpcascades COMPONENT libs)

if(INSTALL_TESTS AND OPENCV_TEST_DATA_PATH)
install(DIRECTORY "${OPENCV_TEST_DATA_PATH}/" DESTINATION "${OPENCV_TEST_DATA_INSTALL_PATH}" COMPONENT "tests")
endif()
Loading

0 comments on commit 3f609aa

Please sign in to comment.