I have a TOX using cv2 and it works fine in the current release 2020.28110, but in the experimental builds it is not evaluating the parent().par values to set parameters. For example using cv2.kmeans it gives an error that argument ‘K’ needs to be an integer. The parameter it is reading is an integer, and the same evaluation in a noise TOP reads just fine. If I hard code the ‘K’ parameter then it goes to the next one - Attempts, and isn’t reading that either. Is this a known regression?
Not a known one I think. Can you post a .toe file so we can take a look?
Sure Malcolm, here you go. Just changing the switch should trigger the error in the pixelRamp container. TestRampOld.toe
Were you able to repro Malcolm, or is there something odd about my setup?
what seems to be happening is that the parameter assigned to the variable
pixels is passed to the
cv2.kmeans function as a TD Parameter object and not automatically casted to an integer.
A quick workaround would be to force the pixel variable to already only have the value of the parameter instead of the whole parameter object:
pixels = parent().par.Kmeanscenters.eval()
Hope this helps
Thanks Markus - just odd that it works in other Ops and 28110. I’m still seeing an issue with the ‘flags’ parameter for kmeans, which is actually an enumeration of 0 or 2 (in my code represented as parent().par.Centers) but this doesn’t seem to like the same workaround (which did work for parent().par.Attempts as well as the pixels).
flags : This flag is used to specify how initial centers are taken. Normally two flags are used for this : cv2.KMEANS_PP_CENTERS and cv2.KMEANS_RANDOM_CENTERS .
I’ll carry on digging around - but I’d be interested in what changed here - in case it hits others reading and using parameters in the script TOP.
we are looking a bit further at this. I’ll keep you updated.
Thanks Markus - and I got the flags working. I was using a menu for PP and Random and passing 0 and 2 - but they came across as floats. so int(parent().par.Centers.eval()) did the trick. Unblocked but would love to know what you find.
the change is due to the switch to opencv 4.5 in the 40k release of TouchDesigner. I tried by installing opencv as an external package for my 2020.20k build and it resulted in the same error in contrast to using the previous opencv 4.0 version. So the change must be somewhere in how the
cv2.kmeans function is casting values in the latest opencv release.
Hope this helps
Thanks Markus - good catch, and that helps a lot and is good to know.