Opencv在运行一个简单程序时抛出了一个奇怪的错误
Opencv throwing a weird error running a simple program
我编译了这个简单的opencv代码:
#include "opencv2/core/core.hpp"
#include "opencv2/highgui/highgui.hpp"
#include <boost/random.hpp>
#include <ctime>
#include <time.h>
#include <stdlib.h>
#include <math.h>
#include <iostream>
/*Compile using
g++ -I /usr/local/boost CreateShares.cpp -o createShares `pkg-config --cflags --libs opencv`
*/
using namespace cv;
class CreateShares
{
private:
cv::Mat CoreImage;
cv::Mat CoreImageR;
cv::Mat CoreImageG;
cv::Mat CoreImageB;
cv::Mat share0;
cv::Mat share1;
cv::Mat share2;
cv::Mat share3;
public:
CreateShares();
CreateShares(std::string path);
void showCoreImage();
void showCoreImageR();
void showCoreImageG();
void showCoreImageB();
};
CreateShares::CreateShares()
{
}
CreateShares::CreateShares(std::string path)
{
CoreImage = cv::imread(path, 1);
if (CoreImage.empty())
{
std::cout<<"Could not read image !"<<std::endl;
return;
}
std::vector<cv::Mat> temp_mat_vector;
cv::split(CoreImage, temp_mat_vector);
//CoreImageB = (temp_mat_vector[0]).clone();
temp_mat_vector[0].copyTo(CoreImageB);
temp_mat_vector[1].copyTo(CoreImageB);
temp_mat_vector[2].copyTo(CoreImageB);
}
void CreateShares::showCoreImage()
{
cv::namedWindow("Core Image", WINDOW_AUTOSIZE);
cv::imshow("Core Image", CoreImage);
}
void CreateShares::showCoreImageR()
{
cv::namedWindow("Core Image R", WINDOW_AUTOSIZE);
cv::imshow("Core Image R", CoreImageR);
}
void CreateShares::showCoreImageG()
{
cv::namedWindow("Core Image G", WINDOW_AUTOSIZE);
cv::imshow("Core Image G", CoreImageG);
}
void CreateShares::showCoreImageB()
{
cv::namedWindow("Core Image B", WINDOW_AUTOSIZE);
cv::imshow("Core Image B", CoreImageB);
}
int main()
{
std::string path = "/home/r/l33t/Secret Sharing/nature.jpg";
CreateShares* cs = new CreateShares(path);
cs->showCoreImage();
return 0;
}
然后我继续运行它,但我得到了一个奇怪的错误:
r@r-HP-Mini-110:~/l33t/Secret Sharing$ g++ -g -I /usr/local/boost CreateShares.cpp -o createShares `pkg-config --cflags --libs opencv`
r@r-HP-Mini-110:~/l33t/Secret Sharing$ ./createShares
OpenCV Error: Bad flag (parameter or structure field) (Unrecognized or unsupported array type) in cvGetMat, file /build/buildd/opencv-2.3.1/modules/core/src/array.cpp, line 2482
terminate called after throwing an instance of 'cv::Exception'
what(): /build/buildd/opencv-2.3.1/modules/core/src/array.cpp:2482: error: (-206) Unrecognized or unsupported array type in function cvGetMat
Aborted (core dumped)
我正在粘贴gdb输出,直到出现错误,以帮助您分析:
(gdb) next
[New Thread 0xb4af2b40 (LWP 17550)]
[New Thread 0xb40ffb40 (LWP 17551)]
65 s::showCoreImage()
(gdb) step
CreateShares::showCoreImageR (this=0x80516e8) at CreateShares.cpp:78
78 ", CoreImageR);
(gdb) step
79 G()
(gdb) step
OpenCV Error: Bad flag (parameter or structure field) (Unrecognized or unsupported array type) in cvGetMat, file /build/buildd/opencv-2.3.1/modules/core/src/array.cpp, line 2482
terminate called after throwing an instance of 'cv::Exception'
what(): /build/buildd/opencv-2.3.1/modules/core/src/array.cpp:2482: error: (-206) Unrecognized or unsupported array type in function cvGetMat
Program received signal SIGABRT, Aborted.
0xb7fdd424 in __kernel_vsyscall ()
(gdb)
有什么想法吗?我的代码有什么问题吗,或者opencv有什么问题,或者我没有在某个地方包含一些opencv路径,或者openpv没有正确安装?我没有主意了。请帮帮我!
这是一个数据类型不匹配的问题
相关文章:
- 试图修复一个错误,该错误不会让我开始编程其余部分
- MSVC 无法根据模板参数进行数学运算,这是一个错误吗?
- 我正在尝试一个傻瓜 C++ 练习,我遇到了一个错误,说类 'GraduateStudent' 没有任何名为 'advisor' 的字段
- 零四元数和任何向量都不为零的特征积,这是一个错误吗?
- 处理程序的模块列表中有一个错误的模块"WebSocketModule"
- 在 C++ 中使用 "transform" 会给出一个错误,指出这未在作用域中声明
- 在Cython中使用C库时,我遇到了一个错误
- 我需要帮助创建一个评分系统,但它一直给我一个错误,注释掉的整数是给我带来麻烦的部分
- 我试图用c++编写递归fibonacci序列,但当我编译时,我遇到了一个错误
- 从system()调用G++会返回一个错误
- 在Visual Studio中,与std::async一起使用时不调用"thread_local"变量"析构函数,这是一个错误吗?
- 我收到一个错误无效的操作数,类型为 const char [42] 和二进制"运算符+"的双倍数
- 使用声明:GCC 和 Clang 的另一个错误?
- 全球免费给出一个错误.调试器不解释
- 相对于继承的构造函数,gcc 编译器是否还有一个错误?
- 为什么直接传递"this"指针来存档是一个错误,而另一个相同类型的指针是可以的?
- 为什么第三板有一个错误
- 如何编写一个错误结构,该结构可以包含不同的强键枚举作为错误代码
- 使用本地类型声明的G lambda被使用但从未定义 - 确实是一个错误
- 我需要在 Android Studio 中构建 NDK. 但它返回一个错误