I work in one Android application. In my application, I collect images using the opencv native camera. When I open the camera to capture the image, the application crashed. Log file showing "Fatal Signal 11 (SIGSEGV) at 0x00000020 (code = 1)." I do not know why it crashed. Can someone tell me what could be the problem? This code works in an emulator. But when I use the device, it crashed. Iam using pattern recognition of boundary points. Below is a snippet of code,
/** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { Log.i(TAG, "onCreate"); super.onCreate(savedInstanceState); requestWindowFeature(Window.FEATURE_NO_TITLE); Log.i(TAG, "Trying to load OpenCV library"); if (!OpenCVLoader.initAsync(OpenCVLoader.OPENCV_VERSION_2_4_2, this, mOpenCVCallBack)) { Log.e(TAG, "Cannot connect to OpenCV Manager"); } } private BaseLoaderCallback mOpenCVCallBack = new BaseLoaderCallback(this) { @Override public void onManagerConnected(int status) { switch (status) { case LoaderCallbackInterface.SUCCESS: { Log.i(TAG, "OpenCV loaded successfully"); // Load native libs after OpenCV initialization System.loadLibrary("detection_based_tracker"); // Create and set View mView = new FdView(mAppContext); mView.setDetectorType(mDetectorType); mView.setMinFaceSize(0.2f); setContentView(mView); // Check native OpenCV camera if( !mView.openCamera() ) { AlertDialog ad = new AlertDialog.Builder(mAppContext).create(); ad.setCancelable(false); // This blocks the 'BACK' button ad.setMessage("Fatal error: can't open camera!"); ad.setButton("OK", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); finish(); } }); ad.show(); } } break; default: { super.onManagerConnected(status); } break; } } }; public FdView(Context context) { super(context); try { InputStream is = context.getResources().openRawResource(R.raw.lbpcascade_frontalface); File cascadeDir = context.getDir("cascade", Context.MODE_PRIVATE); mCascadeFile = new File(cascadeDir, "lbpcascade_frontalface.xml"); FileOutputStream os = new FileOutputStream(mCascadeFile); byte[] buffer = new byte[4096]; int bytesRead; while ((bytesRead = is.read(buffer)) != -1) { os.write(buffer, 0, bytesRead); } is.close(); os.close(); mJavaDetector = new CascadeClassifier(mCascadeFile.getAbsolutePath()); if (mJavaDetector.empty()) { Log.e(TAG, "Failed to load cascade classifier"); mJavaDetector = null; } else Log.i(TAG, "Loaded cascade classifier from " + mCascadeFile.getAbsolutePath()); mNativeDetector = new DetectionBasedTracker(mCascadeFile.getAbsolutePath(), 0); cascadeDir.delete(); } catch (IOException e) { e.printStackTrace(); Log.e(TAG, "Failed to load cascade. Exception thrown: " + e); } } @Override protected Bitmap processFrame(VideoCapture capture) { capture.retrieve(mRgba, Highgui.CV_CAP_ANDROID_COLOR_FRAME_RGBA); capture.retrieve(mGray, Highgui.CV_CAP_ANDROID_GREY_FRAME); if (mAbsoluteFaceSize == 0) { int height = mGray.rows(); if (Math.round(height * mRelativeFaceSize) > 0); { mAbsoluteFaceSize = Math.round(height * mRelativeFaceSize); } mNativeDetector.setMinFaceSize(mAbsoluteFaceSize); } MatOfRect faces = new MatOfRect(); if (mDetectorType == JAVA_DETECTOR) { if (mJavaDetector != null) mJavaDetector.detectMultiScale(mGray, faces, 1.1, 2, 2 // TODO: objdetect.CV_HAAR_SCALE_IMAGE , new Size(mAbsoluteFaceSize, mAbsoluteFaceSize), new Size()); } else if (mDetectorType == NATIVE_DETECTOR) { if (mNativeDetector != null) mNativeDetector.detect(mGray, faces); } else { Log.e(TAG, "Detection method is not selected!"); } Rect[] facesArray = faces.toArray(); for (int i = 0; i < facesArray.length; i++) Core.rectangle(mRgba, facesArray[i].tl(), facesArray[i].br(), FACE_RECT_COLOR, 3); Bitmap bmp = Bitmap.createBitmap(mRgba.cols(), mRgba.rows(), Bitmap.Config.ARGB_8888); try { Utils.matToBitmap(mRgba, bmp); } catch(Exception e) { Log.e(TAG, "Utils.matToBitmap() throws an exception: " + e.getMessage()); bmp.recycle(); bmp = null; } return bmp; }
The log is shown below.
I/dalvikvm-heap( 688): Grow heap (frag case) to 7.827MB for 1228816-byte allocation D/dalvikvm( 688): GC_CONCURRENT freed <1K, 12% free 7852K/8839K, paused 2ms+2ms D/dalvikvm( 688): GC_FOR_ALLOC freed 1200K, 25% free 6652K/8839K, paused 24ms I/dalvikvm-heap( 688): Grow heap (frag case) to 7.827MB for 1228816-byte allocation F/libc ( 688): Fatal signal 11 (SIGSEGV) at 0x00000020 (code=1) I/DEBUG ( 83): *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** I/DEBUG ( 83): Build fingerprint: 'softwinners/crane_q7/crane-q7:4.0.3/IML74K/20120709:eng/test-keys' I/DEBUG ( 83): pid: 688, tid: 690 >>> com.user.mailconf <<< I/DEBUG ( 83): signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr 00000020 I/DEBUG ( 83): r0 00000000 r1 000106e0 r2 000106e0 r3 40a091e8 I/DEBUG ( 83): r4 50a090f8 r5 408d3c58 r6 00000000 r7 000106e0 I/DEBUG ( 83): r8 50a09000 r9 000106e0 10 50a09100 fp 4085f394 I/DEBUG ( 83): ip 0000001f sp 100ffdd0 lr 4084efc4 pc 4085efac cpsr 80000010 I/DEBUG ( 83): d0 0000000000000000 d1 0000000000000000 I/DEBUG ( 83): d2 0000000000000000 d3 0000000000000000 I/DEBUG ( 83): d4 0000000000000000 d5 0000000000000000 I/DEBUG ( 83): d6 0000000000000000 d7 0000000000000000 I/DEBUG ( 83): d8 0000000000000000 d9 0000000000000000 I/DEBUG ( 83): d10 0000000000000000 d11 0000000000000000 I/DEBUG ( 83): d12 0000000000000000 d13 0000000000000000 I/DEBUG ( 83): d14 0000000000000000 d15 0000000000000000 I/DEBUG ( 83): d16 0000000000000000 d17 991f1f1f991f1f1f I/DEBUG ( 83): d18 0707070703030303 d19 0000000000000000 I/DEBUG ( 83): d20 0100010001000100 d21 0100010001000100 I/DEBUG ( 83): d22 0000000000000000 d23 0000000000000000 I/DEBUG ( 83): d24 0000000000000000 d25 0000000000000000 I/DEBUG ( 83): d26 0067006700670067 d27 0067006700670067 I/DEBUG ( 83): d28 0067006700670067 d29 0067006700670067 I/DEBUG ( 83): d30 00308000002b4000 d31 003b40000035c000 I/DEBUG ( 83): scr 80000012 I/DEBUG ( 83): I/DEBUG ( 83):