Commit 67838a7a authored by Andrey Kamaev's avatar Andrey Kamaev

Made dependency of opencv_objdetect from opencv_highgui optional.

parent e1378aad
set(the_description "Object Detection") set(the_description "Object Detection")
ocv_define_module(objdetect opencv_highgui opencv_calib3d) ocv_define_module(objdetect opencv_calib3d OPTIONAL opencv_highgui)
...@@ -388,7 +388,9 @@ int showRootFilterBoxes(IplImage *image, ...@@ -388,7 +388,9 @@ int showRootFilterBoxes(IplImage *image,
cvRectangle(image, points[i], oppositePoint, cvRectangle(image, points[i], oppositePoint,
color, thickness, line_type, shift); color, thickness, line_type, shift);
} }
#ifdef HAVE_OPENCV_HIGHGUI
cvShowImage("Initial image", image); cvShowImage("Initial image", image);
#endif
return LATENT_SVM_OK; return LATENT_SVM_OK;
} }
...@@ -442,7 +444,9 @@ int showPartFilterBoxes(IplImage *image, ...@@ -442,7 +444,9 @@ int showPartFilterBoxes(IplImage *image,
color, thickness, line_type, shift); color, thickness, line_type, shift);
} }
} }
#ifdef HAVE_OPENCV_HIGHGUI
cvShowImage("Initial image", image); cvShowImage("Initial image", image);
#endif
return LATENT_SVM_OK; return LATENT_SVM_OK;
} }
...@@ -476,7 +480,9 @@ int showBoxes(IplImage *img, ...@@ -476,7 +480,9 @@ int showBoxes(IplImage *img,
cvRectangle(img, points[i], oppositePoints[i], cvRectangle(img, points[i], oppositePoints[i],
color, thickness, line_type, shift); color, thickness, line_type, shift);
} }
#ifdef HAVE_OPENCV_HIGHGUI
cvShowImage("Initial image", img); cvShowImage("Initial image", img);
#endif
return LATENT_SVM_OK; return LATENT_SVM_OK;
} }
......
#include "precomp.hpp" #include "precomp.hpp"
#include "_lsvmparser.h" #include "_lsvmparser.h"
#include "_lsvm_matching.h" #include "_lsvm_matching.h"
/* /*
// load trained detector from a file // load trained detector from a file
...@@ -8,34 +8,34 @@ ...@@ -8,34 +8,34 @@
// API // API
// CvLatentSvmDetector* cvLoadLatentSvmDetector(const char* filename); // CvLatentSvmDetector* cvLoadLatentSvmDetector(const char* filename);
// INPUT // INPUT
// filename - path to the file containing the parameters of // filename - path to the file containing the parameters of
// - trained Latent SVM detector // - trained Latent SVM detector
// OUTPUT // OUTPUT
// trained Latent SVM detector in internal representation // trained Latent SVM detector in internal representation
*/ */
CvLatentSvmDetector* cvLoadLatentSvmDetector(const char* filename) CvLatentSvmDetector* cvLoadLatentSvmDetector(const char* filename)
{ {
CvLatentSvmDetector* detector = 0; CvLatentSvmDetector* detector = 0;
CvLSVMFilterObject** filters = 0; CvLSVMFilterObject** filters = 0;
int kFilters = 0; int kFilters = 0;
int kComponents = 0; int kComponents = 0;
int* kPartFilters = 0; int* kPartFilters = 0;
float* b = 0; float* b = 0;
float scoreThreshold = 0.f; float scoreThreshold = 0.f;
int err_code = 0; int err_code = 0;
err_code = loadModel(filename, &filters, &kFilters, &kComponents, &kPartFilters, &b, &scoreThreshold); err_code = loadModel(filename, &filters, &kFilters, &kComponents, &kPartFilters, &b, &scoreThreshold);
if (err_code != LATENT_SVM_OK) return 0; if (err_code != LATENT_SVM_OK) return 0;
detector = (CvLatentSvmDetector*)malloc(sizeof(CvLatentSvmDetector)); detector = (CvLatentSvmDetector*)malloc(sizeof(CvLatentSvmDetector));
detector->filters = filters; detector->filters = filters;
detector->b = b; detector->b = b;
detector->num_components = kComponents; detector->num_components = kComponents;
detector->num_filters = kFilters; detector->num_filters = kFilters;
detector->num_part_filters = kPartFilters; detector->num_part_filters = kPartFilters;
detector->score_threshold = scoreThreshold; detector->score_threshold = scoreThreshold;
return detector; return detector;
} }
/* /*
...@@ -44,68 +44,70 @@ CvLatentSvmDetector* cvLoadLatentSvmDetector(const char* filename) ...@@ -44,68 +44,70 @@ CvLatentSvmDetector* cvLoadLatentSvmDetector(const char* filename)
// API // API
// void cvReleaseLatentSvmDetector(CvLatentSvmDetector** detector); // void cvReleaseLatentSvmDetector(CvLatentSvmDetector** detector);
// INPUT // INPUT
// detector - CvLatentSvmDetector structure to be released // detector - CvLatentSvmDetector structure to be released
// OUTPUT // OUTPUT
*/ */
void cvReleaseLatentSvmDetector(CvLatentSvmDetector** detector) void cvReleaseLatentSvmDetector(CvLatentSvmDetector** detector)
{ {
free((*detector)->b); free((*detector)->b);
free((*detector)->num_part_filters); free((*detector)->num_part_filters);
for (int i = 0; i < (*detector)->num_filters; i++) for (int i = 0; i < (*detector)->num_filters; i++)
{ {
free((*detector)->filters[i]->H); free((*detector)->filters[i]->H);
free((*detector)->filters[i]); free((*detector)->filters[i]);
} }
free((*detector)->filters); free((*detector)->filters);
free((*detector)); free((*detector));
*detector = 0; *detector = 0;
} }
/* /*
// find rectangular regions in the given image that are likely // find rectangular regions in the given image that are likely
// to contain objects and corresponding confidence levels // to contain objects and corresponding confidence levels
// //
// API // API
// CvSeq* cvLatentSvmDetectObjects(const IplImage* image, // CvSeq* cvLatentSvmDetectObjects(const IplImage* image,
// CvLatentSvmDetector* detector, // CvLatentSvmDetector* detector,
// CvMemStorage* storage, // CvMemStorage* storage,
// float overlap_threshold = 0.5f, // float overlap_threshold = 0.5f,
int numThreads = -1); int numThreads = -1);
// INPUT // INPUT
// image - image to detect objects in // image - image to detect objects in
// detector - Latent SVM detector in internal representation // detector - Latent SVM detector in internal representation
// storage - memory storage to store the resultant sequence // storage - memory storage to store the resultant sequence
// of the object candidate rectangles // of the object candidate rectangles
// overlap_threshold - threshold for the non-maximum suppression algorithm [here will be the reference to original paper] // overlap_threshold - threshold for the non-maximum suppression algorithm [here will be the reference to original paper]
// OUTPUT // OUTPUT
// sequence of detected objects (bounding boxes and confidence levels stored in CvObjectDetection structures) // sequence of detected objects (bounding boxes and confidence levels stored in CvObjectDetection structures)
*/ */
CvSeq* cvLatentSvmDetectObjects(IplImage* image, CvSeq* cvLatentSvmDetectObjects(IplImage* image,
CvLatentSvmDetector* detector, CvLatentSvmDetector* detector,
CvMemStorage* storage, CvMemStorage* storage,
float overlap_threshold, int numThreads) float overlap_threshold, int numThreads)
{ {
CvLSVMFeaturePyramid *H = 0; CvLSVMFeaturePyramid *H = 0;
CvPoint *points = 0, *oppPoints = 0; CvPoint *points = 0, *oppPoints = 0;
int kPoints = 0; int kPoints = 0;
float *score = 0; float *score = 0;
unsigned int maxXBorder = 0, maxYBorder = 0; unsigned int maxXBorder = 0, maxYBorder = 0;
int numBoxesOut = 0; int numBoxesOut = 0;
CvPoint *pointsOut = 0; CvPoint *pointsOut = 0;
CvPoint *oppPointsOut = 0; CvPoint *oppPointsOut = 0;
float *scoreOut = 0; float *scoreOut = 0;
CvSeq* result_seq = 0; CvSeq* result_seq = 0;
int error = 0; int error = 0;
cvConvertImage(image, image, CV_CVTIMG_SWAP_RB); if(image->nChannels == 3)
cvCvtColor(image, image, CV_BGR2RGB);
// Getting maximum filter dimensions // Getting maximum filter dimensions
getMaxFilterDims((const CvLSVMFilterObject**)(detector->filters), detector->num_components, getMaxFilterDims((const CvLSVMFilterObject**)(detector->filters), detector->num_components,
detector->num_part_filters, &maxXBorder, &maxYBorder); detector->num_part_filters, &maxXBorder, &maxYBorder);
// Create feature pyramid with nullable border // Create feature pyramid with nullable border
H = createFeaturePyramidWithBorder(image, maxXBorder, maxYBorder); H = createFeaturePyramidWithBorder(image, maxXBorder, maxYBorder);
// Search object // Search object
error = searchObjectThresholdSomeComponents(H, (const CvLSVMFilterObject**)(detector->filters), error = searchObjectThresholdSomeComponents(H, (const CvLSVMFilterObject**)(detector->filters),
detector->num_components, detector->num_part_filters, detector->b, detector->score_threshold, detector->num_components, detector->num_part_filters, detector->b, detector->score_threshold,
&points, &oppPoints, &score, &kPoints, numThreads); &points, &oppPoints, &score, &kPoints, numThreads);
if (error != LATENT_SVM_OK) if (error != LATENT_SVM_OK)
{ {
...@@ -118,28 +120,30 @@ CvSeq* cvLatentSvmDetectObjects(IplImage* image, ...@@ -118,28 +120,30 @@ CvSeq* cvLatentSvmDetectObjects(IplImage* image,
nonMaximumSuppression(kPoints, points, oppPoints, score, overlap_threshold, nonMaximumSuppression(kPoints, points, oppPoints, score, overlap_threshold,
&numBoxesOut, &pointsOut, &oppPointsOut, &scoreOut); &numBoxesOut, &pointsOut, &oppPointsOut, &scoreOut);
result_seq = cvCreateSeq( 0, sizeof(CvSeq), sizeof(CvObjectDetection), storage ); result_seq = cvCreateSeq( 0, sizeof(CvSeq), sizeof(CvObjectDetection), storage );
for (int i = 0; i < numBoxesOut; i++) for (int i = 0; i < numBoxesOut; i++)
{ {
CvObjectDetection detection = {{0, 0, 0, 0}, 0}; CvObjectDetection detection = {{0, 0, 0, 0}, 0};
detection.score = scoreOut[i]; detection.score = scoreOut[i];
CvRect bounding_box = {0, 0, 0, 0}; CvRect bounding_box = {0, 0, 0, 0};
bounding_box.x = pointsOut[i].x; bounding_box.x = pointsOut[i].x;
bounding_box.y = pointsOut[i].y; bounding_box.y = pointsOut[i].y;
bounding_box.width = oppPointsOut[i].x - pointsOut[i].x; bounding_box.width = oppPointsOut[i].x - pointsOut[i].x;
bounding_box.height = oppPointsOut[i].y - pointsOut[i].y; bounding_box.height = oppPointsOut[i].y - pointsOut[i].y;
detection.rect = bounding_box; detection.rect = bounding_box;
cvSeqPush(result_seq, &detection); cvSeqPush(result_seq, &detection);
} }
cvConvertImage(image, image, CV_CVTIMG_SWAP_RB);
if(image->nChannels == 3)
cvCvtColor(image, image, CV_RGB2BGR);
freeFeaturePyramidObject(&H); freeFeaturePyramidObject(&H);
free(points); free(points);
free(oppPoints); free(oppPoints);
free(score); free(score);
return result_seq; return result_seq;
} }
namespace cv namespace cv
......
...@@ -55,11 +55,15 @@ ...@@ -55,11 +55,15 @@
#include "opencv2/imgproc/imgproc.hpp" #include "opencv2/imgproc/imgproc.hpp"
#include "opencv2/imgproc/imgproc_c.h" #include "opencv2/imgproc/imgproc_c.h"
#include "opencv2/core/core_c.h" #include "opencv2/core/core_c.h"
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/core/internal.hpp" #include "opencv2/core/internal.hpp"
#include "opencv2/features2d/features2d.hpp" #include "opencv2/features2d/features2d.hpp"
#include "opencv2/calib3d/calib3d.hpp" #include "opencv2/calib3d/calib3d.hpp"
#include "opencv2/opencv_modules.hpp"
#ifdef HAVE_OPENCV_HIGHGUI
# include "opencv2/highgui/highgui.hpp"
#endif
#ifdef HAVE_TEGRA_OPTIMIZATION #ifdef HAVE_TEGRA_OPTIMIZATION
#include "opencv2/objdetect/objdetect_tegra.hpp" #include "opencv2/objdetect/objdetect_tegra.hpp"
#endif #endif
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment