Saturday, January 08, 2005

Array to IplImage

// array2ipl.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include <cv.h>
#include <highgui.h>

int main(int argc,char *argv[])
{
IplImage *image;
int x,y;
float *data;
int step;

data = new float[640*480];

CvSize size;
/*
IplImage *array = cvLoadImage( "C:\\Data\\Tracking\\UL04\\img\\frameA10.bmp", 1);
cvGetRawData( array, (uchar**)&data, &step, &size );
step /= sizeof(data[0]);

*/
image = cvCreateImage(cvSize(640,480),8,1);
cvSetZero(image);

for(y=0 ; y < image->height ; y++) // get data values from images, just like 'imread'
{
for(x=0; x < image->width ; x++)
{
data[y*image->width +x] = (x*y)%255;
}
}

for(y=0 ; y < image->height ; y++)
{
for(x=0; x < image->width ; x++)
{
(image->imageData+image->widthStep*y)[x] = data[y*image->width +x]; // put data to a new image file
}
}

(image->imageData+image->widthStep*(image->height/2))[image->width/2] = 0; // draw one spot

cvNamedWindow("Image",1);
cvShowImage("Image",image);
cvWaitKey(0);
delete []data;

return 0;
}

No comments:

Post a Comment