Android OpenCv人数

时间:2017-04-05 12:51:02

标签: android opencv

我正在开发一个Android应用程序来计算实时视频中的人数。我使用OpenCv来检测人,但没有找到计算它们的方法。如果有人知道怎么做,请帮助我。

以下是检测即将播放的视频帧中人员的代码

@Override
public Mat onCameraFrame(CameraBridgeViewBase.CvCameraViewFrame inputFrame) {

    List<MatOfPoint> list = new ArrayList<>();
    Mat frame = new Mat();
    Mat gray = new Mat();
    Mat hierarchy = new Mat();
    Mat originalFrame = inputFrame.rgba();
    Core.transpose(originalFrame,mRgbaT);
    Imgproc.resize(mRgbaT,mRgbaF,mRgbaF.size(),0,0,0);
    Core.flip(mRgbaF,originalFrame,1);


    Imgproc.medianBlur(originalFrame,originalFrame,3);
    Imgproc.cvtColor(originalFrame, gray, Imgproc.CV_BGR2GRAY, 0);

    HOGDescriptor hog = new HOGDescriptor();
    //Получаем стандартный определитель людей и устанавливаем его нашему дескриптору
    MatOfFloat descriptors = HOGDescriptor.getDefaultPeopleDetector();
   // MatOfFloat dfdfdf=HOGDescriptor.getDefaultPeopleDetector();
    hog.setSVMDetector(descriptors);
    MatOfRect locations = new MatOfRect();
    MatOfDouble weights = new MatOfDouble();
    hog.detectMultiScale(gray, locations, weights);

    Point rectPoint1 = new Point();
    Point rectPoint2 = new Point();
    Point fontPoint = new Point();

    if (locations.rows() > 0) {
        List<Rect> rectangles = locations.toList();
        for (Rect rect : rectangles) {
            rectPoint1.x = rect.x;
            rectPoint1.y = rect.y;
            fontPoint.x  = rect.x;
            fontPoint.y  = rect.y - 4;
            rectPoint2.x = rect.x + rect.width;
            rectPoint2.y = rect.y + rect.height;
            final Scalar rectColor = new Scalar( 0  , 0 , 0  );
            // Добавляем на изображения найденную информацию
            Imgproc.rectangle(originalFrame, rectPoint1, rectPoint2, rectColor, 2);
        }
    }


    frame.release();
    gray.release();
    hierarchy.release();
    int i=list.size();
    list.clear();
    return originalFrame;

}

0 个答案:

没有答案