Commit 26bcb381 authored by Andrey Kamaev's avatar Andrey Kamaev

Fix binary compatibility of opencv_contrib

parent 971d02cd
...@@ -857,6 +857,17 @@ namespace cv ...@@ -857,6 +857,17 @@ namespace cv
LDA(int num_components = 0) : LDA(int num_components = 0) :
_num_components(num_components) {}; _num_components(num_components) {};
// Initializes and performs a Discriminant Analysis with Fisher's
// Optimization Criterion on given data in src and corresponding labels
// in labels. If 0 (or less) number of components are given, they are
// automatically determined for given data in computation.
LDA(const Mat& src, vector<int> labels,
int num_components = 0) :
_num_components(num_components)
{
this->compute(src, labels); //! compute eigenvectors and eigenvalues
}
// Initializes and performs a Discriminant Analysis with Fisher's // Initializes and performs a Discriminant Analysis with Fisher's
// Optimization Criterion on given data in src and corresponding labels // Optimization Criterion on given data in src and corresponding labels
// in labels. If 0 (or less) number of components are given, they are // in labels. If 0 (or less) number of components are given, they are
...@@ -917,7 +928,7 @@ namespace cv ...@@ -917,7 +928,7 @@ namespace cv
CV_WRAP virtual void train(InputArrayOfArrays src, InputArray labels) = 0; CV_WRAP virtual void train(InputArrayOfArrays src, InputArray labels) = 0;
// Updates a FaceRecognizer. // Updates a FaceRecognizer.
CV_WRAP virtual void update(InputArrayOfArrays src, InputArray labels); CV_WRAP void update(InputArrayOfArrays src, InputArray labels);
// Gets a prediction from a FaceRecognizer. // Gets a prediction from a FaceRecognizer.
virtual int predict(InputArray src) const = 0; virtual int predict(InputArray src) const = 0;
......
...@@ -12,66 +12,17 @@ class DetectionBasedTracker ...@@ -12,66 +12,17 @@ class DetectionBasedTracker
public: public:
struct Parameters struct Parameters
{ {
int minObjectSize;
int maxObjectSize;
double scaleFactor;
int maxTrackLifetime; int maxTrackLifetime;
int minNeighbors;
int minDetectionPeriod; //the minimal time between run of the big object detector (on the whole frame) in ms (1000 mean 1 sec), default=0 int minDetectionPeriod; //the minimal time between run of the big object detector (on the whole frame) in ms (1000 mean 1 sec), default=0
Parameters(); Parameters();
}; };
class IDetector DetectionBasedTracker(const std::string& cascadeFilename, const Parameters& params);
{
public:
IDetector():
minObjSize(96, 96),
maxObjSize(INT_MAX, INT_MAX),
minNeighbours(2),
scaleFactor(1.1f)
{}
virtual ~IDetector() {}
virtual void detect(const cv::Mat& image, std::vector<cv::Rect>& objects) = 0;
void setMinObjectSize(const cv::Size& min)
{
minObjSize = min;
}
void setMaxObjectSize(const cv::Size& max)
{
maxObjSize = max;
}
cv::Size getMinObjectSize() const
{
return minObjSize;
}
cv::Size getMaxObjectSize() const
{
return maxObjSize;
}
float getScaleFactor()
{
return scaleFactor;
}
void setScaleFactor(float value)
{
scaleFactor = value;
}
int getMinNeighbours()
{
return minNeighbours;
}
void setMinNeighbours(int value)
{
minNeighbours = value;
}
protected:
cv::Size minObjSize;
cv::Size maxObjSize;
int minNeighbours;
float scaleFactor;
};
DetectionBasedTracker(cv::Ptr<IDetector> mainDetector, cv::Ptr<IDetector> trackingDetector, const Parameters& params);
virtual ~DetectionBasedTracker(); virtual ~DetectionBasedTracker();
virtual bool run(); virtual bool run();
...@@ -81,39 +32,19 @@ class DetectionBasedTracker ...@@ -81,39 +32,19 @@ class DetectionBasedTracker
virtual void process(const cv::Mat& imageGray); virtual void process(const cv::Mat& imageGray);
bool setParameters(const Parameters& params); bool setParameters(const Parameters& params);
const Parameters& getParameters() const; const Parameters& getParameters();
typedef std::pair<cv::Rect, int> Object; typedef std::pair<cv::Rect, int> Object;
virtual void getObjects(std::vector<cv::Rect>& result) const; virtual void getObjects(std::vector<cv::Rect>& result) const;
virtual void getObjects(std::vector<Object>& result) const; virtual void getObjects(std::vector<Object>& result) const;
enum ObjectStatus
{
DETECTED_NOT_SHOWN_YET,
DETECTED,
DETECTED_TEMPORARY_LOST,
WRONG_OBJECT
};
struct ExtObject
{
int id;
cv::Rect location;
ObjectStatus status;
ExtObject(int _id, cv::Rect _location, ObjectStatus _status)
:id(_id), location(_location), status(_status)
{
}
};
virtual void getObjects(std::vector<ExtObject>& result) const;
virtual int addObject(const cv::Rect& location); //returns id of the new object
protected: protected:
class SeparateDetectionWork; class SeparateDetectionWork;
cv::Ptr<SeparateDetectionWork> separateDetectionWork; cv::Ptr<SeparateDetectionWork> separateDetectionWork;
friend void* workcycleObjectDetectorFunction(void* p); friend void* workcycleObjectDetectorFunction(void* p);
struct InnerParameters struct InnerParameters
{ {
int numLastPositionsToTrack; int numLastPositionsToTrack;
...@@ -159,11 +90,11 @@ class DetectionBasedTracker ...@@ -159,11 +90,11 @@ class DetectionBasedTracker
std::vector<float> weightsPositionsSmoothing; std::vector<float> weightsPositionsSmoothing;
std::vector<float> weightsSizesSmoothing; std::vector<float> weightsSizesSmoothing;
cv::Ptr<IDetector> cascadeForTracking; cv::CascadeClassifier cascadeForTracking;
void updateTrackedObjects(const std::vector<cv::Rect>& detectedObjects); void updateTrackedObjects(const std::vector<cv::Rect>& detectedObjects);
cv::Rect calcTrackedObjectPositionToShow(int i) const; cv::Rect calcTrackedObjectPositionToShow(int i) const;
cv::Rect calcTrackedObjectPositionToShow(int i, ObjectStatus& status) const;
void detectInRegion(const cv::Mat& img, const cv::Rect& r, std::vector<cv::Rect>& detectedObjectsInRegions); void detectInRegion(const cv::Mat& img, const cv::Rect& r, std::vector<cv::Rect>& detectedObjectsInRegions);
}; };
......
...@@ -18,53 +18,6 @@ inline void vector_Rect_to_Mat(vector<Rect>& v_rect, Mat& mat) ...@@ -18,53 +18,6 @@ inline void vector_Rect_to_Mat(vector<Rect>& v_rect, Mat& mat)
mat = Mat(v_rect, true); mat = Mat(v_rect, true);
} }
class CascadeDetectorAdapter: public DetectionBasedTracker::IDetector
{
public:
CascadeDetectorAdapter(cv::Ptr<cv::CascadeClassifier> detector):
IDetector(),
Detector(detector)
{
LOGD("CascadeDetectorAdapter::Detect::Detect");
CV_Assert(!detector.empty());
}
void detect(const cv::Mat &Image, std::vector<cv::Rect> &objects)
{
LOGD("CascadeDetectorAdapter::Detect: begin");
LOGD("CascadeDetectorAdapter::Detect: scaleFactor=%.2f, minNeighbours=%d, minObjSize=(%dx%d), maxObjSize=(%dx%d)", scaleFactor, minNeighbours, minObjSize.width, minObjSize.height, maxObjSize.width, maxObjSize.height);
Detector->detectMultiScale(Image, objects, scaleFactor, minNeighbours, 0, minObjSize, maxObjSize);
LOGD("CascadeDetectorAdapter::Detect: end");
}
virtual ~CascadeDetectorAdapter()
{
LOGD("CascadeDetectorAdapter::Detect::~Detect");
}
private:
CascadeDetectorAdapter();
cv::Ptr<cv::CascadeClassifier> Detector;
};
struct DetectorAgregator
{
cv::Ptr<CascadeDetectorAdapter> mainDetector;
cv::Ptr<CascadeDetectorAdapter> trackingDetector;
cv::Ptr<DetectionBasedTracker> tracker;
DetectorAgregator(cv::Ptr<CascadeDetectorAdapter>& _mainDetector, cv::Ptr<CascadeDetectorAdapter>& _trackingDetector):
mainDetector(_mainDetector),
trackingDetector(_trackingDetector)
{
CV_Assert(!_mainDetector.empty());
CV_Assert(!_trackingDetector.empty());
DetectionBasedTracker::Parameters DetectorParams;
tracker = new DetectionBasedTracker(mainDetector.ptr<DetectionBasedTracker::IDetector>(), trackingDetector.ptr<DetectionBasedTracker::IDetector>(), DetectorParams);
}
};
JNIEXPORT jlong JNICALL Java_org_opencv_samples_fd_DetectionBasedTracker_nativeCreateObject JNIEXPORT jlong JNICALL Java_org_opencv_samples_fd_DetectionBasedTracker_nativeCreateObject
(JNIEnv * jenv, jclass, jstring jFileName, jint faceSize) (JNIEnv * jenv, jclass, jstring jFileName, jint faceSize)
{ {
...@@ -73,18 +26,12 @@ JNIEXPORT jlong JNICALL Java_org_opencv_samples_fd_DetectionBasedTracker_nativeC ...@@ -73,18 +26,12 @@ JNIEXPORT jlong JNICALL Java_org_opencv_samples_fd_DetectionBasedTracker_nativeC
string stdFileName(jnamestr); string stdFileName(jnamestr);
jlong result = 0; jlong result = 0;
LOGD("Java_org_opencv_samples_fd_DetectionBasedTracker_nativeCreateObject");
try try
{ {
cv::Ptr<CascadeDetectorAdapter> mainDetector = new CascadeDetectorAdapter(new CascadeClassifier(stdFileName)); DetectionBasedTracker::Parameters DetectorParams;
cv::Ptr<CascadeDetectorAdapter> trackingDetector = new CascadeDetectorAdapter(new CascadeClassifier(stdFileName));
result = (jlong)new DetectorAgregator(mainDetector, trackingDetector);
if (faceSize > 0) if (faceSize > 0)
{ DetectorParams.minObjectSize = faceSize;
mainDetector->setMinObjectSize(Size(faceSize, faceSize)); result = (jlong)new DetectionBasedTracker(stdFileName, DetectorParams);
//trackingDetector->setMinObjectSize(Size(faceSize, faceSize));
}
} }
catch(cv::Exception e) catch(cv::Exception e)
{ {
...@@ -98,7 +45,7 @@ JNIEXPORT jlong JNICALL Java_org_opencv_samples_fd_DetectionBasedTracker_nativeC ...@@ -98,7 +45,7 @@ JNIEXPORT jlong JNICALL Java_org_opencv_samples_fd_DetectionBasedTracker_nativeC
{ {
LOGD("nativeCreateObject catched unknown exception"); LOGD("nativeCreateObject catched unknown exception");
jclass je = jenv->FindClass("java/lang/Exception"); jclass je = jenv->FindClass("java/lang/Exception");
jenv->ThrowNew(je, "Unknown exception in JNI code {Java_org_opencv_samples_fd_DetectionBasedTracker_nativeCreateObject(...)}"); jenv->ThrowNew(je, "Unknown exception in JNI code {highgui::VideoCapture_n_1VideoCapture__()}");
return 0; return 0;
} }
...@@ -109,14 +56,13 @@ JNIEXPORT jlong JNICALL Java_org_opencv_samples_fd_DetectionBasedTracker_nativeC ...@@ -109,14 +56,13 @@ JNIEXPORT jlong JNICALL Java_org_opencv_samples_fd_DetectionBasedTracker_nativeC
JNIEXPORT void JNICALL Java_org_opencv_samples_fd_DetectionBasedTracker_nativeDestroyObject JNIEXPORT void JNICALL Java_org_opencv_samples_fd_DetectionBasedTracker_nativeDestroyObject
(JNIEnv * jenv, jclass, jlong thiz) (JNIEnv * jenv, jclass, jlong thiz)
{ {
LOGD("Java_org_opencv_samples_fd_DetectionBasedTracker_nativeDestroyObject"); LOGD("Java_org_opencv_samples_fd_DetectionBasedTracker_nativeDestroyObject enter");
try try
{ {
if(thiz != 0) if(thiz != 0)
{ {
((DetectorAgregator*)thiz)->tracker->stop(); ((DetectionBasedTracker*)thiz)->stop();
delete (DetectorAgregator*)thiz; delete (DetectionBasedTracker*)thiz;
} }
} }
catch(cv::Exception e) catch(cv::Exception e)
...@@ -131,7 +77,7 @@ JNIEXPORT void JNICALL Java_org_opencv_samples_fd_DetectionBasedTracker_nativeDe ...@@ -131,7 +77,7 @@ JNIEXPORT void JNICALL Java_org_opencv_samples_fd_DetectionBasedTracker_nativeDe
{ {
LOGD("nativeDestroyObject catched unknown exception"); LOGD("nativeDestroyObject catched unknown exception");
jclass je = jenv->FindClass("java/lang/Exception"); jclass je = jenv->FindClass("java/lang/Exception");
jenv->ThrowNew(je, "Unknown exception in JNI code {Java_org_opencv_samples_fd_DetectionBasedTracker_nativeDestroyObject(...)}"); jenv->ThrowNew(je, "Unknown exception in JNI code {highgui::VideoCapture_n_1VideoCapture__()}");
} }
LOGD("Java_org_opencv_samples_fd_DetectionBasedTracker_nativeDestroyObject exit"); LOGD("Java_org_opencv_samples_fd_DetectionBasedTracker_nativeDestroyObject exit");
} }
...@@ -139,11 +85,10 @@ JNIEXPORT void JNICALL Java_org_opencv_samples_fd_DetectionBasedTracker_nativeDe ...@@ -139,11 +85,10 @@ JNIEXPORT void JNICALL Java_org_opencv_samples_fd_DetectionBasedTracker_nativeDe
JNIEXPORT void JNICALL Java_org_opencv_samples_fd_DetectionBasedTracker_nativeStart JNIEXPORT void JNICALL Java_org_opencv_samples_fd_DetectionBasedTracker_nativeStart
(JNIEnv * jenv, jclass, jlong thiz) (JNIEnv * jenv, jclass, jlong thiz)
{ {
LOGD("Java_org_opencv_samples_fd_DetectionBasedTracker_nativeStart"); LOGD("Java_org_opencv_samples_fd_DetectionBasedTracker_nativeStart enter");
try try
{ {
((DetectorAgregator*)thiz)->tracker->run(); ((DetectionBasedTracker*)thiz)->run();
} }
catch(cv::Exception e) catch(cv::Exception e)
{ {
...@@ -157,7 +102,7 @@ JNIEXPORT void JNICALL Java_org_opencv_samples_fd_DetectionBasedTracker_nativeSt ...@@ -157,7 +102,7 @@ JNIEXPORT void JNICALL Java_org_opencv_samples_fd_DetectionBasedTracker_nativeSt
{ {
LOGD("nativeStart catched unknown exception"); LOGD("nativeStart catched unknown exception");
jclass je = jenv->FindClass("java/lang/Exception"); jclass je = jenv->FindClass("java/lang/Exception");
jenv->ThrowNew(je, "Unknown exception in JNI code {Java_org_opencv_samples_fd_DetectionBasedTracker_nativeStart(...)}"); jenv->ThrowNew(je, "Unknown exception in JNI code {highgui::VideoCapture_n_1VideoCapture__()}");
} }
LOGD("Java_org_opencv_samples_fd_DetectionBasedTracker_nativeStart exit"); LOGD("Java_org_opencv_samples_fd_DetectionBasedTracker_nativeStart exit");
} }
...@@ -165,11 +110,10 @@ JNIEXPORT void JNICALL Java_org_opencv_samples_fd_DetectionBasedTracker_nativeSt ...@@ -165,11 +110,10 @@ JNIEXPORT void JNICALL Java_org_opencv_samples_fd_DetectionBasedTracker_nativeSt
JNIEXPORT void JNICALL Java_org_opencv_samples_fd_DetectionBasedTracker_nativeStop JNIEXPORT void JNICALL Java_org_opencv_samples_fd_DetectionBasedTracker_nativeStop
(JNIEnv * jenv, jclass, jlong thiz) (JNIEnv * jenv, jclass, jlong thiz)
{ {
LOGD("Java_org_opencv_samples_fd_DetectionBasedTracker_nativeStop"); LOGD("Java_org_opencv_samples_fd_DetectionBasedTracker_nativeStop enter");
try try
{ {
((DetectorAgregator*)thiz)->tracker->stop(); ((DetectionBasedTracker*)thiz)->stop();
} }
catch(cv::Exception e) catch(cv::Exception e)
{ {
...@@ -183,7 +127,7 @@ JNIEXPORT void JNICALL Java_org_opencv_samples_fd_DetectionBasedTracker_nativeSt ...@@ -183,7 +127,7 @@ JNIEXPORT void JNICALL Java_org_opencv_samples_fd_DetectionBasedTracker_nativeSt
{ {
LOGD("nativeStop catched unknown exception"); LOGD("nativeStop catched unknown exception");
jclass je = jenv->FindClass("java/lang/Exception"); jclass je = jenv->FindClass("java/lang/Exception");
jenv->ThrowNew(je, "Unknown exception in JNI code {Java_org_opencv_samples_fd_DetectionBasedTracker_nativeStop(...)}"); jenv->ThrowNew(je, "Unknown exception in JNI code {highgui::VideoCapture_n_1VideoCapture__()}");
} }
LOGD("Java_org_opencv_samples_fd_DetectionBasedTracker_nativeStop exit"); LOGD("Java_org_opencv_samples_fd_DetectionBasedTracker_nativeStop exit");
} }
...@@ -191,14 +135,15 @@ JNIEXPORT void JNICALL Java_org_opencv_samples_fd_DetectionBasedTracker_nativeSt ...@@ -191,14 +135,15 @@ JNIEXPORT void JNICALL Java_org_opencv_samples_fd_DetectionBasedTracker_nativeSt
JNIEXPORT void JNICALL Java_org_opencv_samples_fd_DetectionBasedTracker_nativeSetFaceSize JNIEXPORT void JNICALL Java_org_opencv_samples_fd_DetectionBasedTracker_nativeSetFaceSize
(JNIEnv * jenv, jclass, jlong thiz, jint faceSize) (JNIEnv * jenv, jclass, jlong thiz, jint faceSize)
{ {
LOGD("Java_org_opencv_samples_fd_DetectionBasedTracker_nativeSetFaceSize -- BEGIN"); LOGD("Java_org_opencv_samples_fd_DetectionBasedTracker_nativeSetFaceSize enter");
try try
{ {
if (faceSize > 0) if (faceSize > 0)
{ {
((DetectorAgregator*)thiz)->mainDetector->setMinObjectSize(Size(faceSize, faceSize)); DetectionBasedTracker::Parameters DetectorParams = \
//((DetectorAgregator*)thiz)->trackingDetector->setMinObjectSize(Size(faceSize, faceSize)); ((DetectionBasedTracker*)thiz)->getParameters();
DetectorParams.minObjectSize = faceSize;
((DetectionBasedTracker*)thiz)->setParameters(DetectorParams);
} }
} }
catch(cv::Exception e) catch(cv::Exception e)
...@@ -213,23 +158,22 @@ JNIEXPORT void JNICALL Java_org_opencv_samples_fd_DetectionBasedTracker_nativeSe ...@@ -213,23 +158,22 @@ JNIEXPORT void JNICALL Java_org_opencv_samples_fd_DetectionBasedTracker_nativeSe
{ {
LOGD("nativeSetFaceSize catched unknown exception"); LOGD("nativeSetFaceSize catched unknown exception");
jclass je = jenv->FindClass("java/lang/Exception"); jclass je = jenv->FindClass("java/lang/Exception");
jenv->ThrowNew(je, "Unknown exception in JNI code {Java_org_opencv_samples_fd_DetectionBasedTracker_nativeSetFaceSize(...)}"); jenv->ThrowNew(je, "Unknown exception in JNI code {highgui::VideoCapture_n_1VideoCapture__()}");
} }
LOGD("Java_org_opencv_samples_fd_DetectionBasedTracker_nativeSetFaceSize -- END"); LOGD("Java_org_opencv_samples_fd_DetectionBasedTracker_nativeSetFaceSize exit");
} }
JNIEXPORT void JNICALL Java_org_opencv_samples_fd_DetectionBasedTracker_nativeDetect JNIEXPORT void JNICALL Java_org_opencv_samples_fd_DetectionBasedTracker_nativeDetect
(JNIEnv * jenv, jclass, jlong thiz, jlong imageGray, jlong faces) (JNIEnv * jenv, jclass, jlong thiz, jlong imageGray, jlong faces)
{ {
LOGD("Java_org_opencv_samples_fd_DetectionBasedTracker_nativeDetect"); LOGD("Java_org_opencv_samples_fd_DetectionBasedTracker_nativeDetect enter");
try try
{ {
vector<Rect> RectFaces; vector<Rect> RectFaces;
((DetectorAgregator*)thiz)->tracker->process(*((Mat*)imageGray)); ((DetectionBasedTracker*)thiz)->process(*((Mat*)imageGray));
((DetectorAgregator*)thiz)->tracker->getObjects(RectFaces); ((DetectionBasedTracker*)thiz)->getObjects(RectFaces);
*((Mat*)faces) = Mat(RectFaces, true); vector_Rect_to_Mat(RectFaces, *((Mat*)faces));
} }
catch(cv::Exception e) catch(cv::Exception e)
{ {
...@@ -243,7 +187,7 @@ JNIEXPORT void JNICALL Java_org_opencv_samples_fd_DetectionBasedTracker_nativeDe ...@@ -243,7 +187,7 @@ JNIEXPORT void JNICALL Java_org_opencv_samples_fd_DetectionBasedTracker_nativeDe
{ {
LOGD("nativeDetect catched unknown exception"); LOGD("nativeDetect catched unknown exception");
jclass je = jenv->FindClass("java/lang/Exception"); jclass je = jenv->FindClass("java/lang/Exception");
jenv->ThrowNew(je, "Unknown exception in JNI code {Java_org_opencv_samples_fd_DetectionBasedTracker_nativeDetect(...)}"); jenv->ThrowNew(je, "Unknown exception in JNI code {highgui::VideoCapture_n_1VideoCapture__()}");
} }
LOGD("Java_org_opencv_samples_fd_DetectionBasedTracker_nativeDetect END"); LOGD("Java_org_opencv_samples_fd_DetectionBasedTracker_nativeDetect exit");
} }
\ No newline at end of file
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