使用openCv的嘴巴检测只在一张脸上返回很多圆圈
Mouth detection using openCv returns a lot of circles in only one face
我使用OpenCv与android studio来检测图像中的面部以及每个面部的眼睛和嘴巴。但是,问题是每当我试图检测嘴巴时,它都会在脸上返回多个圆圈,这是错误的。
下面是我为嘴巴检测添加的代码:
private BaseLoaderCallback mLoaderCallback = new BaseLoaderCallback(this) {
@Override
public void onManagerConnected(int status) {
switch (status) {
...
InputStream iserM = getResources().openRawResource(
R.raw.haarcascade_mcs_mouth);
File cascadeDirERM = getDir("cascadeERM",
Context.MODE_PRIVATE);
File cascadeFileERM = new File(cascadeDirERM,
"haarcascade_mcs_mouth.xml");
FileOutputStream oserM = new FileOutputStream(cascadeFileERM);
byte[] bufferERM = new byte[4096];
int bytesReadERM;
while ((bytesReadERM = iserM.read(bufferERM)) != -1) {
oserM.write(bufferERM, 0, bytesReadERM);
}
iserM.close();
oserM.close();
...
//here begins
mJavaDetectorMouth = new CascadeClassifier(
cascadeFileERM.getAbsolutePath());
if (mJavaDetectorMouth.empty()) {
Log.e(TAG, "Failed to load cascade classifier");
mJavaDetectorMouth = null;
} else
Log.i(TAG, "Loaded cascade classifier from "
+ mCascadeFile.getAbsolutePath());
//here ends
...
}
public Mat onCameraFrame(CameraBridgeViewBase.CvCameraViewFrame inputFrame) {
...
Rect r = facesArray[i];
MatOfRect mouths = new MatOfRect();
Mat faceROI = mRgba.submat(facesArray[i]);
mJavaDetectorMouth.detectMultiScale(faceROI, mouths,1.1,1,1, new org.opencv.core.Size(30, 30), new org.opencv.core.Size());
Rect[] mouthArray = mouths.toArray();
for (int j = 0; j < mouthArray.length; j++){
Point center1 = new Point(facesArray[i].x + mouthArray[j].x + mouthArray[j].width * 0.5,
facesArray[i].y + mouthArray[j].y + mouthArray[j].height * 0.5);
int radius = (int) Math.round(mouthArray[j].width / 2);
Imgproc.circle(mRgba, center1, radius, new Scalar(255, 0, 0), 4, 8, 0);
}
...
}
自从我发布这个问题以来,我一直在四处寻找,并尝试了很多事情。但最后我找到了解决办法:我改了:
mJavaDetectorMouth.detectMultiScale(faceROI, mouths,1.1,1,1, new org.opencv.core.Size(30, 30), new org.opencv.core.Size());
:
mJavaDetectorMouth.detectMultiScale(faceROI, mouths,1.1, 2,
Objdetect.CASCADE_FIND_BIGGEST_OBJECT
| Objdetect.CASCADE_SCALE_IMAGE, new org.opencv.core.Size(30, 30), new org.opencv.core.Size());
我解决了这个问题。 相关文章:
- 如何从另一张地图构造一张地图
- 从我的2d数组中的一列返回的字符串值被压缩为一个字符串(在Mac os上打开Windows txt文件)
- C++显示图像并将其保持到下一张图像的最佳方法
- OpenGL Ping Pong可与一张通行证一起工作,而不是两个通行证
- 画一张卡,并打电话给它
- 递归:一次返回
- 洗牌一张牌
- 检查一张图片是否与另一张图片偏移
- 在 Windows 中自动将 xlsx 文件转换为多个 (MS-DOS) CSV 文件(每张一张一个)
- 把一个价格(例如89.95美元)读成一张双人床
- 元组作为一种返回类型,是经过优化的未处理值
- C++不止一次返回
- 如何将地图的反面复制到另一张地图上
- CUDA,我需要一张新卡吗?1.0、1.1、2.0、2.1的差异
- 如何找到不在另一张地图的键中的地图键
- 有没有一张多维地图
- C++重载getter两次,一次返回指针,另一次返回常量引用,都失败了
- 用c++中的printf制作一张表格
- 如何使用数据类型的一次返回来返回错误
- 使用openCv的嘴巴检测只在一张脸上返回很多圆圈