1
當我試圖將彩色圖像轉換爲灰度時,我遇到了一個問題。錯誤是:「在cvGetSize」中的錯誤參數(數組應該是CvMat或IplImage),但是當我評論所有與灰度相關的行時,我可以設法加載原始的彩色圖像並顯示它。我該如何解決這個錯誤?在OpenCV中將彩色圖像轉換爲灰度問題
#include <opencv\cv.h>
#include <opencv\highgui.h>
#include <iostream>
#include <stdio.h>
int main(int argc, char** argv)
{
//Loading the color image
IplImage* frame = cvLoadImage("lena.jpg");
//Converting the color image to grayscale
IplImage* grayframe = cvCreateImage(cvGetSize(frame), IPL_DEPTH_8U, 1);
cvCvtColor(frame, grayframe, CV_RGB2GRAY);
//Creating a window for color image
cvNamedWindow("Example1", CV_WINDOW_AUTOSIZE);
//Creating a window for grayscale image
cvNamedWindow("Example2", CV_WINDOW_AUTOSIZE);
// Showing the color image
cvShowImage("Example1", frame);
// Showing the grayscale image
cvShowImage("Example2", grayframe);
//Showeing for X seconds
cvWaitKey(2000);
cvReleaseImage(&frame);
cvDestroyWindow("Example1");
cvReleaseImage(&grayframe);
cvDestroyWindow("Example2");
return 0;
}
兄弟,用CV ::墊用imread獲取圖像。也花了幾個小時[在這裏](http://docs.opencv.org/doc/tutorials/tutorials.html)。 – William