我在Windows XP 32位下使用OpenCV 2.4.2的VideoCapture类时遇到问题.它没有打开任何文件或相机,并修复它是一个痛苦.我正在使用visual studio 2010,但我也在QTcreator中尝试了相同的结果.
测试代码如下:
#include "opencv/cv.h"
#include "opencv/highgui.h"
#include <iostream>
#include <string>
#include <iomanip>
#include <sstream>
using namespace cv;
using namespace std;
int main()
{
const char* videoPath = "C:/video/";
string videoName = string(videoPath) + "avi.avi";
VideoCapture cap(videoName);
if(!cap.isOpened())
{
std::cout<<"Fail"<<std::endl;
return -3;
}
return 0;
}
Run Code Online (Sandbox Code Playgroud)
输出始终为"-3".Qt Creator显示警告:打开文件时出错(../../modules/highgui/src/cap_ffmpeg_impl.hpp:361)
我调试了它,问题出现在第一行:
CvCapture* cvCreateFileCapture_FFMPEG_proxy(const char * filename)
{
CvCapture_FFMPEG_proxy* result = new CvCapture_FFMPEG_proxy;
if( result->open( filename ))
return result;
delete result;
#if defined WIN32 || defined _WIN32
return cvCreateFileCapture_VFW(filename); …Run Code Online (Sandbox Code Playgroud) 我在Qt中开发一个应用程序,在某些时候处理一堆视频.它工作正常,但它在进程阶段只有40-60%的CPU使用率,所以我试图使它多线程.
我使用QtConcurrent导致他的"高水平"而不是更传统的线程管理,我的代码很简单:
for(int i = 0; i < totalVideos; i++)
{
QFuture<ResultClass *> futureToken = QtConcurrent::run(this, process, listOfVideos.takeFirst());
QFutureWatcher<ResultClass *>* fw = new QFutureWatcher<ResultClass *>();
connect(fw, SIGNAL(finished()), this, SLOT(manageResult));
fw->setFuture(futureToken);
}
Run Code Online (Sandbox Code Playgroud)
aaaand它的工作原理,100%的CPU使用率和大约25-30%的速度.但它产生了大约65个新线程(无论它处理25或250个视频),并且大多数线程在处理阶段后不会消失.
我的问题是:这种做法是对的吗?太粗糙了吗?我应该"手动"控制线程创建吗?QtConcurrent模块是否完全处理,所以我不应该关心线程管理?85个线程太多了吗?我是否应该尝试在流程阶段后杀死其中一些?
只需查看活动监视器即可完成每个观察.
提前致谢.
在附加的代码片段中,我预计:std::vector<C> d = { {} };会导致编译器错误,因为B无法默认构造。那么如果没有错误,我希望d.size()是1。这是意外行为还是我错过了一些不言而喻的事情?
#include <array>
#include <algorithm>
#include <iostream>
#include <vector>
struct A {};
struct B {
B( int ) {}
};
struct C {
A a;
B b;
};
int main() {
::std::vector<C> d = { {} }; //ok?!?!
//::std::vector<C> d2 = { C() }; Error
//C c; Error
//d.push_back( {} ); Error
//d.push_back( { {}, { 3 } } ); Ok
return d.size(); // 0 instead of …Run Code Online (Sandbox Code Playgroud)