std::vector<cv::Mat> image_temp,gif;报错:0612 11:17:02.008381 publisher.h:103] OpenCV(4.7.0) /app/source/opencv-4.7.0/modules/imgcodecs/src/loadsave.cpp:783: error: (-215:Assertion failed) !_img.empty() in function 'imwrite'
时间: 2024-01-27 14:05:43 浏览: 25
这个错误与你之前提到的错误信息一样,也是 OpenCV 的 Assertion failed 错误,出现在 imwrite 函数中。这个错误提示中的 !_img.empty() 含义同样是指图像对象不能为空。根据你提供的信息,你的代码中定义了两个 std::vector,分别是 image_temp 和 gif,这两个向量内部存储了一些 cv::Mat 类型的图像对象。因此,你需要检查这两个向量中的每个图像对象是否为空,如果为空,就无法保存为文件,因此就会出现这个错误。你可以使用 cv::Mat 的 empty() 函数来检查图像是否为空。
相关问题
在std::vector<std::vector<int>>删除某些std::vector<int>
在std::vector<std::vector<int>>中删除某些std::vector<int>可以使用erase-remove idiom的方法。这个方法结合了erase和remove两个函数,可以高效地删除指定的元素。
以下是删除某些std::vector<int>的步骤:
1. 使用std::remove_if函数结合lambda表达式来标记要删除的std::vector<int>。lambda表达式可以根据特定的条件来判断是否需要删除。
2. 使用std::erase函数将被标记为删除的std::vector<int>从std::vector<std::vector<int>>中移除。
下面是示例代码:
```cpp
#include <iostream>
#include <vector>
#include <algorithm>
int main() {
std::vector<std::vector<int>> vecOfVec = {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}, {10, 11, 12}};
// 删除满足条件的std::vector<int>
vecOfVec.erase(std::remove_if(vecOfVec.begin(), vecOfVec.end(), [](const std::vector<int>& vec) {
// 根据特定条件判断是否需要删除
return vec.size() == 3; // 删除长度为3的std::vector<int>
}), vecOfVec.end());
// 输出结果
for (const auto& vec : vecOfVec) {
for (const auto& num : vec) {
std::cout << num << " ";
}
std::cout << std::endl;
}
return 0;
}
```
输出结果:
```
4 5 6
7 8 9
```
std::vector<std::vector<float>>
std::vector<std::vector<float>> 是一个二维的 vector 容器,它可以存储多个一维的 std::vector<float> 对象。每个一维的 std::vector<float> 对象都可以存储一组 float 类型的值。
要初始化和定义一个 std::vector<std::vector<float>> 对象,你可以按照以下步骤进行操作:
1. 首先,定义一个二维的 std::vector<std::vector<float>> 对象,可以使用空的大括号进行初始化:
std::vector<std::vector<float>> myVector{};
2. 然后,为每个一维的 std::vector<float> 对象添加元素。你可以使用 push_back() 函数将一维的 std::vector<float> 对象添加到二维容器中:
myVector.push_back(std::vector<float>{1.0, 2.0, 3.0});
myVector.push_back(std::vector<float>{4.0, 5.0, 6.0});
3. 这样,你就创建了一个包含两个一维 std::vector<float> 对象的 std::vector<std::vector<float>>。
总结起来,要初始化和定义一个 std::vector<std::vector<float>> 对象,你可以使用空的大括号初始化,并逐个添加一维的 std::vector<float> 对象到二维容器中。