Login | Register 
FEATURES
APPLICATIONS
DOWNLOADS
EDUCATION
BLOG
WIKI
FORUM
STORE

KMeans Clustering for Dominant Color

Share your components here. First one to 100 wins!

KMeans Clustering for Dominant Color

Postby raganmd » Tue May 15, 2018 7:08 pm

Worked on a KMeans Clustering approach to find dominant color in an image. The module here uses a few external libraries that need some TLC to work correctly - so make sure your Python house is in order. Bonus feature, it runs the analysis process in another thread so the image analysis doesn't block touch

https://github.com/raganmd/touchdesigner-dominant-color
raganmd
 
Posts: 1353
Joined: Thu Mar 28, 2013 5:21 am
Location: San Francisco, CA

Re: KMeans Clustering for Dominant Color

Postby Simplo » Fri May 18, 2018 3:32 am

A little hard to setup, for me, but very useful! Thank you!
Simplo
 
Posts: 65
Joined: Thu Feb 05, 2015 5:39 am

Re: KMeans Clustering for Dominant Color

Postby jmt4zj » Wed Jul 11, 2018 12:26 am

Nice, thank you for posting this, Matthew! A side goal of mine is to port this logic to a gpu based library so that we can start to do this real time 8-)
Jonathan Thompson
@pointshader
http://particularexperienc.es
User avatar
jmt4zj
 
Posts: 108
Joined: Mon Nov 01, 2010 3:15 am
Location: NYC

Re: KMeans Clustering for Dominant Color

Postby oliviercoucke » Sat Nov 24, 2018 7:43 pm

i have trouble making the thing work, are you guys still able to use it with last versions of python, td and dependencies ? sklearn is installed properly as said by the test results after install, still td returns me with strange issue about it being badly installed
oliviercoucke
 
Posts: 8
Joined: Mon Feb 23, 2015 12:00 pm

Re: KMeans Clustering for Dominant Color

Postby lucasm » Sun Nov 25, 2018 11:27 am

what sort of issues do you see returned?

I generally test in three tiers:

In TD it's important to do a sys.path.insert(0,path/to/my/site-packages) then import your modules (NOTE: this has to be done before any other import statements are executed in your TOE file, so you need to manage this carefully if you have lots of executeDAT's firing code that uses libraries at start.)

I think when you add your external python path to the preferences field, it actually appends it to the sys.path, if you print the paths you'll see it at the end in my experience.

This usually makes the most sense because you want to default to what comes with TD and fall back to other libraries as you need them.. but I've personally had tons of issues with more advanced libraries that need some special version of numpy (+MKL) for example.
User avatar
lucasm
 
Posts: 226
Joined: Sat Apr 28, 2012 7:55 pm
Location: Dallas, TX

Re: KMeans Clustering for Dominant Color

Postby oliviercoucke » Sun Nov 25, 2018 11:51 am

seems like my sys path is correct, as it includes sklearn and my site package folder, i used the text DAT method provided by raganmd and printed sys.path to check, its correct !

and the errors returned are those :

python >>>
Traceback (most recent call last):
File "</base1/base_dominant_color/domColorEXT:op('/base1/base_dominant_color/domColorEXT').run()>", line 1
td.Error: File "C:/Program Files/Python37/Lib/site-packages\sklearn\__check_build\__init__.py", line 44
from ._check_build import check_build # noqa
r = previousimport(*args, **kw)
ImportError: No module named 'sklearn.__check_build._check_build'

During handling of the above exception, another exception occurred:

File "/base1/base_dominant_color/domColorEXT", line 12
r = previousimport(*args, **kw)
r = previousimport(*args, **kw)
File "C:/Program Files/Python37/Lib/site-packages\sklearn\__init__.py", line 63
from . import __check_build
r = previousimport(*args, **kw)
r = previousimport(*args, **kw)
File "C:/Program Files/Python37/Lib/site-packages\sklearn\__check_build\__init__.py", line 46
raise_build_error(e)
File "C:/Program Files/Python37/Lib/site-packages\sklearn\__check_build\__init__.py", line 41, in raise_build_error
%s""" % (e, local_dir, ''.join(dir_content).strip(), msg))
ImportError: No module named 'sklearn.__check_build._check_build'
___________________________________________________________________________
Contents of C:/Program Files/Python37/Lib/site-packages\sklearn\__check_build:
setup.py _check_build.cp37-win_amd64.pyd__init__.py
__pycache__
___________________________________________________________________________
It seems that scikit-learn has not been built correctly.

If you have installed scikit-learn from source, please do not forget
to build the package before using it: run `python setup.py install` or
`make` in the source directory.

If you have used an installer, please check that it is suited for your
Python version, your operating system and your platform.
Results of run operation resulted in exception. <type:textDAT path:/base1/base_dominant_color/domColorEXT> <class 'td.textDAT'>
python >>>
Error retrieving extension for /base1/base_dominant_color: (Extension 1) AttributeError: module '/base1/base_dominant_color/domColorEXT' has no attribute 'DomColor'
python >>>

it seems like my build of scikit-learn isnt correct, despite i've checket it correctly with the built in test that commes with the librairy

i surely am missing something easy ... anyway thanks for the help !
oliviercoucke
 
Posts: 8
Joined: Mon Feb 23, 2015 12:00 pm

Re: KMeans Clustering for Dominant Color

Postby raganmd » Mon Nov 26, 2018 1:56 am

hey olivercouche - this is a some grumbly python silliness.

I'd guess that it's a numpy version issue. You can check this by using

Code: Select all
import numpy
print(numpy.__version__)


Ideally you should see version 1.15.4.

If you don't see this, than it's likely that the distributed version of numpy with Touch is different.

To work around this, check the repo for the latest update. There there is now a new folder called dep. Inside you'll see a script to do some python clean-up and organizing. You should right click and run as admin - it will pull the required libraries into a new folder called python in the dep directory.

In the TOE file there's now an addition to the start-up script that will add your newly created local dep directory to the sys.path. This will add the new directory to the top of your list. Quit and restart touch, and see if you still get the error. Fingers crossed that all of that hoopla will get you up and running.
raganmd
 
Posts: 1353
Joined: Thu Mar 28, 2013 5:21 am
Location: San Francisco, CA

Re: KMeans Clustering for Dominant Color

Postby oliviercoucke » Mon Nov 26, 2018 10:49 am

hey !
thanks a lot for your response !
my version is 1.15.4

gonna try the rest !
oliviercoucke
 
Posts: 8
Joined: Mon Feb 23, 2015 12:00 pm

Re: KMeans Clustering for Dominant Color

Postby oliviercoucke » Mon Nov 26, 2018 2:27 pm

it seems that for some reason touchdesigner is not able to import cv2, numpy and sklearn and i cannot figure out why, every folder is appended in the sys path correctly
oliviercoucke
 
Posts: 8
Joined: Mon Feb 23, 2015 12:00 pm

Re: KMeans Clustering for Dominant Color

Postby raganmd » Mon Nov 26, 2018 2:39 pm

Hey there sir - so you shouldn't need to add each folder individually, though that shouldn't break anything. If you print out the contents of sys.path, what folders to you see, in what order?
raganmd
 
Posts: 1353
Joined: Thu Mar 28, 2013 5:21 am
Location: San Francisco, CA

Next

Return to Shared .tox Components

Who is online

Users browsing this forum: No registered users and 2 guests