繁体   English   中英

iOS中摄像机直播流的动态检测

[英]Motion detection from camera live stream in iOS

我正在制作一个应用程序,我必须打开相机并跟踪相机实时视频/流的动作。 然后检测当前帧中的面数。

我使用CIDetector完成了人脸检测部分,但无法进行运动检测。 任何人都可以指导我如何做到这一点。

我使用过GPUImage,但不支持多面检测。

我开发了一个类似的应用程序。 我使用OpenCV进行运动检测和人脸检测。 该过程将涉及将Pixel Buffer ref转换为OpenCV Mat对象,将其转换为灰度并执行absDiff()和threshold()函数以计算两个图像之间的diff(运动)。

然后,您可以再次为面部处理相同的帧。 这可能不如GPUImage有效,GPUImage现在可以使用GPU加速进行运动检测。

    int motionValue;

    // Blur images to reduce noise and equalize
    cv::Mat processedFrame = cv::Mat(originFrame.size(), CV_8UC1);
    cv::blur(originFrame, processedFrame, cv::Size(2,2));

    // Get absolute difference image
    cv::Mat diffMat;
    cv::absdiff(processedFrame, prevFrame, diffMat);

    // Apply threshold to each channel and combine the results
    cv::Mat treshMat;
    cv::threshold(diffMat, treshMat, kCCAlgorithmMotionSensitivity, 255, CV_THRESH_TOZERO);

    // Find all contours
    std::vector<std::vector<cv::Point> > contours;
    cv::findContours(treshMat, contours, CV_RETR_EXTERNAL, CV_CHAIN_APPROX_SIMPLE);

    // Count all motion areas
    std::vector<std::vector<cv::Point> > intruders;
    for (int i = 0; i < contours.size(); i++) {
        double area = cv::contourArea(contours[i]);
        //NSLog(@"Area %d = %f",i, area);
        if (area > kCCAlgorithmMotionMinAreaDetection){
            intruders.push_back(contours[i]);
            motionValue += area;
        }
    }

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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