1
我編這個簡單的OpenCV代碼: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;
}
然後我繼續運行它,但我得到這個奇怪的錯誤:
[email protected]:~/l33t/Secret Sharing$ g++ -g -I /usr/local/boost CreateShares.cpp -o createShares `pkg-config --cflags --libs opencv`
[email protected]:~/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路徑,或者opencv安裝不正確?我沒有想法。請幫幫我 !
在我的系統,當我運行它工作得很好,只要我改變路徑是我的系統上的圖像節目。如果我沒有提供一個實際存在的圖像的路徑,那麼我得到一個像你顯示的錯誤。 – 2013-02-23 16:29:24
當您按頻道分割圖像時,您將每個頻道分配給'CoreImageB'而不是相應的頻道。因此,你的'CoreImageR'和'CoreImageG'保持空白,這可能會導致'imshow'行爲不當。 – 2013-02-23 16:32:19
謝謝。 – Chani 2013-02-23 16:32:40