有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

安卓上使用openCV matchTemplate的java巨型slowup

我正在用openCV的_matchTemplate_方法在Android相机框架上制作一个带有跟踪垫图案的小项目

然而,当我的代码达到_matchTemplate__minMaxLoc_时,我手机上的帧速率下降到每10秒约1次,然而在Android Profiler中,内存和CPU使用率与我祖母的心电图一样平稳

我认为这可能是由于脚本等待查找匹配项造成的,但我在电脑上的一系列图片上尝试了它,不到一秒钟就浏览了200多张图片(即使没有匹配项,它也会简单地指向左上角,没有打嗝)

以下是我的追踪方法代码:

public Mat simpleTrack(Mat input, boolean showCrosshair, boolean showTracker)
{
    if (firstRun)
    {
        crosshairDimensions(input);
        firstRun = false;
    }

    if (showCrosshair)
    {
        Imgproc.rectangle(input, new Point(rowstart, colstart), new Point(rowend, colend), new Scalar(255, 0, 0), 3);
    }
    else if (showTracker)
    {
        if (getTemplate)
        {
            template = input.submat(rowstart, rowend, colstart, colend);
            getTemplate = false;
        }
        Imgproc.matchTemplate(input, template, mRgbaM, Imgproc.TM_CCOEFF_NORMED);
        Point top_left = Core.minMaxLoc(mRgbaM).maxLoc;
        Point bottom_right = new Point(top_left.x + framewidth, top_left.y + frameheight);
        Imgproc.rectangle(input, top_left, bottom_right, new Scalar(0, 255, 0), 3);
    }
    //call Garbage Collector every n'th cycle iteration
    if (iteration % cycle == 0)
    {
        System.gc();
    }
    iteration++;
    return input;
}

共 (1) 个答案

  1. # 1 楼答案

    好吧,如果有人有类似的问题,问题是由提供的低端安卓设备引起的——在较新的设备上,代码开始加速

    更提高我性能的是将输入矩阵从RGB更改为灰度(或者使用阈值过滤器,这样脚本就不会被超过10MB的文件阻塞)。我还将分辨率从4k降低到HD