I'm trying compute `HOGDescriptor` from a frame on android with openCV 3.2.0. Before I have made it in python and it's working. When I use it on android i have error:> E/AndroidRuntime: FATAL EXCEPTION: Thread-24279
Process: com.example.agnieszka.openvctest, PID: 14567 > java.lang.NullPointerException: Attempt to read from field 'long org.opencv.core.Mat.nativeObj' on a null object reference> at org.opencv.objdetect.HOGDescriptor.compute(HOGDescriptor.java:191)> at com.example.agnieszka.openvctest.HogDescriptor.compute(HogDescriptor.java:47)> at com.example.agnieszka.openvctest.MainActivity.onCameraFrame(MainActivity.java:211)> at org.opencv.android.CameraBridgeViewBase.deliverAndDrawFrame(CameraBridgeViewBase.java:392)> at org.opencv.android.JavaCameraView$CameraWorker.run(JavaCameraView.java:352)
at java.lang.Thread.run(Thread.java:818)
The code below:
public class HogDescriptor {
HOGDescriptor Hog;
int nbins = 9;
int derivAperture = 1;
double winSigma = -1.0;
int histogramNormType = 0;
double L2HysThreshold = 0.2;
boolean gammaCorrection = true;
int nlevels = 64;
MatOfFloat descriptors;
Mat frameB = new Mat();
public HogDescriptor()
{
Hog = new HOGDescriptor(new org.opencv.core.Size(60, 100),new org.opencv.core.Size(40, 40), new org.opencv.core.Size(20, 20),new org.opencv.core.Size(10, 10), nbins, derivAperture, winSigma, histogramNormType, L2HysThreshold, gammaCorrection, nlevels);
}
void compute(Mat frame)
{
Imgproc.resize(frame, frameB, winSize,1,1, Imgproc.INTER_AREA);
Hog.compute(frameB, descriptors);
}
MatOfFloat getDescriptors()
{
return this.descriptors;
}
Mat getFrameB()
{
return this.frameB;
}
}
Mat frameB I can preview on the phone screen and I can make some processing but when I use method Hog.compute() i have this error. There are fragments from MainActivity :
private HogDescriptor hog;
public void onCameraViewStarted(int width, int height) {
appStatus = CALIBRATION;
startCountDownTimer();
mRgba = new Mat(height, width, CvType.CV_8UC4);
mMask = new Mat(height, width, CvType.CV_8SC1);
imProc = new ImProcessing(height,width);
hog = new HogDescriptor();
}
public Mat onCameraFrame(CvCameraViewFrame inputFrame) {
mRgba = inputFrame.rgba();
mMask = imProc.backgroungRemove(mRgba, appStatus);
hog.compute(mMask);
mRgba = imProc.drawContours(mRgba,mMask);
return mMask;
}
Anyone can help me why I get NullPointerException in this case?
↧