ofImage ofxDepthImageCompressor::readDepthFrametoImage(string filename) {
	unsigned short* depthFrame = readDepthFrame(filename);
	ofImage outputImage = convertTo8BitImage(depthFrame);
	
	delete depthFrame;
	return outputImage;
}
unsigned short* ofxDepthImageCompressor::readDepthFrame(string filename, unsigned short* outbuf) {
	ofFile infile(filename, ofFile::ReadOnly, true);
	return readDepthFrame(infile, outbuf);
}
void Readvideo::readvideo(string filePath)
{
	clock_t start, durTime;
	start=clock();
	if( !( readColorFrame(filePath) && readDepthFrame(filePath) && readSkeletonFrame(filePath) ))
	{
		return;
	}	

	if( !( vSkeletonFrame.size() == vColorFrame.size() && vSkeletonFrame.size() == vDepthFrame.size() ))
	{
		return;
	}

	string str = filePath.substr(filePath.length()-25,21);
	cout<<str<<endl;
	cout<<"Reading..."<<endl;
	const char* savefilename=str.c_str();

	//读取彩色、深度和骨架数据
	const char* filePathChar=filePath.c_str();
	char filePathName[100];
	strcpy(filePathName,filePathChar);
	strcat(filePathName,"\\color.avi");
	CvCapture *capture = cvCreateFileCapture(filePathName);
	if( NULL == capture )
		return;

	int x,y;
	ifstream depthFileReader;
	depthFileReader.open(filePath+"\\depth.dat",ios::binary);
	if(depthFileReader == NULL)
		return;

	ifstream skeletonFileReader;
	skeletonFileReader.open(filePath+"\\skeleton.dat",ios::binary);
	if(skeletonFileReader == NULL)
		return;

	//read first color depth and skeleton data
	IplImage *frame = cvQueryFrame(capture);
	vColorData.push_back(cvCloneImage(frame));

	Mat depthMat;
	depthMat.create(r_heigth,r_width,CV_16UC1);
	ushort *depthData = new ushort[r_width*r_heigth];
	depthFileReader.read((char*)depthData,r_width*r_heigth*sizeof(ushort));
	if( !depthFileReader.fail() )
	{
		for(y=0; y<r_heigth; y++)
		{
			for(x=0; x<r_width; x++)
			{
				depthMat.at<ushort>(y,x) = depthData[y*r_width+x];
			}
		}
	}	
	delete [] depthData;
	vDepthData.push_back(depthMat.clone());

	SLR_ST_Skeleton mSkeleton;
	skeletonFileReader.read((char*)&mSkeleton,sizeof(mSkeleton));
	

	SLR_ST_Skeleton sLast = mSkeleton;
	SLR_ST_Skeleton sCurrent;
	int index = 0;

	vSkeletonData.clear();
	vSkeletonData.push_back(mSkeleton);
	
	int stillCount = 0;

	while(index < vSkeletonFrame.size()-1)
	{
		//读取下一帧的彩色、深度和骨架数据
		index++;
		frame = cvQueryFrame(capture);
		vColorData.push_back(cvCloneImage(frame));
		
		depthData = new ushort[r_width*r_heigth];
		depthFileReader.read((char*)depthData,r_width*r_heigth*sizeof(ushort));
		if( !depthFileReader.fail() )
		{
			for(y=0; y<r_heigth; y++)
			{
				for(x=0; x<r_width; x++)
				{
					depthMat.at<ushort>(y,x) = depthData[y*r_width+x];
				}
			}
		}	
		delete [] depthData;
		vDepthData.push_back(depthMat.clone());
		skeletonFileReader.read((char*)&sCurrent,sizeof(sCurrent));

		//if begin, judge end time and do hand sgementation
		vSkeletonData.push_back(sCurrent);
		sLast = sCurrent;

	}


	durTime=clock()-start;
	cout<<"Read Data Time:	"<<durTime<<endl;

	start=clock();

	depthFileReader.close();
	skeletonFileReader.close();
	cvReleaseCapture(&capture);
}