如何在opencv的imshow中完全显示2k视频

时间:2019-04-26 10:12:37

标签: c++ opencv

我正在尝试使用DSST算法(鲁棒视觉跟踪的精确比例估计)分析对象跟踪问题。但是我的测试视频是2k,imshow功能无法清晰显示。而且,来自github的代码结构是完全打包的...无法轻易找到进行任何更改的代码。

我尝试添加代码

(
//cv::namedWindow(_windowTitle.c_str(), cv::WINDOW_AUTOSIZE);
//cv::resizeWindow(_windowTitle.c_str(),980,600);
)

imshow上方,但实际上不起作用,仅调整窗口大小,但不能调整视频大小。

if (_paras.showOutput)
    {
        Mat hudImage;
        _image.copyTo(hudImage);
        rectangle(hudImage, _boundingBox, Scalar(0, 0, 255), 2);
        Point_<double> center;
        center.x = _boundingBox.x + _boundingBox.width / 2;
        center.y = _boundingBox.y + _boundingBox.height / 2;
        circle(hudImage, center, 3, Scalar(0, 0, 255), 2);

        stringstream ss;
        ss << "FPS: " << fps;
        putText(hudImage, ss.str(), Point(20, 20), FONT_HERSHEY_TRIPLEX, 0.5, Scalar(255, 0, 0));

        ss.str("");
        ss.clear();
        ss << "#" << _frameIdx;
        putText(hudImage, ss.str(), Point(hudImage.cols - 60, 20), FONT_HERSHEY_TRIPLEX, 0.5, Scalar(255, 0, 0));

        if (_debug != 0)
            _debug->printOnImage(hudImage);

        if (!_targetOnFrame)
        {
            cv::Point_<double> tl = _boundingBox.tl();
            cv::Point_<double> br = _boundingBox.br();

            line(hudImage, tl, br, Scalar(0, 0, 255));
            line(hudImage, cv::Point_<double>(tl.x, br.y),
                cv::Point_<double>(br.x, tl.y), Scalar(0, 0, 255));
        }
        //cv::namedWindow(_windowTitle.c_str(), cv::WINDOW_AUTOSIZE);
        //cv::resizeWindow(_windowTitle.c_str(),980,600);
        imshow(_windowTitle.c_str(), hudImage);

        if (!_paras.imgExportPath.empty())
        {
            stringstream ssi;
            ssi << setfill('0') << setw(5) << _frameIdx << ".png";
            std::string imgPath = _paras.imgExportPath + ssi.str();

            try
            {
                imwrite(imgPath, hudImage);
            }
            catch (runtime_error& runtimeError)
            {
                cerr << "Could not write output images: " << runtimeError.what() << endl;
            }
        }
}

我希望输出的视频能够完整显示,以便我可以追踪它的正确区域。

0 个答案:

没有答案