How to save raw pixel values as image and display it?

asked 2016-05-13 01:01:03 -0600

Flower gravatar image

updated 2016-05-13 03:00:12 -0600

I am using C and OPENCV in Ubuntu 14.04 platform. I have accessed the pixels of the input image (gray scale), compressed them and then reconstructed them back. Now I have a single vector of reconstructed pixel values of size 65536 X 1 (i.e. vi[65536]). I tried in various methods to convert these raw pixels into image so that i can display it. but I failed. Here is the process that I used.

uchar *output = (uchar*)image->imageData;

Then I reconstructed the input image and have saved the pixel values as vector in vi[]

for (i=0; i < 65536; i=i+1) 
{
output->imageData[i]=vi[i];
}
cvSaveImage("foo.png", output, 0);
cvNamedWindow("foo", CV_WINDOW_AUTOSIZE);
cvShowImage( "foo", output );
cvReleaseImage(&output);
cvWaitKey(0);
return 0;

But I am not able to save the pixel values as image and display it. Where have I gone wrong? I am using C. Kindly help me in a step by step manner. I am new to both C and OpenCV.

edit retag flag offensive close merge delete

Comments

1

please do not use opencv's arcane c-api (which was abandoned in 2010 already)

... and have a look at the basic tutorials

berak gravatar imageberak ( 2016-05-13 01:03:47 -0600 )edit

Unknowingly I started with C. Now that I am almost in the verge of completing my project, I need this little conversion. With this last process, my work will be over. That is why I am not able to skip using C. Kindly help me out if possible.

Flower gravatar imageFlower ( 2016-05-13 02:19:25 -0600 )edit