I was playing with OpenCV and sometimes I use a method that returns a PVector like: opencv.getAverageFlow()
, but it is a <type 'processing.core.PVector'>
and not <class '__main__.PVector'>
as one created by the sketch.

I bothers me a bit because I don’t seem to be able to use the nice Python infix operators I love with them, v1 += v2 instead of v1.add(v2) etc.
Is there anything I can do about this (short of converting them with v = PVector(v.x, v.y, v.z)
)?
2 Likes
You may try out this workaround: PVector().set(opencv.getAverageFlow())

Alternatively this shorter version might work too: PVector().set(opencv.averageFlow)

3 Likes
The first syntax works perfectly, thank you!
The second one complains, similar, I think, as I when I tried main_pv = PVector(core_pv)
. Cheers!
I’m not too familiar with jython but I assume it should be possible to do something like I have with JRuby to create a python class in java as I have with my ruby-processing implementations. I created Vec2D and Vec3D classes to make more ruby friendly classes, to make great benefit all round when programming in ruby. I added missing features such as being able to duck-type, convert Vectors to vertex etc. See java code for Vec3D class.
2 Likes
Very nice!
The PVector implemented by JDF in Python mode is very pythonic already, this is the first time I notice there still is such thing as a “Java PVector” (being returned by the imported lib) that needed converting 