[Pyobjc-dev] How to get (void*) data into a Python array
Brought to you by:
ronaldoussoren
From: Trevor B. <mr...@gm...> - 2011-02-04 17:16:23
|
Hello, I am working on a small Python script to grab a single frame from the iSight camera using PyObjC. I want to import the frame into a python numpy array for manipulation, and I want to write it exclusively in Python. I have fairly limited experience in Python and Objective-C, and no prior experience with PyObjC. I have made some progress, and currently it is able to find the camera, open it, and capture a frame. The frame data is (theoretically) available in my QTCaptureDecompressedVideoOutput delegate's callback function: - (void)captureOutput:(QTCaptureOutput *)captureOutput didOutputVideoFrame:(CVImageBufferRef)videoFrame withSampleBuffer:(QTSampleBuffer *)sampleBuffer fromConnection:(QTCaptureConnection *)connection So I added "pdb.set_trace()" at the beginning of the callback, and am trying to figure out how to get the raw bytes available in Python. The closest I have come is examining sampleBuffer: -------------------------------------------------- (Pdb) sampleBuffer <QTSampleBuffer: 0x1044b42d0> (Pdb) sampleBuffer.numberOfSamples() 1 (Pdb) sampleBuffer.lengthForAllSamples() 2624000 (Pdb) sampleBuffer.bytesForAllSamples() 4674363392L -------------------------------------------------- However, this is where I'm confused. bytesForAllSamples() returns a (void*), which is literally, of course, a long integer. I have no idea how to get at those bytes, since I'm assuming I can't just dereference an ObjC pointer somehow in Python. I was hoping an NSData object initialized with the address would work, but it does not: -------------------------------------------------- (Pdb) NSData.dataWithBytes_length_(sampleBuffer.bytesForAllSamples(),2624000) *** TypeError: converting to a C array -------------------------------------------------- Any guidance in getting past this point would be much appreciated! And thanks to everyone responsible for PyObjC, it is an excellent resource. -Trevor |