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:236: error: (-215:Assertion failed) ngroups > 0 && inpCn % ngroups == 0 && outCn % ngroups == 0 in function 'virtual bool cv::dnn::ConvolutionLayerImpl::getMemoryShapes(const std::vector<std::vector<int> >&, int, std::vector<std::vector<int> >&, std::vector<std::vector<int> >&) const']
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(mGray, face);
Mat inputBlob = Dnn.blobFromImage(capturedFace, 1.0f, new Size(256, 256), new Scalar(0), false, false);
net.setInput(inputBlob, "data");
Mat detections = net.forward("prob");
int cols = capturedFace.cols();
int rows = capturedFace.rows();
detections = detections.reshape(1, (int) detections.total() / 7);
for (int i = 0; i < detections.rows(); i++) {
double confidence = detections.get(i, 2)[0];
if (confidence > THRESHOLD) {
int classId = (int) detections.get(i, 1)[0];
int xLeftBottom = (int) (detections.get(i, 3)[0] * cols);
int yLeftBottom = (int) (detections.get(i, 4)[0] * rows);
int xRightTop = (int) (detections.get(i, 5)[0] * cols);
int yRightTop = (int) (detections.get(i, 6)[0] * rows);
// Draw rectangle around detected object.
Imgproc.rectangle(capturedFace, new Point(xLeftBottom, yLeftBottom),
new Point(xRightTop, yRightTop),
new Scalar(0, 255, 0));
String label = classId + ": " + confidence;
// Write class name and confidence.
Imgproc.putText(capturedFace, label, new Point(xLeftBottom, yLeftBottom),
Core.FONT_HERSHEY_SIMPLEX, 0.5, new Scalar(0, 0, 0));
}
}
}
} catch (Exception e) {
Log.e(TAG, "Error", e);
}
}
return mRgba;
}