Created
October 30, 2012 10:58
-
-
Save fjenett/3979612 to your computer and use it in GitHub Desktop.
Simple JavaCV example in Processing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* JavaCV in Processing 2.0b5 on MacBook with 64bit | |
* | |
* OpenCV from MacPorts: | |
* - /opt/local/macports/macports.conf needs to have "build_arch" to be set to x86_64 | |
* - now just do: sudo port install opencv | |
* | |
* Sketch has the .jar files from this download inside "code" folder (just drag-drop them on sketch window): | |
* - http://code.google.com/p/javacv/downloads/detail?name=javacv-0.2-bin.zip | |
*/ | |
import static com.googlecode.javacv.cpp.opencv_core.*; | |
import static com.googlecode.javacv.cpp.opencv_imgproc.*; | |
import static com.googlecode.javacv.cpp.opencv_highgui.*; | |
void setup () | |
{ | |
size( 500, 500 ); | |
String filename = sketchPath("data/moonwalk.jpg"); // use the one from Processing examples .. | |
IplImage iplImg = cvLoadImage(filename); | |
if ( iplImg != null ) | |
{ | |
cvSmooth( iplImg, iplImg, CV_GAUSSIAN, 3 ); | |
PImage img = iplImageToPImage(iplImg); | |
image( img, 0, 0 ); | |
cvReleaseImage(iplImg); | |
} | |
} | |
/* convert IplImage to PImage */ | |
PImage iplImageToPImage ( IplImage iplImg ) | |
{ | |
java.awt.image.BufferedImage bImg = iplImg.getBufferedImage(); | |
PImage img = new PImage( bImg.getWidth(), bImg.getHeight(), ARGB ); | |
bImg.getRGB( 0, 0, img.width, img.height, img.pixels, 0, img.width ); | |
img.updatePixels(); | |
return img; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment