Пример #1
0
void dfDisplacementMap::applyDisplaceMap(ofxCvColorImage& sourceImage,ofTexture& destTexture,float hscale=0.3, float vscale=0.3){
    //apply displacement
    unsigned char * displacePixels  = this->getPixels();
    unsigned char * pixels          = sourceImage.getPixels();
    int displace,hdisplace,vdisplace;
    int totalPixels=height*width*3;
    unsigned char * videoDisplaced     = new unsigned char[totalPixels];
    for (int i = 0; i < totalPixels;i+=3){
        hdisplace = (int)((displacePixels[i] - 127)*hscale); //x coord
        vdisplace = (int)((displacePixels[i+2] - 127) *vscale); //y coord
        if( i%(320*3)+hdisplace*3 >0 && i%(320*3)+hdisplace*3<320*3){
            displace=hdisplace+vdisplace*320;
        }else{
            displace = 0;
        }
        displace*= 3;
        if(i+displace>0 && i+displace<totalPixels){
            videoDisplaced[i]   = pixels[i+displace];
            videoDisplaced[i+1] = pixels[i+displace+1];
            videoDisplaced[i+2] = pixels[i+displace+2];
        }
    }
    destTexture.loadData(videoDisplaced,width,height, GL_RGB);
    delete videoDisplaced;
}
Пример #2
0
void chromaKeyer::keyImage( ofxCvColorImage & src, ofxCvColorImage & dst, int w, int h )
{

    // resize images if not at same size already
    if( hsvImage.width != w || hsvImage.height != h)
    {
            hsvImage.allocate(w,h);
            hueImg.allocate(w,h);
            satImg.allocate(w,h);
            valImg.allocate(w,h);
    }

    // convert src to hsv color space
    hsvImage.setFromPixels(src.getPixels(),w,h);
    hsvImage.convertRgbToHsv();

    // extract the hsv channels to a grayscale image
    hsvImage.convertToGrayscalePlanarImages(hueImg,satImg,valImg);

    unsigned char * pixelsHue = hsvImage.getPixels();
    //unsigned char * pixelsSat = satImg.getPixels();
    unsigned char * dstMask = new unsigned char[w*h];


    // loop through and compare
    /*
    if( pixelsHue[i] >= H-tH && pixelsHue[i] <= H+tH&&
            pixelsSat[i] >= S-tS && pixelsSat[i] <= S+tS
        ){
    */
    for( int i = 0; i < w*h; i++)
    {
        if( pixelsHue[i*3] >= H-tH && pixelsHue[i*3] <= H+tH&&
            pixelsHue[i*3+1] >= S-tS && pixelsHue[i*3+1] <= S+tS
        ){
            dstMask[i] = 0;


        }else{
            dstMask[i] = 255;

        }
    }

    hueImg.setFromPixels(dstMask,w,h);

    cvCopy( hsvImage.getCvImage(),dst.getCvImage(),hueImg.getCvImage());//,hueImg.getCvImage());
    dst.flagImageChanged();
    dst.convertHsvToRgb();

    delete dstMask;
}
Пример #3
0
//---------------------------------------------------------------------------------
void videoBlob::set(ofxCvBlob myBlob, ofxCvColorImage myImage, ofxCvGrayscaleImage myMask){

	memcpy(&blob, &myBlob, sizeof(ofxCvBlob));

	// now, let's get the data in,
	int w = blob.boundingRect.width;
	int h = blob.boundingRect.height;
	int imgw = myImage.width;
	int imgh = myImage.height;
	int imgx = blob.boundingRect.x;
	int imgy = blob.boundingRect.y;

	unsigned char * blobRGBA = new unsigned char [ w * h * 4 ];
	unsigned char * colorPixels 	= myImage.getPixels();
	unsigned char * grayPixels 		= myMask.getPixels();

	for (int i = 0; i < w; i++){
		for (int j = 0; j < h; j++){
			int posTex = (j * w + i)*4;
			int posGray = ((j+imgy)*imgw + (i + imgx));
			int posCol = posGray * 3;
			blobRGBA[posTex + 0] = colorPixels[posCol + 0];
			blobRGBA[posTex + 1] = colorPixels[posCol + 1];
			blobRGBA[posTex + 2] = colorPixels[posCol + 2];
			blobRGBA[posTex + 3] = grayPixels[posGray];
		}
	}

//	myTexture.clear();
//	myTexture.allocate(w,h,GL_RGBA);

	unsigned char * black = new unsigned char [ofNextPow2(w) * ofNextPow2(h) * 4];
	memset(black, 0, ofNextPow2(w) * ofNextPow2(h) * 4);
//	myTexture.loadData(black, ofNextPow2(w), ofNextPow2(h), GL_RGBA);
//	myTexture.loadData(blobRGBA, w, h, GL_RGBA);

	delete black;
	delete blobRGBA;

	pos.x = blob.centroid.x;
	pos.y = blob.centroid.y;
	scale = 1;
	angle = 0;

}
Пример #4
0
void chromaKeyer::getColorFromScreen( int x, int y, int w, ofxCvColorImage & src)
{
    // tried many different things here but it doesnt work... need to fix it
    cout << " x " << x << " y " << y << endl;
    if( x > src.width-1 || y > src.height-1 || x < 1 || y < 1 ) return;

    //ofxCvColorImage temp;
    //temp.allocate(src.width,src.height);
    //temp = src;


    unsigned char * pixels = src.getPixels();


    int pix = x * w + y;
    int r = pixels[ pix ];
    int g = pixels[ pix + 1];
    int b = pixels[ pix + 2];

    setFromRGB( r,  g,  b);
}
void ofxOpticalFlowLK :: update	( ofxCvColorImage& source )
{
	update( source.getPixels(), source.width, source.height, OF_IMAGE_COLOR );
}