Eric Q
Eric Q

Reputation: 83

Loading an array of pixel values in OpenCV

I have a 32-bit integer array containing pixel values of a 3450x3450 image I want to create a Mat image with. Tried the following:

int *image_array;
image_array = (int *)malloc( 3450*3450*sizeof(int) );
memset( (char *)image_array, 0, sizeof(int)*3450*3450 );
image_array[0] = intensity_of_first_pixel;
...
image_array[11902499] = intensity_of_last_pixel;
Mat M(3450, 3450, CV_32FC1, image_array);

and upon displaying the image I get a black screen. I should also note the array contains a 16-bit grayscale image.

Upvotes: 0

Views: 948

Answers (1)

ZdaR
ZdaR

Reputation: 22964

I guess you should try to convert the input image, which I assume is in RGB[A] format using:

cv::Mat m(3450, 3450, CV_8UC1, image_array) // For GRAY image
cv::Mat m(3450, 3450, CV_8UC3, image_array) // For RGB image
cv::Mat m(3450, 3450, CV_8UC4, image_array) // For RGBA image

Upvotes: 1

Related Questions