简体   繁体   中英

How can I increase OpenCV realtime detector app's fps?

I have face detector app which is using java's native cpp lines and OpenCV. It is detecting faces and drawing a circle around them. But its fps is very low because of its working plan.

So I tried changing JavaCameraView's layout width and height to decrease resolution and increase fps but it was still has same fps. Then I tried adding setting resolution and fps lines to my cpp file but they didn't work.

Here's my changed cpp codes:

#include <jni.h>
#include "opencv2/objdetect.hpp"
#include "opencv2/highgui.hpp"
#include <android/log.h>
#include <opencv2/core/core.hpp>
#include <opencv2/imgproc/imgproc.hpp>

using namespace std;
using namespace cv;

extern "C" {
void detect(Mat &input);
void JNICALL
Java_com_example_nativeopencvandroidtemplate_MainActivity_adaptiveThresholdFromJNI(JNIEnv *env, jobject instance,
                                                                                   jlong matAddr) {

    Mat &input = *(Mat *) matAddr;
    detect(input);
}
void detect(Mat &input) {
    String face_cascade_name = "/storage/emulated/0/ony.xml";
    CascadeClassifier face_cascade;
    

    std::vector<Rect> faces;
    Mat frame_gray;

    cvtColor( input, frame_gray, COLOR_RGB2GRAY );
    equalizeHist(frame_gray, frame_gray);

    face_cascade.detectMultiScale(frame_gray, faces, 1.1, 2, 0 | CASCADE_SCALE_IMAGE, Size(30, 30));

    for (size_t i = 0; i < faces.size(); i++) {
        Point center(faces[i].x + faces[i].width * 0.5, faces[i].y + faces[i].height * 0.5);
        ellipse(input, center, Size(faces[i].width * 0.5, faces[i].height * 0.5), 0, 0, 360, Scalar(255, 0, 255), 4, 8,
                0);
    }
}
}

Here's its original template which I changed its cpp file to detecting faces.

And when I tried to add three classifiers and their lines for detecting another things and drawing another circles, app is stopping repeatedly on my Android OS. That is my another problem about this project.

Your code is incomplete, but it looks like you create the classifier on each frame. That is not efficient.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM