2 of 6
2
OS X Multitouch? 
Posted: 22 April 2008 12:10 PM   [ Ignore ]   [ # 16 ]
Sr. Member
RankRankRank
Total Posts:  58
Joined  2007-07-09

Hey bridgeyman,

I see you got an unimplemented openglview file up.  I think this is good.  I think the choice between an nsview and an openglview is good to have.  I was looking at the portvideo stuff and it looks like it is not cvBlobslib library. It looks like some examples in the project use cvBlobslib and some don’t. If you just want to look at the code for cvBlobslib is it found here- opencvlibrary.sourceforge.net/cvBlobsLib. Big problem with it is that it is all C++ but its very fast, anyway something to look at.  Keep up the good work.

EDIT- I was just looking at the C++ blobtracking source code you are working with.  I might be wrong but it doesn’t look that hard to rewrite it in objective C.

Ding

Profile
 
 
Posted: 06 May 2008 10:33 PM   [ Ignore ]   [ # 17 ]
New Member
Rank
Total Posts:  7
Joined  2007-10-07

congrats bridger on the ars technica newsbit—http://arstechnica.com/journals/apple.ars/2008/05/06/17-year-old-creates-impressive-mac-os-x-multi-touch-table

multi-touch is really capturing people’s attention!

Profile
 
 
Posted: 08 May 2008 12:45 PM   [ Ignore ]   [ # 18 ]
Sr. Member
RankRankRank
Total Posts:  58
Joined  2007-07-09

yeah dude congrats! I just saw an article about it on engadget. Keep it UP!

Ding

Profile
 
 
Posted: 09 May 2008 06:05 AM   [ Ignore ]   [ # 19 ]
New Member
Avatar
Rank
Total Posts:  3
Joined  2008-05-09

Hey there!  I’m pretty new to this stuff but i’m building an MT surface for use in my art/music installation.  Well done on the recognition you’re receiving already!  awesome stuff, this forum has been really helpful for me!

-christopher

 Signature 

--------------------------------------
Christopher Chong
MA in Sonic Arts @ SARC Belfast
http://majorc.wordpress.com
http://www.MajorC.co.uk
--------------------------------------

Profile
 
 
Posted: 12 May 2008 07:00 AM   [ Ignore ]   [ # 20 ]
New Member
Avatar
Rank
Total Posts:  26
Joined  2008-02-14

hi there,
i’m trying to configure and run some opentouch apps on my mac. i’ve got some stuff up and working but still i do not get the big picture. is there yome central place where i could find something similar to a documentation? anyway the app cvBlobDetection is up and running on my mac… what next?

 Signature 

_________________________________________________
our project blog: digitalvolvelles.wordpress.com

Profile
 
 
Posted: 12 May 2008 07:17 AM   [ Ignore ]   [ # 21 ]
New Member
Avatar
Rank
Total Posts:  26
Joined  2008-02-14

anyway, having lots of fun with comments in the source of opentouch’s ‘cvBlobDetection’ project, which seem to be written in catalán…

 Signature 

_________________________________________________
our project blog: digitalvolvelles.wordpress.com

Profile
 
 
Posted: 13 May 2008 10:24 AM   [ Ignore ]   [ # 22 ]
Sr. Member
RankRankRank
Total Posts:  58
Joined  2007-07-09

Hey lagerkoller,

I would say that the opentouch stuff is still in early infancy.  bridgeyman posted some stuff but it is just a very small beginning. I am assuming that he is busy and hasn’t posted his finished code yet.  As far as the other stuff in there the most complete seems to be the portVideoBlobDetection project.  I think bridgeyman used this code and gave it a cocoa facelift but I could be wrong. In his beginning code he seems to be using CIImage filters to filter the image instead of opencv filters like touchlib does. It would be nice if he found a way to incorporate the lens correction stuff. The portVideoBlobDetection project doesn’t use cvBlobslib although you can easily integrate it.  It uses a modified version of the v3ga code that uses a metaballs type edge detection algorithm.  I tested both and found cvBlobslib a little bit faster but not by much at all. Anyway I think the comments in blobslib are catalan or portuguese I am not sure but the author of cvBlobslib is very helpful in the opencv forums or by email.  Seems like a nice guy.  Good luck and share any progress.

Ding

Profile
 
 
Posted: 13 May 2008 10:29 AM   [ Ignore ]   [ # 23 ]
Sr. Member
RankRankRank
Total Posts:  58
Joined  2007-07-09

I forgot to mention that if you look at the console the portVideoBlobDetection project spits out touch events.  I believe it uses OSC to send out data so you can build an app that listens to the correct port or just integrate the code into your own app.

Profile
 
 
Posted: 13 May 2008 10:39 AM   [ Ignore ]   [ # 24 ]
New Member
Avatar
Rank
Total Posts:  26
Joined  2008-02-14

thanks, ding!
i’ve got the cv example app up and running and it really seems to be quite fast. additionally after hours of tweaking bridgeyman’s code i was able to get it up and running as well. the core image filters are quite nice and yield very good results. on the other hand they seem to integrate quite badly with other libs like opencv. the problem there is to pass the raw image data from coreimage/quartz to another lib. anyway, the opencv blob code does not look like it handles blob tracking with the gpu what is a bit sad… an glsl shader for this task would be very nice. maybe after the gsoc wink

 Signature 

_________________________________________________
our project blog: digitalvolvelles.wordpress.com

Profile
 
 
Posted: 13 May 2008 07:25 PM   [ Ignore ]   [ # 25 ]
Sr. Member
RankRankRank
Total Posts:  58
Joined  2007-07-09

Have you found any blob tracking algorithm that uses the gpu? Also how did you pass the ciimage to the metablobs detection algorithm?  I have been converting the pixelbuffer from the camera to an iplimage so as to use opencv. But I would be interested as to how you passed the core image data to this function:
BlobDetection(int imgWidth, int imgHeight, int bytesPerPixel);
I would love to convert either blob tracker into native objective-c. I have been trying to convert the cvBlobslib but its a massive job and I’m not so sure as how to handle Map and Vector functions. I know you have to use NSArray but I’m still figuring it out. I think the metablobs one might be easier but it uses Map.

Ding

Profile
 
 
Posted: 14 May 2008 02:43 AM   [ Ignore ]   [ # 26 ]
New Member
Avatar
Rank
Total Posts:  26
Joined  2008-02-14

>> 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…

 Signature 

_________________________________________________
our project blog: digitalvolvelles.wordpress.com

Profile
 
 
Posted: 14 May 2008 08:24 AM   [ Ignore ]   [ # 27 ]
Sr. Member
RankRankRank
Total Posts:  58
Joined  2007-07-09

Well Im having a hell of a time trying to get the blob detection algorithm introduced properly into my nsopenglview.  Maybe we could help each other and figure this thing out.  I know this is as backwards but you can try converting the ciimage to an iplimage like this:

- (IplImage*) iplImageFromCIImage:(CIImage*) image
{
    CvSize size 
cvSize((int) image.extent.size.width, (int) image.extent.size.height);
    
    
IplImageresult      cvCreateImage(sizeIPL_DEPTH_8U4);
    
IplImagefinalResult cvCreateImage(sizeIPL_DEPTH_8U3);
    
    
CGColorSpaceRef colorSpace CGColorSpaceCreateWithName(kCGColorSpaceGenericRGB);
    
CGContextRef context CGBitmapContextCreate (NULL,
                                     
size.width,
                                     
size.height,
                                     
8,      // bits per component
                                     
result->widthStep,
                                     
colorSpace,
                                     
kCGImageAlphaPremultipliedLast);
    if (
context == NULL{
        NSLog
(@"Context not created!");
        return 
NULL;
    
}

    CIContext
ciContext [CIContext contextWithCGContext:context options:[NSDictionary dictionaryWithObject: (NSString*) kCGColorSpaceGenericRGB forKey:  kCIContextOutputColorSpace]];
    
    
CGRect rect CGRectMake(0,0size.widthsize.height);

    
// Expensive...
    
[ciContext drawImage:image inRect:rect fromRectrect];
    
    
// Expensive...
    
[ciContext render:image 
             toBitmap
:result->imageData
             rowBytes
:result->widthStep
               bounds
:rect 
               format
:kCIFormatARGB8 
           colorSpace
:NULL];

    
// Reorder ARGB to RGBA
    
int i;
    for (
0result->imageSize+= 4{
        result
->imageData[i]   result->imageData[i+1];
        
result->imageData[i+1] result->imageData[i+2];
        
result->imageData[i+2] result->imageData[i+3];
    
}
    
    
// Change to the standard OpenCV color ordering.
    
cvCvtColor(resultfinalResultCV_RGBA2BGR);
    
    
// Cleanup
    
CGColorSpaceReleasecolorSpace );
    
CGContextReleasecontext );
    
cvReleaseImage(&result);
    
    return 
finalResult;
}

and you can just do this:

IplImage data [self plImageFromCIImage:endOfChainImage];
theBlobDetection.computeBlobs(data);

But this is a bit expensive and a little backwards.  I believe the blob detection algorithm is expecting an iplimage and if you want to stick in a bitmap data you have to modify it a bit.  I have been trying to figure that bit out. I decided to use this delegate instead:

- (void)captureOutput:(QTCaptureOutput *)captureOutput didOutputVideoFrame:(CVImageBufferRef)videoFrame
      withSampleBuffer
:(QTSampleBuffer *)sampleBuffer fromConnection:(QTCaptureConnection *)connection;

and just convert the bufferref to an iplimage which is a lot less expensive and just skip the ciimage filters and use the opencv ones. But when I try to get an nsarray from the blob tracker (cvBlobslib) I get a major video refresh lag to the point where my app just crawls. It makes no sense to me because when I time it, it clocks in very decent at around 0.0200 of a second or so.  Im a bit confused and stuck on this for the moment till I can find an answer.

Ding

Profile
 
 
Posted: 14 May 2008 08:43 AM   [ Ignore ]   [ # 28 ]
Sr. Member
RankRankRank
Total Posts:  58
Joined  2007-07-09

Oh one thing of note.  The QTKit capture delegates are not thread safe.  Quote from Apple:

Warning: Delegates should not assume that this method will be called on the main thread. In addition, this method is called periodically, so it must be efficient to prevent capture performance problems.

This means using @synchronized and I think this has to do with my lag problems. I don’t think I have quite mastered how to properly use this.

Ding

Profile
 
 
Posted: 14 May 2008 11:39 AM   [ Ignore ]   [ # 29 ]
Sr. Member
RankRankRank
Total Posts:  58
Joined  2007-07-09

I found this:

NSBitmapImageRepbitmap [[[NSBitmapImageRep alloc]  initWithCIImageendOfChainImage] autorelease];

 
// Getting pixels data
// this returns a pointer to the pixel data
 
int *data [bitmap bitmapData];

Let me know if it works

Ding

Profile
 
 
Posted: 15 May 2008 09:41 AM   [ Ignore ]   [ # 30 ]
Sr. Member
RankRankRank
Total Posts:  58
Joined  2007-07-09

I need some advice,

Im writing the drawing part of my app and Im trying to figure out wether to stick with opengl or to change direction and draw with the cocoa stuff.  I am trying to figure out which is faster plus I will need to use text and upload images and series of images in a loop to different parts of the view. Does anyone have any advise.

Ding

Profile
 
 
   
2 of 6
2