ofxSyphon to image

Hi guys.
I’m searching a way to get from syphon to an image for using the feed into openCv.
Actually I’m drawing into an fbo (in the update function, to not have one more frame delay, if I’m right) then use the readToPixels from that fbo and feeding my cv image with this.
Is their any better way to do that?
I also add a getTextureReference() that I think quite usefull in my ofxSyphon, Is their any reason for which this would not be already in ?

No reason that a reference to the internal texture wasn’t included in ofxSyphon. No one has had a use for it so far. It seems most people use the OF implementation to push frames to other programs, not necessarily the other way around. Feel free to make any changes and if people find them useful, we’ll add them to the core.

For example in SyphonClient add:

  
ofTexture& getTexture(){  
     return mTex;  
}  

As far as getting the pixels from Syphon for OpenCV goes, once you have the actual texture you can just readToPixels from that. Untested, but positive it should work. No need to draw to a FBO if you implement getTextureReference() for the Syphon Client.

The issue is that Syphon keeps all of the pixel data on the GPU, you must do a readToPixels to move the data CPU side.

Oh! Didn’t notice there was a readToPixels in textures. ^^ Cool. :slight_smile:
Actually I had already implemented the getTextureReference() and getTextureData() methods into my ofxSyphon plugin since a while. I was just wondering if there was a reason why it’s not already in syphon plugin.
About the use as Syphon, I’m running video into VDMX and using syphon to feed from VDMX to openFrameworks to build more complex fx, then feed back into VDMX. Maybe one time the fx will be finished, I’ll try to compile it as a quartz Composer plugin. Should it be more efficient?

hum. Actually this doesn’t work.

  
  
syphonFeed.getTextureReference().readToPixels(feedPxl);   
feedImg.setFromPixels(feedPxl);  
  

but this work

  
  
fbo.begin();  
syphonFeed.draw(0, 0, w, h);  
fbo.end();  
      
fbo.readToPixels(feedPxl);      
feedImg.setFromPixels(feedPxl);  
  

here is my (simple) implementation of getTextureReference

  
  
ofTexture & ofxSyphonClient::getTextureReference(){  
    return mTex;  
}  
  

That’s not a really big deal, but was just wondering why that’s not working.

1 Like

It does not work, because the ofTexture reference returned is actually Syphons internal “IOSurface” backed texture, which has special texture “backing” (memory location) used by the Kernel to masquerade the reference of where the texture lives on the GPU and CPU. Its not a “normal” OpenGL Texture, but it pretends to be one is all but a few odd edge cases (mostly read back related, etc).

Essentially, you would have to call IOSurfaceLock() around the IOsurface reference Syphon uses internally. We don’t expose that for a few reasons, one being ping-ponging from App A-> GPU -> (Syphon) App B -> GPU -> CPU sort of defeats the purpose of Syphon (keeping things on the GPU). That said, I can see how it could be useful if done well.

We might add at a later date a “get image on the CPU” function, but those methods stall rendering of both Applications due to the locking required. Its best avoided though just for performance sake. If you really want this, file a feature request.