cv::Mat image;
對象,這是我從文件加載的圖像,它正確地和所有讀取它。
現在我寫了一個函數將其轉換爲灰色。
cv::cvtColor(image, image, CV_RGB2GRAY);
而這個錯誤出現:
OpenCV Error: Assertion failed (scn == 3 || scn == 4) in cvtColor, file /build/buildd/opencv-2.3.1/modules/imgproc/src/color.cpp, line 2834
terminate called after throwing an instance of 'cv::Exception'
what(): /build/buildd/opencv-2.3.1/modules/imgproc/src/color.cpp:2834: error: (-215) scn == 3 || scn == 4 in function cvtColor
可能是什麼問題呢?
這是我的讀取的圖像(通過imagehandler類,其具有構件CV ::墊m_image)
imagehandler::imagehandler(const std::string& fileName)
: m_image(imread(fileName, CV_LOAD_IMAGE_COLOR))
{
if(!m_image.data)
{
cout << "Failed loading " << fileName << endl;
}
}
您確定您將'image'作爲彩色圖像讀取嗎? – Sassa
我該怎麼做? – TheNotMe
看看[imread](http://docs.opencv.org/modules/highgui/doc/reading_and_writing_images_and_video.html?highlight=imread#imread)。你如何在你的代碼中讀到你的? – Sassa