Hi, I'm baeckgoo
I tried to converting RGB image in pxcimage into data in IplImage.
It succeeeded.
But, I don't know how to depth image of pxcimage into IplImage data.
I know, type of depth data in pxcimage is float.
how can I convert this into IplImage??
Can I get a kind of hint or explanation?
Anyone know??
my code is following.
cf) when I'd like to get depth data, I tried to using unsigned char instead of float type . But, it fail.
---
#include <cv.h>
#include <highgui.h>
#include <stdio.h>
//#include "stdafx.h"
#include "util_render.h"
#include "util_pipeline.h"
int main()
{
UtilPipeline pipeline;
pipeline.EnableImage(PXCImage::COLOR_FORMAT_RGB24,640,480);
pipeline.EnableImage(PXCImage::COLOR_FORMAT_DEPTH,320,240); //depth resolution은 320,240가 maximum 인듯
pipeline.Init();
UtilRender color_render(L"Color Stream");
UtilRender depth_render(L"Depth Stream");
///////////// OPENCV
IplImage *image=0;
CvSize gab_size;
gab_size.height=480;
gab_size.width=640;
image=cvCreateImage(gab_size,8,3);
IplImage *depth=0;
CvSize gab_size_depth;
gab_size_depth.height=240;
gab_size_depth.width=320;
depth=cvCreateImage(gab_size,8,1);
//PXCImage *color_image=0;
PXCImage::ImageData data;
PXCImage::ImageData data_depth;
unsigned char *rgb_data;//=new unsigned char[];
float *depth_data;
//rgb_data=(unsigned char*)image->imageData;
PXCImage::ImageInfo rgb_info;
PXCImage::ImageInfo depth_info;
cvNamedWindow("depth_cv2",0);
cvResizeWindow("depth_cv2",320,240);
///////
for (;;) {
if (!pipeline.AcquireFrame(true)) break;
PXCImage *color_image=pipeline.QueryImage(PXCImage::IMAGE_TYPE_COLOR);
PXCImage *depth_image=pipeline.QueryImage(PXCImage::IMAGE_TYPE_DEPTH );
color_image->AcquireAccess(PXCImage::ACCESS_READ_WRITE,PXCImage::COLOR_FORMAT_RGB24,&data); //이거 release 해야대나?
depth_image->AcquireAccess(PXCImage::ACCESS_READ,&data_depth);
//depth_image->AcquireAccess(PXCImage::ACCESS_READ_WRITE,PXCImage::
//(unsigned char*)image->imageData=data.planes[0];
rgb_data=data.planes[0];
depth_data=(float*)data_depth.planes[0]; //(그냥 (float) 하면 error 나고, (float*)하면 error가 안나네.
printf("0=%f\n",*depth_data[0]); //921600을 프린트 하면 다 0나옴..그 이유는640*480*3=921600 이라서. 921599까지 픽셀값이들어있음.
// printf("1=%f\n",depth_data[1]);
// printf("2=%f\n",depth_data[2]);
// printf("3=%f\n",depth_data[3]);
// printf("4=%f\n",depth_data[4]);
pxcStatus stat1 = depth_image->QueryInfo(&depth_info);
// pxcStatus stat2 = color_image->QueryInfo(&rgb_info);
int w1=depth_info.width;
int h1=depth_info.height;
// printf("w=%d ,h=%d\n",w1,h1);
// int w2=rgb_info.width;
// int h2=rgb_info.height;
//printf("%d\n",depth_data[230400]);
for(int y=0; y<480; y++)
{
for(int x=0; x<640; x++)
{
for(int k=0; k<3 ; k++)
{
image->imageData[y*640*3+x*3+k]=rgb_data[y*640*3+x*3+k];
}
}
}
for(int y=0; y<240; y++)
{
for(int x=0; x<320; x++)
{
depth->imageData[y*320+x]=depth_data[y*320+x];
}
}
color_image->ReleaseAccess(&data);
depth_image->ReleaseAccess(&data_depth);
cvShowImage("rgb_cv",image);
cvShowImage("depth_cv2",depth);
/////////////opencv
if( cvWaitKey(10) >= 0 )
break;
////////
//if (!color_render.RenderFrame(color_image)) break; //이게 윈도우에 이미지 뿌려주는거인듯.
if (!depth_render.RenderFrame(depth_image)) break;
pipeline.ReleaseFrame();
}
cvReleaseImage(&image);
cvReleaseImage(&depth);
pipeline.Close();
return 0;
}



