Ask Your Question

Flower's profile - activity

2016-05-13 02:19:25 -0600 commented question How to save raw pixel values as image and display it?

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.

2016-05-13 01:02:11 -0600 received badge  Editor (source)
2016-05-13 01:01:03 -0600 asked a question How to save raw pixel values as image and display it?

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.

2016-04-15 04:23:26 -0600 commented question I get the error: segmentation error: (core dumped) when I try to run my C code which uses Oen CV library. Where am I wrong?

I found out where I went wrong. I had used 'j' instead of 'i' in the loop 'for (i=0; i<image->height; j++)'. Thank you so much. :)

2016-04-14 09:19:53 -0600 commented question I get the error: segmentation error: (core dumped) when I try to run my C code which uses Oen CV library. Where am I wrong?

I am trying to access the pixel values of the image which are stored in the pointer 'input' for further processing. I am using Ubuntu.

2016-04-14 08:19:45 -0600 asked a question I get the error: segmentation error: (core dumped) when I try to run my C code which uses Oen CV library. Where am I wrong?

I use the following code for reading and displaying the image, and to display the data in the image:

#include <opencv2/highgui/highgui.hpp>
#include<stdio.h>
#include<stdlib.h>

int main()
{
IplImage* image = cvLoadImage("lena.jpg",0);
IplImage* output;
cvNamedWindow("lena", CV_WINDOW_AUTOSIZE);
cvShowImage( "lena", image );
//cvDestroyWindow( "lena" );

//intializations
int h=1, blk_siz=8, sparsity=20, r=0;
int ext = blk_siz-1; int rb, cb, n_blocks, x, y, i, j;
int rows = 512/blk_siz;
int columns = 512/blk_siz;
int v[262144] = {0};
rb = rows/blk_siz;
cb = columns/blk_siz;
n_blocks = rb*cb;

uchar *input = (uchar*)image->imageData;
x=image->height;
y=image->width;
printf("%d\n", x);
printf("%d\n", y);

for (i=0; i<image->height; j++)
{
for (j=0; j<image->width; j++)
{
v[r] = input[i*image->width + j];
printf("%d\n", v[r]);
r = r+1;
}
printf("\n");
}
cvReleaseImage(&image);
cvWaitKey(0);
return 0;
}
2016-04-11 00:03:08 -0600 asked a question I am new to OpenCV and I am writing code using C in OpenCV. I have an IplImage object file that I want to convert into matrix file. How can I do that?

I tried to create an empty matrix using Mat function but it shows me error.