- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我使用了示例代码 super_resolution.cpp。用于从视频源创建高质量图像。所以这里是super_resolution.cpp的代码
#include <iostream>
#include <iomanip>
#include <string>
#include <ctype.h>
#include "opencv2/core/core.hpp"
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/imgproc/imgproc.hpp"
#include "opencv2/contrib/contrib.hpp"
#include "opencv2/superres/superres.hpp"
#include "opencv2/superres/optical_flow.hpp"
#include "opencv2/opencv_modules.hpp"
#if defined(HAVE_OPENCV_OCL)
#include "opencv2/ocl/ocl.hpp"
#endif
using namespace std;
using namespace cv;
using namespace cv::superres;
bool useOclChanged;
#define MEASURE_TIME(op) \
{ \
TickMeter tm; \
tm.start(); \
op; \
tm.stop(); \
cout << tm.getTimeSec() << " sec" << endl; \
}
static Ptr<DenseOpticalFlowExt> createOptFlow(const string& name, bool useGpu)
{
if (name == "farneback")
{
if (useGpu)
return createOptFlow_Farneback_GPU();
else
return createOptFlow_Farneback();
}
else if (name == "simple")
return createOptFlow_Simple();
else if (name == "tvl1")
{
if (useGpu)
return createOptFlow_DualTVL1_GPU();
else
return createOptFlow_DualTVL1();
}
else if (name == "brox")
return createOptFlow_Brox_GPU();
else if (name == "pyrlk")
return createOptFlow_PyrLK_GPU();
else
{
cerr << "Incorrect Optical Flow algorithm - " << name << endl;
exit(-1);
}
}
#if defined(HAVE_OPENCV_OCL)
static Ptr<DenseOpticalFlowExt> createOptFlow(const string& name)
{
if (name == "farneback")
{
return createOptFlow_Farneback_OCL();
}
else if (name == "simple")
{
useOclChanged = true;
std::cout<<"simple on OpenCL has not been implemented. Use CPU instead!\n";
return createOptFlow_Simple();
}
else if (name == "tvl1")
return createOptFlow_DualTVL1_OCL();
else if (name == "brox")
{
std::cout<<"brox has not been implemented!\n";
return NULL;
}
else if (name == "pyrlk")
return createOptFlow_PyrLK_OCL();
else
{
cerr << "Incorrect Optical Flow algorithm - " << name << endl;
}
return 0;
}
#endif
int main(int argc, const char* argv[])
{
useOclChanged = false;
CommandLineParser cmd(argc, argv,
"{ v | video | | Input video }"
"{ o | output | | Output video }"
"{ s | scale | 4 | Scale factor }"
"{ i | iterations | 180 | Iteration count }"
"{ t | temporal | 4 | Radius of the temporal search area }"
"{ f | flow | farneback | Optical flow algorithm (farneback, simple, tvl1, brox, pyrlk) }"
"{ g | gpu | | CPU as default device, cuda for CUDA and ocl for OpenCL }"
"{ h | help | false | Print help message }"
);
if (cmd.get<bool>("help"))
{
cout << "This sample demonstrates Super Resolution algorithms for video sequence" << endl;
cmd.printParams();
return 0;
}
const string inputVideoName = cmd.get<string>("video");
const string outputVideoName = cmd.get<string>("output");
const int scale = cmd.get<int>("scale");
const int iterations = cmd.get<int>("iterations");
const int temporalAreaRadius = cmd.get<int>("temporal");
const string optFlow = cmd.get<string>("flow");
string gpuOption = cmd.get<string>("gpu");
std::transform(gpuOption.begin(), gpuOption.end(), gpuOption.begin(), ::tolower);
bool useCuda = false;
bool useOcl = false;
if(gpuOption.compare("ocl") == 0)
useOcl = true;
else if(gpuOption.compare("cuda") == 0)
useCuda = true;
#ifndef HAVE_OPENCV_OCL
if(useOcl)
{
{
cout<<"OPENCL is not compiled\n";
return 0;
}
}
#endif
#if defined(HAVE_OPENCV_OCL)
if(useCuda)
{
CV_Assert(!useOcl);
}
#endif
Ptr<SuperResolution> superRes;
#if defined(HAVE_OPENCV_OCL)
if(useOcl)
{
Ptr<DenseOpticalFlowExt> of = createOptFlow(optFlow);
if (of.empty())
exit(-1);
if(useOclChanged)
{
superRes = createSuperResolution_BTVL1();
useOcl = !useOcl;
}else
superRes = createSuperResolution_BTVL1_OCL();
superRes->set("opticalFlow", of);
}
else
#endif
{
if (useCuda)
superRes = createSuperResolution_BTVL1_GPU();
else
superRes = createSuperResolution_BTVL1();
Ptr<DenseOpticalFlowExt> of = createOptFlow(optFlow, useCuda);
if (of.empty())
exit(-1);
superRes->set("opticalFlow", of);
}
superRes->set("scale", scale);
superRes->set("iterations", iterations);
superRes->set("temporalAreaRadius", temporalAreaRadius);
Ptr<FrameSource> frameSource;
if (useCuda)
{
// Try to use gpu Video Decoding
try
{
frameSource = createFrameSource_Video_GPU(inputVideoName);
Mat frame;
frameSource->nextFrame(frame);
}
catch (const cv::Exception&)
{
frameSource.release();
}
}
if (frameSource.empty())
frameSource = createFrameSource_Video(inputVideoName);
// skip first frame, it is usually corrupted
{
Mat frame;
frameSource->nextFrame(frame);
cout << "Input : " << inputVideoName << " " << frame.size() << endl;
cout << "Scale factor : " << scale << endl;
cout << "Iterations : " << iterations << endl;
cout << "Temporal radius : " << temporalAreaRadius << endl;
cout << "Optical Flow : " << optFlow << endl;
#if defined(HAVE_OPENCV_OCL)
cout << "Mode : " << (useCuda ? "CUDA" : useOcl? "OpenCL" : "CPU") << endl;
#else
cout << "Mode : " << (useCuda ? "CUDA" : "CPU") << endl;
#endif
}
superRes->setInput(frameSource);
VideoWriter writer;
for (int i = 0;; ++i)
{
cout << '[' << setw(3) << i << "] : ";
Mat result;
#if defined(HAVE_OPENCV_OCL)
cv::ocl::oclMat result_;
if(useOcl)
{
MEASURE_TIME(
{
superRes->nextFrame(result_);
ocl::finish();
});
}
else
#endif
{
MEASURE_TIME(superRes->nextFrame(result));
}
#ifdef HAVE_OPENCV_OCL
if(useOcl)
{
if(!result_.empty())
{
result_.download(result);
}
}
#endif
if (result.empty())
break;
imshow("Super Resolution", result);
if (waitKey(1000) > 0)
break;
if (!outputVideoName.empty())
{
if (!writer.isOpened())
writer.open(outputVideoName, CV_FOURCC('X', 'V', 'I', 'D'), 25.0, result.size());
writer << result;
}
}
return 0;
}
我已经编译了它们。但是在终端运行时。
./SuperResolution -v /home/raiym/Downloads/bird.avi
程序报错:
OpenCV Error: Assertion failed (vc_.isOpened()) in reset, file /home/raiym/Downloads/opencv-2.4.9/modules/superres/src/frame_source.cpp, line 161
terminate called after throwing an instance of 'cv::Exception'
what(): /home/raiym/Downloads/opencv-2.4.9/modules/superres/src/frame_source.cpp:161: error: (-215) vc_.isOpened() in function reset
Aborted (core dumped)
frame_source.cpp 是:
/*M///////////////////////////////////////////////////////////////////////////////////////
//
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
//
// By downloading, copying, installing or using the software you agree to this license.
// If you do not agree to this license, do not download, install,
// copy or use the software.
//
//
// License Agreement
// For Open Source Computer Vision Library
//
// Copyright (C) 2000-2008, Intel Corporation, all rights reserved.
// Copyright (C) 2009, Willow Garage Inc., all rights reserved.
// Third party copyrights are property of their respective owners.
//
// Redistribution and use in source and binary forms, with or without modification,
// are permitted provided that the following conditions are met:
//
// * Redistribution's of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
//
// * Redistribution's in binary form must reproduce the above copyright notice,
// this list of conditions and the following disclaimer in the documentation
// and/or other materials provided with the distribution.
//
// * The name of the copyright holders may not be used to endorse or promote products
// derived from this software without specific prior written permission.
//
// This software is provided by the copyright holders and contributors "as is" and
// any express or implied warranties, including, but not limited to, the implied
// warranties of merchantability and fitness for a particular purpose are disclaimed.
// In no event shall the Intel Corporation or contributors be liable for any direct,
// indirect, incidental, special, exemplary, or consequential damages
// (including, but not limited to, procurement of substitute goods or services;
// loss of use, data, or profits; or business interruption) however caused
// and on any theory of liability, whether in contract, strict liability,
// or tort (including negligence or otherwise) arising in any way out of
// the use of this software, even if advised of the possibility of such damage.
//
//M*/
#include "precomp.hpp"
using namespace std;
using namespace cv;
using namespace cv::gpu;
using namespace cv::superres;
using namespace cv::superres::detail;
cv::superres::FrameSource::~FrameSource()
{
}
//////////////////////////////////////////////////////
// EmptyFrameSource
namespace
{
class EmptyFrameSource : public FrameSource
{
public:
void nextFrame(OutputArray frame);
void reset();
};
void EmptyFrameSource::nextFrame(OutputArray frame)
{
frame.release();
}
void EmptyFrameSource::reset()
{
}
}
Ptr<FrameSource> cv::superres::createFrameSource_Empty()
{
return new EmptyFrameSource;
}
//////////////////////////////////////////////////////
// VideoFrameSource & CameraFrameSource
#ifndef HAVE_OPENCV_HIGHGUI
Ptr<FrameSource> cv::superres::createFrameSource_Video(const string& fileName)
{
(void) fileName;
CV_Error(CV_StsNotImplemented, "The called functionality is disabled for current build or platform");
return Ptr<FrameSource>();
}
Ptr<FrameSource> cv::superres::createFrameSource_Camera(int deviceId)
{
(void) deviceId;
CV_Error(CV_StsNotImplemented, "The called functionality is disabled for current build or platform");
return Ptr<FrameSource>();
}
#else // HAVE_OPENCV_HIGHGUI
namespace
{
class CaptureFrameSource : public FrameSource
{
public:
void nextFrame(OutputArray frame);
protected:
VideoCapture vc_;
private:
Mat frame_;
};
void CaptureFrameSource::nextFrame(OutputArray _frame)
{
if (_frame.kind() == _InputArray::MAT)
{
vc_ >> _frame.getMatRef();
}
else if(_frame.kind() == _InputArray::GPU_MAT)
{
vc_ >> frame_;
arrCopy(frame_, _frame);
}
else if(_frame.kind() == _InputArray::OCL_MAT)
{
vc_ >> frame_;
if(!frame_.empty())
{
arrCopy(frame_, _frame);
}
}
else
{
//should never get here
}
}
class VideoFrameSource : public CaptureFrameSource
{
public:
VideoFrameSource(const string& fileName);
void reset();
private:
string fileName_;
};
VideoFrameSource::VideoFrameSource(const string& fileName) : fileName_(fileName)
{
reset();
}
void VideoFrameSource::reset()
{
vc_.release();
vc_.open(fileName_);
CV_Assert( vc_.isOpened() );
}
class CameraFrameSource : public CaptureFrameSource
{
public:
CameraFrameSource(int deviceId);
void reset();
private:
int deviceId_;
};
CameraFrameSource::CameraFrameSource(int deviceId) : deviceId_(deviceId)
{
reset();
}
void CameraFrameSource::reset()
{
vc_.release();
vc_.open(deviceId_);
CV_Assert( vc_.isOpened() );
}
}
Ptr<FrameSource> cv::superres::createFrameSource_Video(const string& fileName)
{
return new VideoFrameSource(fileName);
}
Ptr<FrameSource> cv::superres::createFrameSource_Camera(int deviceId)
{
return new CameraFrameSource(deviceId);
}
#endif // HAVE_OPENCV_HIGHGUI
//////////////////////////////////////////////////////
// VideoFrameSource_GPU
#if !defined(HAVE_OPENCV_GPU) || defined(DYNAMIC_CUDA_SUPPORT)
Ptr<FrameSource> cv::superres::createFrameSource_Video_GPU(const string& fileName)
{
(void) fileName;
CV_Error(CV_StsNotImplemented, "The called functionality is disabled for current build or platform");
return Ptr<FrameSource>();
}
#else // HAVE_OPENCV_GPU
namespace
{
class VideoFrameSource_GPU : public FrameSource
{
public:
VideoFrameSource_GPU(const string& fileName);
void nextFrame(OutputArray frame);
void reset();
private:
string fileName_;
VideoReader_GPU reader_;
GpuMat frame_;
};
VideoFrameSource_GPU::VideoFrameSource_GPU(const string& fileName) : fileName_(fileName)
{
reset();
}
void VideoFrameSource_GPU::nextFrame(OutputArray _frame)
{
if (_frame.kind() == _InputArray::GPU_MAT)
{
bool res = reader_.read(_frame.getGpuMatRef());
if (!res)
_frame.release();
}
else
{
bool res = reader_.read(frame_);
if (!res)
_frame.release();
else
arrCopy(frame_, _frame);
}
}
void VideoFrameSource_GPU::reset()
{
reader_.close();
reader_.open(fileName_);
CV_Assert( reader_.isOpened() );
}
}
Ptr<FrameSource> cv::superres::createFrameSource_Video_GPU(const string& fileName)
{
return new VideoFrameSource(fileName);
}
#endif // HAVE_OPENCV_GPU
这段代码是在 frame_source.cpp(第 161 行)中发现错误的地方:
void VideoFrameSource::reset()
{
vc_.release();
vc_.open(fileName_);
CV_Assert( vc_.isOpened() );
}
谁能帮帮我?
最佳答案
可能是您的编解码器有问题。该断言检查源是否可以打开。当它失败时,它会给你你描述的错误。它可能会失败,因为源不存在或者因为它无法打开文件格式或读取编解码器。您也可以尝试另一个 .avi 视频,看看是否有效。如果是,则可以确定是编解码器问题。
查看此 SO 帖子以了解一些检查编解码器的方法:Why can't I open avi video in openCV?
您可以通过打开 Linux 终端并键入以下内容来检查文件的编解码器:
ffmpeg -i video.3gp
然后就可以看到安装了哪些库,视频编码是什么。例如:
流:#0.0:视频 mjpeg (MJPG/0x47504A4D),yuvj422p,1280x720,30.02 tbr
显示 FFMPEG 工作正常(否则您会收到错误消息)并且文件是 MJPG 编码的。
另一个选项是您的 openCV 安装没有使用 FFMPEG 构建。您可以通过运行 cmake 来检查并检查是否检测到 cmake。它应该看起来像:
-- FFMPEG:是
显然有时您的 FFMPEG 可以安装和检测,但配置不正确。这个 SO 帖子显示了一个解决方案:VideoCapture is not working in OpenCV 2.4.2
关于c++ - OpenCV 错误 : Assertion failed (vc_. isOpened()) 复位,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25013234/
测试返回类型为 bool 的方法时。 你应该: expected = true; Assert.AreEqual(expected, actual); 或 Assert.IsTrue(actual);
我最近在编写新的 NUnit 测试时尝试使用 Assert.Equals() 方法。执行此方法时会抛出一个 AssertionException ,说明Assert.Equals 不应该用于断言。 乍
在 Chai 断言库中,当我们已经有了“assert.deepEqual()”时,“assert.equal()”有什么用"和 "assert.strictEqual()"用于严格和深度相等断言?还提
有没有办法断言 puppet 中的变量(或更具体地说,事实)具有特定值,如果没有则中止安装? 对于背景,情况如下: 在大多数情况下,我可以引用主机名,但有时我需要使用 IP 地址。例如,我们的日志收集
喜欢什么: Assert.That(obj.Foo, Is.EqualTo(true)) 或 Assert.True(obj.Foo) 对我来说,这两个断言是等价的,那么应该首选哪个? 最佳答案 在这
如何在 xUnit 中找到多个断言或软断言?我发现 Nunit 有以下能力,试图在 xUnit 中找到类似的选项。 Assert.Multiple(() => { Assert.AreEqua
有什么区别: Assert.Equals和 Assert.AreEqual Assert.NotNull和 Assert.IsNotNull ... ? 最佳答案 Assert.Equals 是一个对
我想写一个像这样工作的断言函数: //the following expression outputs "assertion failed" to std::err and then terminat
有人可以指出差异吗? 以上确实是我的问题,但是如果您也可以与他们分享您的经验以及您为什么使用其中一个。 最佳答案 它们只是两个不同的库,因此只需查看功能,尤其是报告功能,然后选择即可。 因为我是 的作
我无法找到断言 1 失败但断言 2 通过的原因: var a = Test.test1; var b = Test.test1; a.Should().BeSameAs(b); //1 Assert.
我正在为每个步骤使用 NUnit 断言运行自动化 BDD 步骤,即 Then And 我的 UI 测试。 NUnit 断言仅限于每个方法。这意味着如果方法中的断言失败,则不会运行其他步骤。 我正在考虑
关闭。这个问题不符合Stack Overflow guidelines .它目前不接受答案。 要求我们推荐或查找工具、库或最喜欢的场外资源的问题对于 Stack Overflow 来说是偏离主题的,
按照目前的情况,这个问题不适合我们的问答形式。我们希望答案得到事实、引用或专业知识的支持,但这个问题可能会引发辩论、争论、投票或扩展讨论。如果您觉得这个问题可以改进并可能重新打开,visit the
我只是在寻找一些示例,说明何时适合使用 Assert.Catch 或 Assert.Throws 断言单元测试中抛出的任何异常。我知道我也可以使用 ExpectedException,但我特别想知道“
Assert.AreEqual 和 Assert.AreSame 有什么区别? 最佳答案 这意味着 AreSame() 检查它们是否是完全相同的对象 - 如果引用指示内存中的相同对象。 AreEqua
在C#中,有什么区别 Assert.AreNotEqual 和 Assert.AreNotSame 最佳答案 这里给出的几乎所有答案都是正确的,但可能值得举个例子: public static str
我曾经在 NUnit 中使用过它们,它们非常有用。知道如何做类似的事情吗? 编辑,代码示例: bool condition = false;//would be nice not to have th
关于Arrange-Act-Assert的经典测试模式,我经常发现自己在 Act 之前添加了反断言。这样我就知道传递的断言确实是作为操作的结果传递的。 我认为它类似于红绿重构中的红色,只有当我在测试过
每当我创建断言时,Eclipse 都会建议我从这两个包之一导入它。 例如,当我尝试使用 assertArrayEquals() 比较数组时Eclipse 建议从其中之一导入它 org.junit.As
每当我创建断言时,Eclipse 都会建议我从这两个包之一导入它。 例如,当我尝试使用 assertArrayEquals() 比较数组时Eclipse 建议从其中之一导入它 org.junit.As
我是一名优秀的程序员,十分优秀!