>> Have you found any blob tracking algorithm that uses the gpu?
no, not yet. and the more i think of that the more difficult it seems to be… it’s not so much a problem to get the camera’s image (as a texture) into a shader and search with the pixel shader for blobs (anyway, i would’t know how to do that instantly). the problem would be to retrieve the results. you could show the results as white dots on a black canvas but you can’t just return numbers or array values from a shader. however, there’s a library which does exactly this. it’s called gpgpu (General-Purpose Computation Using Graphics Hardware). for processing with the gpu you put an array with values into a texture (pixel colours are values), send it to a gpu shader, your shader kernel does something with the array and afterwards you get a result as a texture that works as an array as well. gpgpu puts the values for you into that texture and retrieves them as well. you ‘just’ have to write the kernel. kind of complicated but very useful: http://www.gpgpu.org/developer/#code-tutorial
>>Also how did you pass the ciimage to the metablobs detection algorithm?
i haven’t come that far, yet. i’ve been struggling with exactly that problem and i tried to solve this with following code:
________________________________________________________________________________________________________
//grab image from last filter
CIImage *endOfChainImage = [colorCorrectionFilter valueForKey:@"outputImage"];
//put CIImage into Quartz 2D CGImageRef
CGImageRef imageRef = [self cgImageCreateFromCIImage:endOfChainImage fromRect:[endOfChainImage extent]];
//find out image extents
CGRect rect = {(0,0), ( CGImageGetWidth(imageRef), CGImageGetHeight(imageRef))};
//create context from which to retrieve the image contents (createARGBBitmapContext:imageRef is another method which i do not include)
CGContextRef cgctx = [self createARGBBitmapContext:imageRef];
//write image to context
CGContextDrawImage(cgctx, rect, imageRef);
//retrieve raw data from context
int *data = (int*) CGBitmapContextGetData (cgctx);
if (data != NULL)
{
//do sth. with the raw data
blobDetection::BlobDetection theBlobDetection(CGImageGetWidth(imageRef), CGImageGetHeight(imageRef),24);
theBlobDetection.setPosDiscrimination(false);
theBlobDetection.setThreshold(0.38f);
theBlobDetection.setBlobDimensionMin(5, 5);
blobDetection::Blob b;
b.setParent(&theBlobDetection);
blobDetection::EdgeVertex eA,eB;
theBlobDetection.computeBlobs(data);
NSLog(@"Blobs Count: %d\n”,theBlobDetection.getBlobNb());
}
// When finished, release the context
CGContextRelease(cgctx);
// Free image data memory for the context
if (data)
{
free(data);
}
_________________________________________________________________________________________________________
but it doesn’t detect any blobs so far. i do not know exactly what kind of image is in data. just an rgb image with 8bit per colour? i don’t know…
additionally it would be nice to scale down the image that is grabbed from the cam. it has a resolution of 1280x800 px or so…