revisions 8681 and 8688 restored. Warning fixed.
Warning: changes beak binary compatibility
This commit is contained in:
@@ -18,6 +18,29 @@ inline void vector_Rect_to_Mat(vector<Rect>& v_rect, Mat& mat)
|
||||
mat = Mat(v_rect, true);
|
||||
}
|
||||
|
||||
class CascadeDetectorAdapter: public DetectionBasedTracker::IDetector
|
||||
{
|
||||
public:
|
||||
CascadeDetectorAdapter(cv::Ptr<cv::CascadeClassifier> detector):
|
||||
IDetector(),
|
||||
Detector(detector)
|
||||
{
|
||||
CV_Assert(!detector.empty());
|
||||
}
|
||||
|
||||
void detect(const cv::Mat &Image, std::vector<cv::Rect> &objects)
|
||||
{
|
||||
Detector->detectMultiScale(Image, objects, scaleFactor, minNeighbours, 0, minObjSize, maxObjSize);
|
||||
}
|
||||
|
||||
virtual ~CascadeDetectorAdapter()
|
||||
{}
|
||||
|
||||
private:
|
||||
CascadeDetectorAdapter();
|
||||
cv::Ptr<cv::CascadeClassifier> Detector;
|
||||
};
|
||||
|
||||
JNIEXPORT jlong JNICALL Java_org_opencv_samples_fd_DetectionBasedTracker_nativeCreateObject
|
||||
(JNIEnv * jenv, jclass, jstring jFileName, jint faceSize)
|
||||
{
|
||||
@@ -27,25 +50,26 @@ JNIEXPORT jlong JNICALL Java_org_opencv_samples_fd_DetectionBasedTracker_nativeC
|
||||
|
||||
try
|
||||
{
|
||||
DetectionBasedTracker::Parameters DetectorParams;
|
||||
if (faceSize > 0)
|
||||
DetectorParams.minObjectSize = faceSize;
|
||||
result = (jlong)new DetectionBasedTracker(stdFileName, DetectorParams);
|
||||
// TODO: Reimplement using adapter
|
||||
// DetectionBasedTracker::Parameters DetectorParams;
|
||||
// if (faceSize > 0)
|
||||
// DetectorParams.minObjectSize = faceSize;
|
||||
// result = (jlong)new DetectionBasedTracker(stdFileName, DetectorParams);
|
||||
}
|
||||
catch(cv::Exception e)
|
||||
{
|
||||
LOGD("nativeCreateObject catched cv::Exception: %s", e.what());
|
||||
jclass je = jenv->FindClass("org/opencv/core/CvException");
|
||||
if(!je)
|
||||
je = jenv->FindClass("java/lang/Exception");
|
||||
jenv->ThrowNew(je, e.what());
|
||||
LOGD("nativeCreateObject catched cv::Exception: %s", e.what());
|
||||
jclass je = jenv->FindClass("org/opencv/core/CvException");
|
||||
if(!je)
|
||||
je = jenv->FindClass("java/lang/Exception");
|
||||
jenv->ThrowNew(je, e.what());
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
LOGD("nativeCreateObject catched unknown exception");
|
||||
jclass je = jenv->FindClass("java/lang/Exception");
|
||||
jenv->ThrowNew(je, "Unknown exception in JNI code {highgui::VideoCapture_n_1VideoCapture__()}");
|
||||
return 0;
|
||||
LOGD("nativeCreateObject catched unknown exception");
|
||||
jclass je = jenv->FindClass("java/lang/Exception");
|
||||
jenv->ThrowNew(je, "Unknown exception in JNI code {highgui::VideoCapture_n_1VideoCapture__()}");
|
||||
return 0;
|
||||
}
|
||||
|
||||
return result;
|
||||
@@ -56,22 +80,22 @@ JNIEXPORT void JNICALL Java_org_opencv_samples_fd_DetectionBasedTracker_nativeDe
|
||||
{
|
||||
try
|
||||
{
|
||||
((DetectionBasedTracker*)thiz)->stop();
|
||||
delete (DetectionBasedTracker*)thiz;
|
||||
((DetectionBasedTracker*)thiz)->stop();
|
||||
delete (DetectionBasedTracker*)thiz;
|
||||
}
|
||||
catch(cv::Exception e)
|
||||
{
|
||||
LOGD("nativeestroyObject catched cv::Exception: %s", e.what());
|
||||
jclass je = jenv->FindClass("org/opencv/core/CvException");
|
||||
if(!je)
|
||||
je = jenv->FindClass("java/lang/Exception");
|
||||
jenv->ThrowNew(je, e.what());
|
||||
LOGD("nativeestroyObject catched cv::Exception: %s", e.what());
|
||||
jclass je = jenv->FindClass("org/opencv/core/CvException");
|
||||
if(!je)
|
||||
je = jenv->FindClass("java/lang/Exception");
|
||||
jenv->ThrowNew(je, e.what());
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
LOGD("nativeDestroyObject catched unknown exception");
|
||||
jclass je = jenv->FindClass("java/lang/Exception");
|
||||
jenv->ThrowNew(je, "Unknown exception in JNI code {highgui::VideoCapture_n_1VideoCapture__()}");
|
||||
LOGD("nativeDestroyObject catched unknown exception");
|
||||
jclass je = jenv->FindClass("java/lang/Exception");
|
||||
jenv->ThrowNew(je, "Unknown exception in JNI code {highgui::VideoCapture_n_1VideoCapture__()}");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -80,21 +104,21 @@ JNIEXPORT void JNICALL Java_org_opencv_samples_fd_DetectionBasedTracker_nativeSt
|
||||
{
|
||||
try
|
||||
{
|
||||
((DetectionBasedTracker*)thiz)->run();
|
||||
((DetectionBasedTracker*)thiz)->run();
|
||||
}
|
||||
catch(cv::Exception e)
|
||||
{
|
||||
LOGD("nativeStart catched cv::Exception: %s", e.what());
|
||||
jclass je = jenv->FindClass("org/opencv/core/CvException");
|
||||
if(!je)
|
||||
je = jenv->FindClass("java/lang/Exception");
|
||||
jenv->ThrowNew(je, e.what());
|
||||
LOGD("nativeStart catched cv::Exception: %s", e.what());
|
||||
jclass je = jenv->FindClass("org/opencv/core/CvException");
|
||||
if(!je)
|
||||
je = jenv->FindClass("java/lang/Exception");
|
||||
jenv->ThrowNew(je, e.what());
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
LOGD("nativeStart catched unknown exception");
|
||||
jclass je = jenv->FindClass("java/lang/Exception");
|
||||
jenv->ThrowNew(je, "Unknown exception in JNI code {highgui::VideoCapture_n_1VideoCapture__()}");
|
||||
LOGD("nativeStart catched unknown exception");
|
||||
jclass je = jenv->FindClass("java/lang/Exception");
|
||||
jenv->ThrowNew(je, "Unknown exception in JNI code {highgui::VideoCapture_n_1VideoCapture__()}");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -103,21 +127,21 @@ JNIEXPORT void JNICALL Java_org_opencv_samples_fd_DetectionBasedTracker_nativeSt
|
||||
{
|
||||
try
|
||||
{
|
||||
((DetectionBasedTracker*)thiz)->stop();
|
||||
((DetectionBasedTracker*)thiz)->stop();
|
||||
}
|
||||
catch(cv::Exception e)
|
||||
{
|
||||
LOGD("nativeStop catched cv::Exception: %s", e.what());
|
||||
jclass je = jenv->FindClass("org/opencv/core/CvException");
|
||||
if(!je)
|
||||
je = jenv->FindClass("java/lang/Exception");
|
||||
jenv->ThrowNew(je, e.what());
|
||||
LOGD("nativeStop catched cv::Exception: %s", e.what());
|
||||
jclass je = jenv->FindClass("org/opencv/core/CvException");
|
||||
if(!je)
|
||||
je = jenv->FindClass("java/lang/Exception");
|
||||
jenv->ThrowNew(je, e.what());
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
LOGD("nativeStop catched unknown exception");
|
||||
jclass je = jenv->FindClass("java/lang/Exception");
|
||||
jenv->ThrowNew(je, "Unknown exception in JNI code {highgui::VideoCapture_n_1VideoCapture__()}");
|
||||
LOGD("nativeStop catched unknown exception");
|
||||
jclass je = jenv->FindClass("java/lang/Exception");
|
||||
jenv->ThrowNew(je, "Unknown exception in JNI code {highgui::VideoCapture_n_1VideoCapture__()}");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -126,28 +150,27 @@ JNIEXPORT void JNICALL Java_org_opencv_samples_fd_DetectionBasedTracker_nativeSe
|
||||
{
|
||||
try
|
||||
{
|
||||
if (faceSize > 0)
|
||||
{
|
||||
DetectionBasedTracker::Parameters DetectorParams = \
|
||||
((DetectionBasedTracker*)thiz)->getParameters();
|
||||
DetectorParams.minObjectSize = faceSize;
|
||||
((DetectionBasedTracker*)thiz)->setParameters(DetectorParams);
|
||||
}
|
||||
|
||||
if (faceSize > 0)
|
||||
{
|
||||
// TODO: Reimplement using adapter
|
||||
// DetectionBasedTracker::Parameters DetectorParams = ((DetectionBasedTracker*)thiz)->getParameters();
|
||||
// DetectorParams.minObjectSize = faceSize;
|
||||
// ((DetectionBasedTracker*)thiz)->setParameters(DetectorParams);
|
||||
}
|
||||
}
|
||||
catch(cv::Exception e)
|
||||
{
|
||||
LOGD("nativeStop catched cv::Exception: %s", e.what());
|
||||
jclass je = jenv->FindClass("org/opencv/core/CvException");
|
||||
if(!je)
|
||||
je = jenv->FindClass("java/lang/Exception");
|
||||
jenv->ThrowNew(je, e.what());
|
||||
LOGD("nativeStop catched cv::Exception: %s", e.what());
|
||||
jclass je = jenv->FindClass("org/opencv/core/CvException");
|
||||
if(!je)
|
||||
je = jenv->FindClass("java/lang/Exception");
|
||||
jenv->ThrowNew(je, e.what());
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
LOGD("nativeSetFaceSize catched unknown exception");
|
||||
jclass je = jenv->FindClass("java/lang/Exception");
|
||||
jenv->ThrowNew(je, "Unknown exception in JNI code {highgui::VideoCapture_n_1VideoCapture__()}");
|
||||
LOGD("nativeSetFaceSize catched unknown exception");
|
||||
jclass je = jenv->FindClass("java/lang/Exception");
|
||||
jenv->ThrowNew(je, "Unknown exception in JNI code {highgui::VideoCapture_n_1VideoCapture__()}");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -157,23 +180,23 @@ JNIEXPORT void JNICALL Java_org_opencv_samples_fd_DetectionBasedTracker_nativeDe
|
||||
{
|
||||
try
|
||||
{
|
||||
vector<Rect> RectFaces;
|
||||
((DetectionBasedTracker*)thiz)->process(*((Mat*)imageGray));
|
||||
((DetectionBasedTracker*)thiz)->getObjects(RectFaces);
|
||||
vector_Rect_to_Mat(RectFaces, *((Mat*)faces));
|
||||
vector<Rect> RectFaces;
|
||||
((DetectionBasedTracker*)thiz)->process(*((Mat*)imageGray));
|
||||
((DetectionBasedTracker*)thiz)->getObjects(RectFaces);
|
||||
*((Mat*)faces) = Mat(RectFaces, true);
|
||||
}
|
||||
catch(cv::Exception e)
|
||||
{
|
||||
LOGD("nativeCreateObject catched cv::Exception: %s", e.what());
|
||||
jclass je = jenv->FindClass("org/opencv/core/CvException");
|
||||
if(!je)
|
||||
je = jenv->FindClass("java/lang/Exception");
|
||||
jenv->ThrowNew(je, e.what());
|
||||
LOGD("nativeCreateObject catched cv::Exception: %s", e.what());
|
||||
jclass je = jenv->FindClass("org/opencv/core/CvException");
|
||||
if(!je)
|
||||
je = jenv->FindClass("java/lang/Exception");
|
||||
jenv->ThrowNew(je, e.what());
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
LOGD("nativeDetect catched unknown exception");
|
||||
jclass je = jenv->FindClass("java/lang/Exception");
|
||||
jenv->ThrowNew(je, "Unknown exception in JNI code {highgui::VideoCapture_n_1VideoCapture__()}");
|
||||
LOGD("nativeDetect catched unknown exception");
|
||||
jclass je = jenv->FindClass("java/lang/Exception");
|
||||
jenv->ThrowNew(je, "Unknown exception in JNI code {highgui::VideoCapture_n_1VideoCapture__()}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -7,7 +7,9 @@ public class DetectionBasedTracker
|
||||
{
|
||||
public DetectionBasedTracker(String cascadeName, int minFaceSize)
|
||||
{
|
||||
mNativeObj = nativeCreateObject(cascadeName, minFaceSize);
|
||||
mMainDetector = nativeCreateDetector(cascadeName, minFaceSize);
|
||||
mTrackingDetector = nativeCreateDetector(cascadeName, minFaceSize);
|
||||
mNativeObj = nativeCreateTracker(mMainDetector, mTrackingDetector);
|
||||
}
|
||||
|
||||
public void start()
|
||||
@@ -22,7 +24,8 @@ public class DetectionBasedTracker
|
||||
|
||||
public void setMinFaceSize(int size)
|
||||
{
|
||||
nativeSetFaceSize(mNativeObj, size);
|
||||
nativeSetFaceSize(mMainDetector, size);
|
||||
nativeSetFaceSize(mTrackingDetector, size);
|
||||
}
|
||||
|
||||
public void detect(Mat imageGray, MatOfRect faces)
|
||||
@@ -32,17 +35,25 @@ public class DetectionBasedTracker
|
||||
|
||||
public void release()
|
||||
{
|
||||
nativeDestroyObject(mNativeObj);
|
||||
nativeDestroyTracker(mNativeObj);
|
||||
nativeDestroyDetector(mMainDetector);
|
||||
nativeDestroyDetector(mTrackingDetector);
|
||||
mNativeObj = 0;
|
||||
mMainDetector = 0;
|
||||
mTrackingDetector = 0;
|
||||
}
|
||||
|
||||
private long mNativeObj = 0;
|
||||
private long mMainDetector = 0;
|
||||
private long mTrackingDetector = 0;
|
||||
|
||||
private static native long nativeCreateObject(String cascadeName, int minFaceSize);
|
||||
private static native void nativeDestroyObject(long thiz);
|
||||
private static native long nativeCreateDetector(String cascadeName, int minFaceSize);
|
||||
private static native long nativeCreateTracker(long mainDetector, long trackingDetector);
|
||||
private static native void nativeDestroyTracker(long tracker);
|
||||
private static native void nativeDestroyDetector(long detector);
|
||||
private static native void nativeStart(long thiz);
|
||||
private static native void nativeStop(long thiz);
|
||||
private static native void nativeSetFaceSize(long thiz, int size);
|
||||
private static native void nativeSetFaceSize(long detector, int size);
|
||||
private static native void nativeDetect(long thiz, long inputImage, long faces);
|
||||
|
||||
static
|
||||
|
@@ -91,7 +91,7 @@ public class FdActivity extends Activity {
|
||||
ad.setMessage("Fatal error: can't open camera!");
|
||||
ad.setButton("OK", new DialogInterface.OnClickListener() {
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
dialog.dismiss();
|
||||
dialog.dismiss();
|
||||
finish();
|
||||
}
|
||||
});
|
||||
|
Reference in New Issue
Block a user