Esempio n. 1
0
void Video::update()
{
    if( mMovie.checkPlayable() ){
        Area area = mMovie.getSurface().getBounds();
        mFrameSurface = ci::Surface(area.getWidth(), area.getHeight(), true);
		mFrameSurface.copyFrom(mMovie.getSurface(), mFrameSurface.getBounds() );
        
        /*
        mFrameSurface = ci::Surface(mMovie.getSurface());
        mFrameTexture = gl::Texture(mFrameSurface, mFrameFormat);
        */
        
        Surface::Iter iter = mFrameSurface.getIter( mFrameSurface.getBounds() );

        while( iter.line() ) {
            while( iter.pixel() ) {
                //if (iter.b() > 50 && iter.r() < 50 && iter.g() < 50){
                if (iter.g() > 50 && iter.g() > iter.r() && iter.g() > iter.b()){
                    //std::cout << "yes" << std::endl;
                    //iter.r() = 0;
                    //iter.g() = 0;
                    //iter.b() = 0;
                    iter.a() = 0;
                }
                else{
                    iter.a() = 255;
                    //std::cout << "no" << std::endl;
                }
            }
        }
        //mFrameSurface = ci::Surface( loadImage( loadResource( "bomb.png")) );
        mFrameTexture = gl::Texture(mFrameSurface, mFrameFormat);
         
    }
    //mCenteredRect = Rectf( mFrameTexture.getBounds() ).getCenteredFit( getWindowBounds(), true );
    mCenteredRect = Rectf(-40,0,800,600);
    
   
     
}
void CinderOpenNISkeleton::setDepthSurface() {
	int texWidth =  gCinderOpenNISkeleton->mDepthMD.XRes();
	int texHeight = gCinderOpenNISkeleton->mDepthMD.YRes();
	
	const XnDepthPixel* pDepth = gCinderOpenNISkeleton->mDepthMD.Data();
	const XnLabel* pLabels = gCinderOpenNISkeleton->mSceneMD.Data();
	
	// Calculate the accumulative histogram -  whatever that means
	memset(gCinderOpenNISkeleton->pDepthHist, 0, MAX_DEPTH*sizeof(float));
	
	unsigned int nX = 0;
	unsigned int nValue = 0;
	unsigned int nIndex = 0;
	unsigned int nY = 0;
	unsigned int nNumberOfPoints = 0;
	unsigned int nHistValue = 0;
	
	if(!gCinderOpenNISkeleton->bInitialized)
	{
	
		gCinderOpenNISkeleton->pDepthTexBuf = new unsigned char[texWidth*texHeight*3];
		
		app::console() << "Initialised Buffer" <<endl;
		
		gCinderOpenNISkeleton->bInitialized = true;
		
		gCinderOpenNISkeleton->mDepthSurface = Surface8u( texWidth, texHeight, false ); // width, height, alpha?

	}
	
	
	for (nY=0; nY<texHeight; nY++)
	{
		for (nX=0; nX<texWidth; nX++)
		{
			nValue = *pDepth;
			
			if (nValue != 0)
			{
				gCinderOpenNISkeleton->pDepthHist[nValue]++;
				nNumberOfPoints++;
			}
			
			pDepth++;
		}
	}
	
	for (nIndex=1; nIndex<MAX_DEPTH; nIndex++)
	{
		gCinderOpenNISkeleton->pDepthHist[nIndex] += gCinderOpenNISkeleton->pDepthHist[nIndex-1];
	}
	if (nNumberOfPoints)
	{
		for (nIndex=1; nIndex<MAX_DEPTH; nIndex++)
		{
			gCinderOpenNISkeleton->pDepthHist[nIndex] = 
			(unsigned int)(256 * (1.0f - (gCinderOpenNISkeleton->pDepthHist[nIndex] / nNumberOfPoints)));
		}
	}
	
	pDepth = gCinderOpenNISkeleton->mDepthMD.Data();

	Area area( 0, 0, texWidth, texHeight );

	Surface::Iter iter = gCinderOpenNISkeleton->mDepthSurface.getIter( area );
	while( iter.line() ) {
		while( iter.pixel() ) {
			iter.r() = 0;
			iter.g() = 0;
			iter.b() = 0;
			
			if ( *pLabels != 0) // Buh?
			{
				nValue = *pDepth;
				XnLabel label = *pLabels;
				XnUInt32 nColorID = label % nColors;
				if (label == 0)
				{
					nColorID = nColors;
				}
				
				if (nValue != 0)
				{
					nHistValue = gCinderOpenNISkeleton->pDepthHist[nValue];
					
					iter.r() = nHistValue * Colors[nColorID][0]; 
					iter.g() = nHistValue * Colors[nColorID][1];
					iter.b() = nHistValue * Colors[nColorID][2];
				}
				
				//app::console() << "PLABEL with Colour: " << label % nColors << endl;
			}
			else {
				nValue = *pDepth;
				//app::console() << "nValue: " << nValue << endl;
				if (nValue != 0)
				{
					nHistValue = gCinderOpenNISkeleton->pDepthHist[nValue];
					
					//app::console() << "nHistValue: " << nHistValue << endl;
					
					iter.r() = nHistValue; 
					iter.g() = nHistValue;
					iter.b() = nHistValue;
				}
			}
			
			pDepth++;
			pLabels++;
			
		}
	}

	gl::clear( Color( 0, 0, 0 ) );
	gl::draw(gl::Texture(gCinderOpenNISkeleton->mDepthSurface));
}