0
我使用cvLoadImage將圖像(原始圖像)讀入CvMat,並通過中間數據塊將其數據指針指定給另一個CvMat,然後使用cvShowImage顯示此CvMat,但只顯示原始圖像的一小部分區域在與原始圖像大小相同的窗口中。如何使用OpenCV將數據保存到圖像中?
char* filename = "image\\neuron.tif"; // an 8bits grayscale image
IplImage* iplImage = cvLoadImage(filename);
int width = iplImage->width;
int height = iplImage->height;
cvNamedWindow("Original", CV_WINDOW_AUTOSIZE);
cvShowImage("Original", iplImage); // showed properly
cvWaitKey();
CvMat* header = cvCreateMatHeader(height, width, CV_8UC1);
CvMat* img_mat = cvGetMat(iplImage, header);
unsigned char* img_host = (unsigned char*)malloc(height * width * sizeof(unsigned char));// the intermediate data block, on which I need to apply a cuda operation
img_host = img_mat->data.ptr;
CvMat* blur_mat = cvCreateMat(height, width, CV_8UC1);
blur_mat->data.ptr = img_host;
cvNamedWindow("Blurred", CV_WINDOW_AUTOSIZE);
cvShowImage("Blurred", blur_mat); // the problem described
cvWaitKey();
其實,當我嘗試 「img_host = img_mat-> data.ptr」,但我不知道什麼是錯的問題發生。
將cvLoadImage(文件名)更改爲cvLoadImage(文件名,CV_LOAD_IMAGE_GRAYSCALE); – eyllanesc
您使用**陳舊** C api的任何特定原因? – Miki
@Miki我想對圖像數據矩陣進行其他CUDA操作,所以我選擇C api ...真的很慚愧,我發佈了這個亂碼 – Zhang