Fix crash on resume in face detection sample

This commit is contained in:
Andrey Kamaev 2012-08-23 16:02:33 +04:00
parent ce11c0d1eb
commit e9e0668549
2 changed files with 12 additions and 3 deletions

View File

@ -68,6 +68,7 @@ struct DetectorAgregator
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)
{ {
LOGD("Java_org_opencv_samples_fd_DetectionBasedTracker_nativeCreateObject enter");
const char* jnamestr = jenv->GetStringUTFChars(jFileName, NULL); const char* jnamestr = jenv->GetStringUTFChars(jFileName, NULL);
string stdFileName(jnamestr); string stdFileName(jnamestr);
jlong result = 0; jlong result = 0;
@ -101,6 +102,7 @@ JNIEXPORT jlong JNICALL Java_org_opencv_samples_fd_DetectionBasedTracker_nativeC
return 0; return 0;
} }
LOGD("Java_org_opencv_samples_fd_DetectionBasedTracker_nativeCreateObject exit");
return result; return result;
} }
@ -110,10 +112,13 @@ JNIEXPORT void JNICALL Java_org_opencv_samples_fd_DetectionBasedTracker_nativeDe
LOGD("Java_org_opencv_samples_fd_DetectionBasedTracker_nativeDestroyObject"); LOGD("Java_org_opencv_samples_fd_DetectionBasedTracker_nativeDestroyObject");
try try
{
if(thiz != 0)
{ {
((DetectorAgregator*)thiz)->tracker->stop(); ((DetectorAgregator*)thiz)->tracker->stop();
delete (DetectorAgregator*)thiz; delete (DetectorAgregator*)thiz;
} }
}
catch(cv::Exception e) catch(cv::Exception e)
{ {
LOGD("nativeestroyObject catched cv::Exception: %s", e.what()); LOGD("nativeestroyObject catched cv::Exception: %s", e.what());
@ -128,6 +133,7 @@ JNIEXPORT void JNICALL Java_org_opencv_samples_fd_DetectionBasedTracker_nativeDe
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 {Java_org_opencv_samples_fd_DetectionBasedTracker_nativeDestroyObject(...)}");
} }
LOGD("Java_org_opencv_samples_fd_DetectionBasedTracker_nativeDestroyObject exit");
} }
JNIEXPORT void JNICALL Java_org_opencv_samples_fd_DetectionBasedTracker_nativeStart JNIEXPORT void JNICALL Java_org_opencv_samples_fd_DetectionBasedTracker_nativeStart
@ -153,6 +159,7 @@ JNIEXPORT void JNICALL Java_org_opencv_samples_fd_DetectionBasedTracker_nativeSt
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 {Java_org_opencv_samples_fd_DetectionBasedTracker_nativeStart(...)}");
} }
LOGD("Java_org_opencv_samples_fd_DetectionBasedTracker_nativeStart exit");
} }
JNIEXPORT void JNICALL Java_org_opencv_samples_fd_DetectionBasedTracker_nativeStop JNIEXPORT void JNICALL Java_org_opencv_samples_fd_DetectionBasedTracker_nativeStop
@ -178,6 +185,7 @@ JNIEXPORT void JNICALL Java_org_opencv_samples_fd_DetectionBasedTracker_nativeSt
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 {Java_org_opencv_samples_fd_DetectionBasedTracker_nativeStop(...)}");
} }
LOGD("Java_org_opencv_samples_fd_DetectionBasedTracker_nativeStop exit");
} }
JNIEXPORT void JNICALL Java_org_opencv_samples_fd_DetectionBasedTracker_nativeSetFaceSize JNIEXPORT void JNICALL Java_org_opencv_samples_fd_DetectionBasedTracker_nativeSetFaceSize

View File

@ -34,8 +34,8 @@ public abstract class SampleCvViewBase extends SurfaceView implements SurfaceHol
releaseCamera(); releaseCamera();
mCamera = new VideoCapture(Highgui.CV_CAP_ANDROID); mCamera = new VideoCapture(Highgui.CV_CAP_ANDROID);
if (!mCamera.isOpened()) { if (!mCamera.isOpened()) {
releaseCamera();
Log.e(TAG, "Failed to open native camera"); Log.e(TAG, "Failed to open native camera");
releaseCamera();
return false; return false;
} }
} }
@ -92,6 +92,7 @@ public abstract class SampleCvViewBase extends SurfaceView implements SurfaceHol
public void surfaceDestroyed(SurfaceHolder holder) { public void surfaceDestroyed(SurfaceHolder holder) {
Log.i(TAG, "surfaceDestroyed"); Log.i(TAG, "surfaceDestroyed");
releaseCamera(); releaseCamera();
Log.i(TAG, "surfaceDestroyed2");
} }
protected abstract Bitmap processFrame(VideoCapture capture); protected abstract Bitmap processFrame(VideoCapture capture);