在矢量Opencv中加载许多图像<Mat>
Load many images in vector<Mat> Opencv
我试图将多个图像存储在矢量上的文件夹中以供稍后处理。问题是我得到了错误:
*Debug Assertion Failed!
Expression: vector subscript out of range.*
我要测试的代码如下:
stringstream Nombre2;
vector<Mat> Imagen2;
for (int a=0; a<=Count;a++)
{
Nombre2.clear();
Nombre2 << "C:\Users\Azu\Documents\Visual Studio 2010\Projects\SIFT2\SIFT2\BBDDFaces\"<< a+1 << ".pgm";
imread(Nombre2.str()).copyTo(Imagen2[a]);
}
图像名称为数字:1。的pgm, 2。Pgm,等等…
如果有人能帮我解决这个问题,我会很感激的。所以,在你的代码中:
// since Imagen2 is empty, Imagen2[a] is an access violation.
imread(Nombre2.str()).copyTo(Imagen2[a]);
不要使它过于复杂,只需使用cv::format代替stringstream,并且不要使用无用的copyTo():
vector<Mat> images; // another thing. use english for variable names, nothing else...
for (int a=0; a<Count;a++) // a <=Count would do one too many...
{
string name = format("C:\bla\BBDDFaces\%d.pgm", a);
Mat img = imread(name); // pgm implies grayscale, maybe even: imread(name,0); to return CV_8U
if ( img.empty() ) // please, *always check* resource-loading.
{
cerr << "whaa " << name << " can't be loaded!" << endl;
continue;
}
images.push_back(img);
// show result:
imshow("test",img);
waitKey(); // yes, you need the waitKey()
}
我的眼睛。我找到了这个表格。
String filename = "lg.mp4"; //SOLO FUNCIONA CON VIDEOS TIPO MP4
VideoCapture capture(filename);
Mat frame;
Mat imagenesT;
vector<Mat> images; // almacenar imagenes en la cola
Mat converted_image;
double dHeight = capture.get(CV_CAP_PROP_FRAME_COUNT);
cout<< "tiene frames ___" << dHeight << endl;
if( !capture.isOpened() )
throw "Error when reading steam_avi";
capture >> frame;
cvtColor(frame, converted_image, CV_BGR2GRAY);//2XYZ);
for(int i=0 ;i< 584;i++ )
{
capture >> frame;
if(frame.empty())
break;
cvtColor(frame, converted_image, CV_BGR2GRAY);//2XYZ);
images.push_back(converted_image.clone()); //almacenar imagenes en la cola
imshow("out", converted_image);
imshow("in",frame);
waitKey(20); // waits to display frame
}
for(int i=0 ;i< 584;i++ )
{
imshow("salida1",images[i]);
waitKey(30);
}
相关文章:
- Difference in displaying cv2 Mat
- 请解释这句话(cout<<1+int((a<b)^((b-a)&1) )<<endl
- 呼叫运营商<<临时
- 为什么Mat类的两个对象可以在不重载运算符+的情况下添加
- 如何防止clang格式在流运算符调用之间添加换行符<<
- <<操作员在下面的行中工作
- 将CHW格式的浮点向量转换为cv::Mat
- C++中的openCV Mat访问冲突
- OpenCV 和从 OutputArrays 或 (Mat) 读取数据
- 使用 mat.at<uchar>(i,j) 的 opencv C++中的矩阵赋值错误
- C++:从GPU内存(cudaMemcpy2D)获取BGR图像(cv::Mat)
- 选择基于另一个垫子的非零像素的cv::Mat的一部分?
- 将 cv::mat 转换为 QImage
- 两个垫子的 OpenCV 数据是相同的,但使用 Mat::at 检索时的值已损坏
- 将 cv::Mat 转换为 std::vector 的通用函数
- 如何通过引用传递OpenCV MAT
- 在 QML VideoOutput 中将 cv::mat 显示为 QVideoFrame
- Read OpenCV Mat 16bit to QImage 8bit Greyscale
- 将本地 OpenCV Mat 变量声明为静态以防止重新分配
- 将 OpenCv Mat 从 C++ 传递给 Python