1

I have a a raw image file which contains image data from the 5th byte onwards. Each byte in the file represents a 8 bit greyscale pixel intensity. I have been able to store the binary data of the image in a 2-D unsigned char array.

Can anyone tell me how to use the array or the file to display the image in openCV?

Right now I am using this code :

void openRaw() {
    cv::Mat img(numRows,numCols,CV_8U,&(image[0][0]);
    //img.t();
    cv::imshow("img",img);  
    cv::waitKey();
}

But its displaying a wrong image.

I also tried using the IplImage method, but I am not sure how to pass the pointer to the source image there.

Could anyone provide me with some code for this?

Thanks, Uday

4

1 回答 1

1

“我已经能够将图像的二进制数据存储在二维无符号字符数组中。”

那是你的问题。

opencv 将像素数据存储在连续的 uchar* 中,因此它对您的期望也相同。

你的二维数组很可能是一个指针数组,它不一样。

所以:而不是 2d 数组,制作 1d :

uchar *data = new uchar[rows * cols];

您可以在那里访问单个像素,例如:

uchar pixel = data[y*cols+x];    

然后将数据指针传递到您的 cv::Mat :

cv::Mat img( rows, cols, CV_8U, data );

哦,请不要再使用 IplImages(又名 1.0 api),不惜一切代价避免!

于 2013-03-10T12:10:45.850 回答