JavaCV convertToIplImage return NULL

301 views Asked by At

In JavaCV used in Android,while converting Frame to IplImage for applying color effect on video,we are NullPointerException.NPE is only encountered for some of the Frames in the Video.

...
while (true) {
   Log.d("JAVA_CV", "Counting . . . " + count);
   Frame original_frame = ffg.grab();
    if (original_frame == null) {

                    Log.d("JAVA_CV", "original_frame is NULL at" + count);
                    break;
                } else {
                    Log.d("JAVA_CV", "original_frame is NOT_NULL at" + count);
                    if (converter == null) {
                        Log.d("JAVA_CV", "converter is null at position" +count);
                        continue;

                    }
                    opencv_core.IplImage frame1 = null;
                    if (original_frame != null) {
                        frame1 = converter.convertToIplImage(original_frame);
                    } else {
                        continue;
                    }

                    if (frame1 == null) {
                        Log.d("JAVA_CV", "frame1 is NULL at" + count);
                    } else {

                        if (!frame1.isNull() && original_frame.image != null) {


                            int width = frame1.width();
                            int height = frame1.height();
                            int channel = frame1.nChannels();
                            opencv_core.IplImage frame2 = opencv_core.IplImage.create(width, height, opencv_core.IPL_DEPTH_8U, channel);
                            if (frame2 == null)
                                continue;
                            opencv_core.cvCopy(frame1, frame2);
                            opencv_core.IplImage frame3 = opencv_core.IplImage.create(width, height, opencv_core.IPL_DEPTH_8U, 1);
                            if (frame3 == null)
                                continue;
                            opencv_imgproc.cvCvtColor(frame2, frame3, opencv_imgproc.CV_BGRA2GRAY);

                            Log.d("JAVA_CV", "frame1 is NOT_NULL at" + count + " Height " + frame1.height());
                            Frame resultFrame = converter.convert(frame3);
                            if (resultFrame == null)
                                continue;
                            recorder.record(resultFrame);
                            frame1.release();
                            frame2.release();
                            frame3.release();
                            original_frame = null;
                        } else {
                            break;
                        }
                    }
                }
                count++;
            }
 ...

The Exception stack is here :

06-20 12:00:57.664  30245-30245/com.appxperts.opencvfirstapp W/System.err﹕ java.lang.NullPointerException: This pointer address is NULL.
06-20 12:00:57.664  30245-30245/com.appxperts.opencvfirstapp W/System.err﹕ at org.bytedeco.javacpp.opencv_core$IplImage.width(Native Method)
06-20 12:00:57.664  30245-30245/com.appxperts.opencvfirstapp W/System.err﹕ at org.bytedeco.javacv.OpenCVFrameConverter.isEqual(OpenCVFrameConverter.java:75)
06-20 12:00:57.664  30245-30245/com.appxperts.opencvfirstapp W/System.err﹕ at org.bytedeco.javacv.OpenCVFrameConverter.convertToIplImage(OpenCVFrameConverter.java:85)
06-20 12:00:57.664  30245-30245/com.appxperts.opencvfirstapp W/System.err﹕ at org.bytedeco.javacv.OpenCVFrameConverter$ToIplImage.convert(OpenCVFrameConverter.java:41)
06-20 12:00:57.664  30245-30245/com.appxperts.opencvfirstapp W/System.err﹕ at com.appxperts.opencvfirstapp.MainActivitySecond.kaamdg(MainActivitySecond.java:161)
06-20 12:00:57.664  30245-30245/com.appxperts.opencvfirstapp W/System.err﹕ at com.appxperts.opencvfirstapp.MainActivitySecond$1.onClick(MainActivitySecond.java:62)
06-20 12:00:57.665  30245-30245/com.appxperts.opencvfirstapp W/System.err﹕ at android.view.View.performClick(View.java:4463)
06-20 12:00:57.665  30245-30245/com.appxperts.opencvfirstapp W/System.err﹕ at android.view.View$PerformClick.run(View.java:18789)
06-20 12:00:57.665  30245-30245/com.appxperts.opencvfirstapp W/System.err﹕ at android.os.Handler.handleCallback(Handler.java:808)
06-20 12:00:57.665  30245-30245/com.appxperts.opencvfirstapp W/System.err﹕ at android.os.Handler.dispatchMessage(Handler.java:103)
06-20 12:00:57.665  30245-30245/com.appxperts.opencvfirstapp W/System.err﹕ at android.os.Looper.loop(Looper.java:193)`enter code here`
06-20 12:00:57.665  30245-30245/com.appxperts.opencvfirstapp W/System.err﹕ at android.app.ActivityThread.main(ActivityThread.java:5299)
06-20 12:00:57.665  30245-30245/com.appxperts.opencvfirstapp W/System.err﹕ at java.lang.reflect.Method.invokeNative(Native Method)
06-20 12:00:57.665  30245-30245/com.appxperts.opencvfirstapp W/System.err﹕ at java.lang.reflect.Method.invoke(Method.java:515)
06-20 12:00:57.665  30245-30245/com.appxperts.opencvfirstapp W/System.err﹕ at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:825)
06-20 12:00:57.665  30245-30245/com.appxperts.opencvfirstapp W/System.err﹕ at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:641)
0

There are 0 answers