using TOPs with python

hello
this might be a stupid question that fundamentally misunderstands how touch and python can interact - i use a lot python scripting for stuff rather than patching but had a question around using a library like openCV and whether we can use a TOP as the camera or input to some image detection so that i can do cropping thresholding etc and pass the resulting TOP into a script DAT…

is that a thing?

thanks

b

You can sample a pixel with:

[code]op( ‘path_to_your_top’ ).sample( x=pixel_position, y=pixel_position )

or

op( ‘path_to_your_top’ ).sample( u=normalized_position, v=normalized_position )[/code]

While you can do that, I don’t know that I’d recommend doing that - python is pretty slow in the context of touch, so your performance will suffer the larger your sampling texture is. You could instead use a GLSL TOP - and write a shader instead, though if you’re using a specific library that might be a little cumbersome.

You could use a C++ TOP:
derivative.ca/wiki088/index. … usPlus_DLL

I don’t know if this would work or not, but you might be able to write your dll as a pyd - I don’t know enough here to offer any guidance, but that seems possible from a theoretical perspective.

great - thanks
felt like it would be nice to able to put a bit of python downstream to do some CV stuff in a quick sketchy way like dropping OPs - but i take the point on performance -
ended up ‘outsourcing’ the CV stuff to VVVV and got it chatting back and forth with Touch via OSC

cheers

b

I just wanted to ask the same thing as the OP.
Is it really true that we can’t use the python+open CV thing with TOPs in a realtime efficient way?

Currently in 099 it’s possible to read image files in opencv with python, see example on 099 OpenCV wiki page
There is no option yet to read/write TOP->OpenCv or OpenCV->TOP, but I can imagine it’s something Derivative has on its nice-to-have wishlist.

very late to this party.
Anyone has updates regarding TOP > python > TOP ?

thx

Answering my own question, should it be helpful for anyone:
check out Script TOP, it retrieves a TOP as a numpy array.
(my new favorite TOP <3)