MiaoRong / javacv

Automatically exported from code.google.com/p/javacv
GNU General Public License v2.0
0 stars 0 forks source link

This GMM Class occured NullPointerException at Native Method #238

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
i trying follow code

-----------------------------------------------------------------------

public class GMM {
    private CvBGStatModel bgModel;
    private int learnCnt;
    private int frameCnt;

    private IplImage fgClone;

    public GMM(int learnCnt) {
        this.learnCnt = (learnCnt <= 0) ? 20 : learnCnt;
    }

    public void update(IplImage currFrame) {
        if(this.bgModel == null) {
            CvGaussBGStatModelParams params = new CvGaussBGStatModelParams();
            this.bgModel = CvGaussBGModel.create(currFrame, params);
        }else{
            IplImage currGray = null;
            if(currFrame.nChannels() == 3) {
                currGray = IplImage.create(cvGetSize(currFrame), IPL_DEPTH_8U, 1);
                cvCvtColor(currFrame, currGray, CV_RGB2GRAY);
            }else if(currFrame.nChannels() == 1) {
                currGray = currFrame.clone();
            }

            if(this.frameCnt++ <= this.learnCnt) 
                new CvUpdateBGStatModel().call(currGray, this.bgModel, -1);
            else
                new CvUpdateBGStatModel().call(currGray, this.bgModel, 0);

            if(currFrame.nChannels() == 3)
                cvReleaseImage(currGray);
        }
    }

    public IplImage getForeground() {
        return this.fgClone.clone();
    }

    public IplImage getForegroundOrigin() {
        return this.bgModel.foreground().clone();
    }

    public void release() {
        if(this.bgModel != null)
            new CvReleaseBGStatModel().call(this.bgModel);

        if(this.fgClone != null)
            cvReleaseImage(this.fgClone);
    }
}

--------------------------------------------------

Java Runtime stack

Exception in thread "main" java.lang.NullPointerException: This pointer address 
is NULL.
    at com.googlecode.javacv.cpp.opencv_legacy$CvUpdateBGStatModel.call(Native Method)
    at GMM.update(GMM.java:43)
    at main(Main.java:24)

Original issue reported on code.google.com by crazykoo...@gmail.com on 30 Aug 2012 at 4:42

GoogleCodeExporter commented 9 years ago
This code

new CvUpdateBGStatModel().call(currGray, this.bgModel, -1);

Original comment by crazykoo...@gmail.com on 30 Aug 2012 at 4:50

GoogleCodeExporter commented 9 years ago
Incorrectly using the API should crash, I am not sure what you expect.

Original comment by samuel.a...@gmail.com on 30 Aug 2012 at 12:48