|
Notes on Using OpenCV and Reactivision in Ptolemy IIInstalling OpenCVSeehttp://ubaa.net/shared/processing/opencv/
for details.
Installing OpenCV under Mac OS X
Note that under Eclipse, you may need to add OpenCV.jar to your classpath. OpenCV and PtolemySee http://chess.eecs.berkeley.edu/ptexternal for information about getting started with Ptolemy.A version of the actor below has been installed as
There is a demo at
See $PTII/ptolemy/actor/lib/opencv/package.html for detailed instructions about how to set up. If you install and you add the jar file to your build path in Eclipse, then the following actor, put (inappropriately) in $PTII will run in this model. import hypermedia.video.OpenCV; import java.awt.Frame; import java.awt.Image; import java.awt.image.MemoryImageSource; import ptolemy.actor.TypedAtomicActor; import ptolemy.actor.TypedIOPort; import ptolemy.data.AWTImageToken; import ptolemy.data.type.BaseType; import ptolemy.kernel.CompositeEntity; import ptolemy.kernel.util.IllegalActionException; import ptolemy.kernel.util.NameDuplicationException; public class OpenCVHelloWorld extends TypedAtomicActor { public OpenCVHelloWorld(CompositeEntity container, String name) throws IllegalActionException, NameDuplicationException { super(container, name); output = new TypedIOPort(this, "output", false, true); output.setTypeEquals(BaseType.OBJECT); _dummyFrame = new Frame(); } public TypedIOPort output; public void fire() throws IllegalActionException { _openCV.read(); // create a new image from cv pixels data MemoryImageSource mis = new MemoryImageSource( _openCV.width, _openCV.height, _openCV.pixels(), 0, _openCV.width ); Image image = _dummyFrame.createImage( mis ); output.send(0, new AWTImageToken(image)); } public void initialize() throws IllegalActionException { super.initialize(); _openCV = new OpenCV(); _openCV.capture( 640, 480 ); _openCV.cascade( OpenCV.CASCADE_FRONTALFACE_ALT ); } private OpenCV _openCV; private Frame _dummyFrame; } Dai's Interface to OpenCVDai's OpenCV interface to the C API is illustrated in $PTII/ptolemy/codegen/demo/OpenCV. However, using the Java API may be far more convenient in the long run. |