只想在一個窗口中顯示float數組,我使用的代碼是:問題顯示float數組與OpenCV的
CvSize size;
size.height = HEIGHT ; //(640)
size.width = WIDTH; //(1680)
IplImage* ipl_image_p = cvCreateImageHeader(size, IPL_DEPTH_32F, 1);
ipl_image_p->imageData = (char*)my_float_image_data; //imageData only accepts char*
ipl_image_p->imageDataOrigin = ipl_image_p->imageData;
cvNamedWindow("Image", 1);
cvShowImage("Image", ipl_image_p);
cvWaitKey(0);
cvDestroyAllWindows();
彈出是全白的圖像。我究竟做錯了什麼 ?
感謝
編輯:
感謝Martin貝克特快速回答這個。我也有與16位圖像相同的問題,是否鏈接? (我的圖像從0到1000的範圍內)
unsigned short* temp = new unsigned short[HEIGHT*WIDTH];
for(int i = 0 ; i < HEIGHT*WIDTH; i++){
temp[i] = (unsigned short)my_float_image_data[i];
}
CvSize size;
size.height = HEIGHT ;
size.width = DISPLAY_DATA_WIDTH;
IplImage* ipl_image_p = cvCreateImageHeader(size, IPL_DEPTH_16U, 1);
ipl_image_p->imageData = (char*)temp;
ipl_image_p->imageDataOrigin = ipl_image_p->imageData;
cvNamedWindow("Image", 1);
cvShowImage("Image", ipl_image_p);
cvWaitKey(0);
cvDestroyAllWindows();
AFAIK你不能顯示16位數據 - 您需要先轉換爲8位,請參閱cvtColor() – 2011-02-25 19:17:22