[HELP] CvException @ Dnn.forward() in Android [closed]
I'm trying to implement Gil Levi and Tal Hassner.Age and Gender Classification Using Convolutional Neural Networks to Android app but I'm getting an error on Dnn.forward(). I followed this link:tutorial and I get following error:
CvException [org.opencv.core.CvException: cv::Exception: OpenCV(3.4.2) /build/3_4_pack-android/opencv/modules/dnn/src/layers/convolution_layer.cpp:987: error: (-215:Assertion failed) inputs[0]->size[1] % blobs[0].size[1] == 0 in function 'virtual void cv::dnn::ConvolutionLayerImpl::forward(std::vector<cv::mat*>&, std::vector<cv::mat>&, std::vector<cv::mat>&)' ]
at org.opencv.dnn.Net.forward_0(Native Method)
at org.opencv.dnn.Net.forward(Net.java:52)
at com.alensalihbasic.recfaceocv.MainActivity.onCameraFrame(MainActivity.java:226)
at org.opencv.android.CameraBridgeViewBase.deliverAndDrawFrame(CameraBridgeViewBase.java:392)
at org.opencv.android.JavaCameraView$CameraWorker.run(JavaCameraView.java:373)
at java.lang.Thread.run(Thread.java:764)
If could somebody help me, I'll be grateful :)
Code snippet:
@Override public Mat onCameraFrame(CameraBridgeViewBase.CvCameraViewFrame inputFrame) {
mRgba = inputFrame.rgba();
mGray = inputFrame.gray();
if (mAbsoluteFaceSize == 0) {
int height = mGray.rows();
if (Math.round(height * mRelativeFaceSize) > 0) {
mAbsoluteFaceSize = Math.round(height * mRelativeFaceSize);
}
}
MatOfRect faces = new MatOfRect();
// Use the classifier to detect faces
if (mFaceDetector != null) {
mFaceDetector.detectMultiScale(mGray, faces, 1.1, 2, 2, new Size(mAbsoluteFaceSize, mAbsoluteFaceSize), new Size());
}else {
Log.e(TAG, "Detection is not selected!");
}
// If there are any faces found, draw a rectangle around it
Rect[] facesArray = faces.toArray();
for (int i = 0; i < facesArray.length; i++) {
Imgproc.rectangle(mRgba, facesArray[i].tl(), facesArray[i].br(), new Scalar(0, 255, 0, 255), 3);
}
if (facesArray.length == 1) {
try {
for (Rect face : facesArray) {
Mat capturedFace = new Mat(mRgba, face);
Imgproc.resize(capturedFace, capturedFace, new Size(227, 227));
Mat inputBlob = Dnn.blobFromImage(capturedFace, 1.0f, new Size(227, 227), new Scalar(0), false, false);
net.setInput(inputBlob, "data");
Mat probs = net.forward("prob").reshape(1, 1); // flatten to a single row
Core.MinMaxLocResult mm = Core.minMaxLoc(probs); // get largest softmax output
double result = mm.maxLoc.x; //gender or age group
Log.i(TAG, "Result is: " + result);
}
} catch (Exception e) {
Log.e(TAG, "Error", e);
}
}
return mRgba;
}