javacv

所属分类:图形图像处理
开发工具:Java
文件大小:927KB
下载次数:62
上传日期:2012-03-22 18:37:16
上 传 者lijall
说明:  Java CV图像处理包,应用java语言实现多种图像处理算法,需要结合OpenCV语言包
(JavaCV image processing library)

文件列表:
javacv (0, 2012-03-20)
javacv\.DS_Store (6148, 2012-03-20)
__MACOSX (0, 2012-03-22)
__MACOSX\javacv (0, 2012-03-22)
__MACOSX\javacv\._.DS_Store (82, 2012-03-20)
javacv\.svn (0, 2012-03-07)
javacv\.svn\all-wcprops (349, 2012-03-07)
javacv\.svn\dir-prop-base (37, 2012-03-07)
javacv\.svn\entries (704, 2012-03-07)
javacv\.svn\prop-base (0, 2012-03-07)
javacv\.svn\props (0, 2012-03-07)
javacv\.svn\text-base (0, 2012-03-07)
javacv\.svn\text-base\build.xml.svn-base (9246, 2012-03-07)
javacv\.svn\text-base\LICENSE.txt.svn-base (19355, 2012-03-07)
javacv\.svn\tmp (0, 2012-03-07)
javacv\.svn\tmp\prop-base (0, 2012-03-07)
javacv\.svn\tmp\props (0, 2012-03-07)
javacv\.svn\tmp\text-base (0, 2012-03-07)
javacv\build.xml (9246, 2012-03-07)
javacv\LICENSE.txt (19355, 2012-03-07)
javacv\nbproject (0, 2012-03-07)
javacv\nbproject\.svn (0, 2012-03-07)
javacv\nbproject\.svn\all-wcprops (532, 2012-03-07)
javacv\nbproject\.svn\dir-prop-base (33, 2012-03-07)
javacv\nbproject\.svn\entries (843, 2012-03-07)
javacv\nbproject\.svn\prop-base (0, 2012-03-07)
javacv\nbproject\.svn\props (0, 2012-03-07)
javacv\nbproject\.svn\text-base (0, 2012-03-07)
javacv\nbproject\.svn\text-base\build-impl.xml.svn-base (48391, 2012-03-07)
javacv\nbproject\.svn\text-base\genfiles.properties.svn-base (467, 2012-03-07)
javacv\nbproject\.svn\text-base\project.properties.svn-base (2296, 2012-03-07)
javacv\nbproject\.svn\text-base\project.xml.svn-base (921, 2012-03-07)
javacv\nbproject\.svn\tmp (0, 2012-03-07)
javacv\nbproject\.svn\tmp\prop-base (0, 2012-03-07)
javacv\nbproject\.svn\tmp\props (0, 2012-03-07)
javacv\nbproject\.svn\tmp\text-base (0, 2012-03-07)
javacv\nbproject\build-impl.xml (48391, 2012-03-07)
javacv\nbproject\genfiles.properties (467, 2012-03-07)
javacv\nbproject\project.properties (2296, 2012-03-07)
... ...

=JavaCV= ==Introduction== JavaCV first provides wrappers to commonly used libraries by researchers in the field of computer vision: [http://opencv.willowgarage.com/ OpenCV], [http://www.ffmpeg.org/ FFmpeg], [http://damien.douxchamps.net/ieee1394/libdc1394/ libdc1394], [http://www.ptgrey.com/products/pgrflycapture/ PGR FlyCapture], [http://openkinect.org/ OpenKinect], [http://muonics.net/school/spring05/videoInput/ videoInput], and [http://studierstube.icg.tugraz.at/handheld_ar/artoolkitplus.php ARToolKitPlus]. The following classes, found under the `com.googlecode.javacv.cpp` package namespace, expose their complete APIs: `opencv_core`, `opencv_imgproc`, `opencv_video`, `opencv_flann`, `opencv_features2d`, `opencv_calib3d`, `opencv_objdetect`, `opencv_highgui`, `opencv_legacy`, `opencv_ml`, `opencv_contrib`, `avutil`, `avcodec`, `avformat`, `avdevice`, `avfilter`, `postproc`, `swscale`, `dc1394`, `PGRFlyCapture`, `freenect`, `videoInputLib`, and `ARToolKitPlus`, respectively. Moreover, utility classes make it easy to use their functionality on the Java platform, including Android. JavaCV also comes with hardware accelerated full-screen image display (`CanvasFrame` and `GLCanvasFrame`), easy-to-use methods to execute code in parallel on multiple cores (`Parallel`), user-friendly geometric and color calibration of cameras and projectors (`GeometricCalibrator`, `ProCamGeometricCalibrator`, `ProCamColorCalibrator`), detection and matching of feature points (`ObjectFinder`), a set of classes that implement direct image alignment of projector-camera systems (mainly `GNImageAligner`, `ProjectiveTransformer`, `ProjectiveColorTransformer`, `ProCamTransformer`, and `ReflectanceInitializer`), as well as miscellaneous functionality in the `JavaCV` class. Some of these classes also have an OpenCL and OpenGL counterpart, their names ending with `CL`, i.e.: `JavaCVCL`, etc. except for `GLCanvasFrame`. To learn how to use the API, since documentation currently lacks, please refer to the [#Quick_Start_for_OpenCV_and_FFmpeg] section below as well as the sample programs, including one for Android, found in the `samples` directory. You may also find it useful to refer to the source code of [http://code.google.com/p/javacv/source/browse/trunk/procamcalib/ ProCamCalib] and [http://code.google.com/p/javacv/source/browse/trunk/procamtracker/ ProCamTracker]. I will continue to add all code that I am developing for my doctoral research as I go. ==Required Software== To use JavaCV, you will need to download and install the following software: * An implementation of Java SE 6 or 7 * OpenJDK http://openjdk.java.net/install/ or * Sun JDK http://www.oracle.com/technetwork/java/javase/downloads/ or * IBM JDK http://www.ibm.com/developerworks/java/jdk/ or * Java SE for Mac OS X http://developer.apple.com/java/ etc. * OpenCV 2.3.1 http://sourceforge.net/projects/opencvlibrary/files/ * Precompiled for Android 2.2 http://code.google.com/p/javacv/downloads/list And please make sure your Java and OpenCV have the same bitness: *32-bit and ***-bit modules do not mix under any circumstances*. Further, although not always required, some functionality of JavaCV also relies on: * FFmpeg 0.6.x or 0.7.x http://ffmpeg.org/download.html * Precompiled for Windows http://ffmpeg.zeranoe.com/builds/ Known compatible builds: * http://ffmpeg.zeranoe.com/builds/win32/shared/ffmpeg-0.7.1-win32-shared.7z * http://ffmpeg.zeranoe.com/builds/win***/shared/ffmpeg-0.7.1-win***-shared.7z * Precompiled for Android 2.2 http://code.google.com/p/javacv/downloads/list * libdc1394 2.1.x (Linux and Mac OS X) http://sourceforge.net/projects/libdc1394/files/ * PGR FlyCapture 1.7~2.2 (Windows only) http://www.ptgrey.com/products/pgrflycapture/ * OpenKinect http://openkinect.org/ * CL Eye Platform SDK http://codelaboratories.com/downloads/ * Android SDK API 8 or newer http://developer.android.com/sdk/ * JOCL and JOGL from JogAmp http://jogamp.org/ To modify the source code, please note that the project files were created for: * NetBeans 6.9 http://netbeans.org/downloads/ * JavaCPP http://code.google.com/p/javacpp/ * ARToolKitPlus 2.1.1t http://code.google.com/p/javacv/downloads/list Please keep me informed of any updates or fixes you make to the code so that I may integrate them into the next release. Thank you! And feel free to ask questions on [http://groups.google.com/group/javacv the mailing list] if you encounter any problems with the software! I am sure it is far from perfect... ==Quick Start for OpenCV and FFmpeg== First, put all the JAR files of JavaCV (`javacpp.jar`, `javacv.jar`, and `javacv-*.jar`) somewhere in your classpath, and make sure that the library files of OpenCV and FFmpeg (`*.so`, `*.dylib`, or `*.dll`) can be found either in their default installation directory or in the system PATH, which under Windows includes the current working directory. (For answers to problems frequently encountered with OpenCV on the Windows platform, please refer to [http://code.google.com/p/javacv/wiki/Windows7AndOpenCV Common issues with OpenCV under Windows 7].) Here are some more specific instructions for common cases: NetBeans (Java SE 6 or 7): * In the Projects window, right-click the Libraries node of your project, and select "Add JAR/Folder...". * Locate the JAR files, select them, and click OK. Eclipse (Java SE 6 or 7): * Navigate to Project > Properties > Java Build Path > Libraries and click "Add External JARs..." * Locate the JAR files, select them, and click OK. Eclipse (Android 2.2 or newer): * Follow the instructions on this page: http://developer.android.com/resources/tutorials/hello-world.html * Go to File > New > Folder, select your project as parent folder, type "libs/armeabi" as Folder name, and click Finish. * Copy `javacpp.jar` and `javacv.jar` in the newly created "libs" folder. * Extract directly all the `*.so` files from `javacv-android-arm.jar` *as well as* the ones from `OpenCV-2.3.1-android-arm.zip` and `ffmpeg-0.7.11-android-arm.zip` in the newly created "libs/armeabi" folder, without creating any new subdirectories. * Navigate to Project > Properties > Java Build Path > Libraries and click "Add JARs..." * Select both `javacpp.jar` and `javacv.jar` from the newly created "libs" folder. After that, the wrapper classes for OpenCV and FFmpeg can automatically access all of their C/C++ APIs. The class definitions are basically ports to Java of the original include files in C, plus the missing functionality exposed only by the C++ API of OpenCV, and I deliberately decided to keep as much of the original syntax as possible. For example, here is a method that tries to load an image file, smooth it, and save it back to disk: {{{ import static com.googlecode.javacv.cpp.opencv_core.*; import static com.googlecode.javacv.cpp.opencv_imgproc.*; import static com.googlecode.javacv.cpp.opencv_highgui.*; public class Smoother { public static void smooth(String filename) { IplImage image = cvLoadImage(filename); if (image != null) { cvSmooth(image, image, CV_GAUSSIAN, 3); cvSaveImage(filename, image); cvReleaseImage(image); } } } }}} JavaCV also comes with helper classes and methods on top of OpenCV and FFmpeg to facilitate their integration to the Java platform. Here is a small demo program demonstrating the most frequently useful parts: {{{ import com.googlecode.javacpp.Loader; import com.googlecode.javacv.*; import com.googlecode.javacv.cpp.*; import static com.googlecode.javacv.cpp.opencv_core.*; import static com.googlecode.javacv.cpp.opencv_imgproc.*; import static com.googlecode.javacv.cpp.opencv_calib3d.*; import static com.googlecode.javacv.cpp.opencv_objdetect.*; public class Demo { public static void main(String[] args) throws Exception { String classifierName = null; if (args.length > 0) { classifierName = args[0]; } else { System.err.println("Please provide the path to \"haarcascade_frontalface_alt.xml\"."); System.exit(1); } // Preload the opencv_objdetect module to work around a known bug. Loader.load(opencv_objdetect.class); // We can "cast" Pointer objects by instantiating a new object of the desired class. CvHaarClassifierCascade classifier = new CvHaarClassifierCascade(cvLoad(classifierName)); if (classifier.isNull()) { System.err.println("Error loading classifier file \"" + classifierName + "\"."); System.exit(1); } // CanvasFrame is a JFrame containing a Canvas component, which is hardware accelerated. // It can also switch into full-screen mode when called with a screenNumber. CanvasFrame frame = new CanvasFrame("Some Title"); // OpenCVFrameGrabber uses opencv_highgui, but other more versatile FrameGrabbers // include DC1394FrameGrabber, FlyCaptureFrameGrabber, OpenKinectFrameGrabber, // PS3EyeFrameGrabber, VideoInputFrameGrabber, and FFmpegFrameGrabber. FrameGrabber grabber = new OpenCVFrameGrabber(0); grabber.start(); // FAQ about IplImage: // - For custom raw processing of data, getByteBuffer() returns an NIO direct // buffer wrapped around the memory pointed by imageData. // - To get a BufferedImage from an IplImage, you may call getBufferedImage(). // - The createFrom() factory method can construct an IplImage from a BufferedImage. // - There are also a few copy*() methods for BufferedImage<->IplImage data transfers. IplImage grabbedImage = grabber.grab(); int width = grabbedImage.width(); int height = grabbedImage.height(); IplImage grayImage = IplImage.create(width, height, IPL_DEPTH_8U, 1); IplImage rotatedImage = grabbedImage.clone(); // Let's create some random 3D rotation... CvMat randomR = CvMat.create(3, 3), randomAxis = CvMat.create(3, 1); // We can easily and efficiently access the elements of CvMat objects // with the set of get() and put() methods. randomAxis.put((Math.random()-0.5)/4, (Math.random()-0.5)/4, (Math.random()-0.5)/4); cvRodrigues2(randomAxis, randomR, null); double f = (width + height)/2.0; randomR.put(0, 2, randomR.get(0, 2)*f); randomR.put(1, 2, randomR.get(1, 2)*f); randomR.put(2, 0, randomR.get(2, 0)/f); randomR.put(2, 1, randomR.get(2, 1)/f); System.out.println(randomR); // Objects allocated with a create*() or clone() factory method are automatically released // by the garbage collector, but may still be explicitly released by calling release(). // You shall NOT call cvReleaseImage(), cvReleaseMemStorage(), etc. on objects allocated this way. CvMemStorage storage = CvMemStorage.create(); // We can allocate native arrays using constructors taking an integer as argument. CvPoint hatPoints = new CvPoint(3); // Again, FFmpegFrameRecorder also exists as a more versatile alternative. FrameRecorder recorder = new OpenCVFrameRecorder("output.avi", width, height); recorder.start(); while (frame.isVisible() && (grabbedImage = grabber.grab()) != null) { cvClearMemStorage(storage); // Let's try to detect some faces! but we need a grayscale image... cvCvtColor(grabbedImage, grayImage, CV_BGR2GRAY); CvSeq faces = cvHaarDetectObjects(grayImage, classifier, storage, 1.1, 3, CV_HAAR_DO_CANNY_PRUNING); int total = faces.total(); for (int i = 0; i < total; i++) { CvRect r = new CvRect(cvGetSeqElem(faces, i)); int x = r.x(), y = r.y(), w = r.width(), h = r.height(); cvRectangle(grabbedImage, cvPoint(x, y), cvPoint(x+w, y+h), CvScalar.RED, 1, CV_AA, 0); // To access the elements of a native array, use the position() method. hatPoints.position(0).x(x-w/10) .y(y-h/10); hatPoints.position(1).x(x+w*11/10).y(y-h/10); hatPoints.position(2).x(x+w/2) .y(y-h/2); cvFillConvexPoly(grabbedImage, hatPoints.position(0), 3, CvScalar.GREEN, CV_AA, 0); } // Let's find some contours! but first some thresholding... cvThreshold(grayImage, grayImage, ***, 255, CV_THRESH_BINARY); // To check if an output argument is null we may call either isNull() or equals(null). CvSeq contour = new CvSeq(null); cvFindContours(grayImage, storage, contour, Loader.sizeof(CvContour.class), CV_RETR_LIST, CV_CHAIN_APPROX_SIMPLE); while (contour != null && !contour.isNull()) { if (contour.elem_size() > 0) { CvSeq points = cvApproxPoly(contour, Loader.sizeof(CvContour.class), storage, CV_POLY_APPROX_DP, cvContourPerimeter(contour)*0.02, 0); cvDrawContours(grabbedImage, points, CvScalar.BLUE, CvScalar.BLUE, -1, 1, CV_AA); } contour = contour.h_next(); } cvWarpPerspective(grabbedImage, rotatedImage, randomR); frame.showImage(rotatedImage); recorder.record(rotatedImage); } recorder.stop(); grabber.stop(); frame.dispose(); } } }}} ==Acknowledgments== I am currently an active member of the Okutomi & Tanaka Laboratory, Tokyo Institute of Technology, supported by a scholarship from the Ministry of Education, Culture, Sports, Science and Technology (MEXT) of the Japanese Government. ==Changes== ===February 18, 2012=== * Added `GLCanvasFrame` to show OpenGL renderbuffers on screen, plus a new factory method `JavaCVCL.createCLGLImageFrom()` to create compatible ones from `IplImage` objects, as well as more user-friendly `getGLContext()`, `getGL()` and `getGL2()` methods * Fixed various things of the original `CanvasFrame`, and `JavaCV.createCLImage()` and `createIplImage()`, also appending `From` to their names * New `createPinnedBuffer()` and `createPinnedIplImage()` factory methods in `JavaCVCL` to allocate page-locked memory for faster CPU<->GPU transfers, but it does not seem to work for OpenCL image objects, only linear buffer objects :( * Fixed and enhanced `GNImageAlignerCL` and `ProjectorDevice` (its `useOpenGL` property) to support fully OpenCL and OpenGL acceleration * Refactored `Parallel` a bit so that we may set the number of threads it uses via its static `numThreads` property or the "com.googlecode.javacv.numthreads" system property, which defaults to `Parallel.getNumCores() = Runtime.getRuntime().availableProcessors()` * Cleaned up and renamed some methods in `JavaCV`, while adding `boundingRect()`, functionally similar to `cvBoundingRect`, but better adapted to compute a properly aligned and padded ROI * Inserted a couple of missing `allocate()` inside `opencv_flann` * Updated `ObjectFinder` with a `Settings.useFLANN` property to let it use FLANN via OpenCV * Cleaned up and optimized `HandMouse` * `CanvasFrame`, `FrameGrabber`, `FrameRecorder`, and `ProjectiveDevice` objects now throw `Exception` objects of a nested class instead of the too generic `java.lang.Exception` one * Moved parallel execution of `cvkernels.multiWarpColorTransform()`, modifying `ImageTransformer` classes, from `GNImageAligner` into `cvkernels`, which now also supports other image types than `float` * Renamed some `Settings` properties here and there to correct typos and reflect better their meanings * Updated `freenect` to reflect the latest changes of OpenKinect's master branch * FFmpeg and other libraries did not work under Android when compiled with the latest NDK, r7 (issue #147): Fixed in JavaCPP * Moved `IplImage.timestamp` to `FrameGrabber`, also adding a `frameNumber` property, both allowing to seek within streams too * Removed `triggerFlushSize` property from `CameraDevice` and `FrameGrabber`, instead relying on the `numBuffers` property to decide the required size of a buffer flush * Corrected the logic behind `FFmpegFrameGrabber.getFrameRate()` and `getTimestamp()` (issue #151) * Created a `BufferRing` class for convenient circular rings of large buffers that require manual release of resources, such as OpenCL memory * Added a few more useful methods to `FrameGrabber`, including `restart()`, `flush()`, and `delayedGrab()` (to be used in conjunction with `getDelayedTime()` and `getDelayedImage()`) * Inserted `cvLoadImageBGRA()` and `cvLoadImageRGBA()` methods into `opencv_highgui` to load color images compatible with OpenCL more easily * `JavaCvErrorCallback` now outputs messages to `Logger` instead of `System.err` * Defined `VI_COM_MULTI_THREADED` for `videoInput`, allowing it to run on multiple threads if needed ===January 8, 2012=== * JavaCV should now have an easier time automatically finding libraries inside standard directories such as `/usr/local/lib/`, `/opt/local/lib/`, and `C:\opencv\`, even when they are not part of the system configuration or PATH (issue #127) * Renamed `set()` and `fill()` methods to `put()` inside `CvPoint*` classes, for better naming consistency * Renamed `FrameGrabber.ColorMode` to `ImageMode` and its `BGR` value to `COLOR` to reflect the fact that a `FrameGrabber` instance can return color images in some arbitrary format, but added a new `pixelFormat` property to let users know or specify the exact pixel format desired, such as `PIX_FMT_BGR24`, etc. in the case of `FFmpegFrameGrabber` * After `FFmpegFrameGrabber.start()`, the `format`, `imageWidth`, `imageHeight`, and `frameRate` properties switch to their effective values * Added new `FrameGrabber.sensorPattern` property to obtain the Bayer filter layout of raw data from `DC1394FrameGrabber` and `FlyCaptureFrameGrabber` * Readded to `KDTree`, `Index`, and `HOGDescriptor` some functions with `FloatPointer` and `IntPointer` arguments that were mistakenly removed when OpenCV switched to using `cv::InputArray` and `cv::OutputArray` parameter types (issue #134) * Renamed `ProjectiveGainBiasTransformer` to `ProjectiveColorTransformer` * Added a few classes to do some processing using OpenCL and OpenGL: `JavaCVCL`, `GNImageAlignerCL`, `ProjectiveTransformerCL`, `ProjectiveColorTransformerCL`, and `ProCamTransformerCL` with some other related files * Renamed `Parallel.numCores` to the more conventional `Parallel.NUM_CORES` * Added new `FaceRecognition.java` sample from Stephen L. Reed * Inserted a couple of missing calls to `Loader.load()` (issue #142) * Improved hacks for `Loader.load()` in JavaCPP make JavaCV work on Android 4.0 * New `PS3EyeFrameGrabber` from Jiri Masa can now grab images using the SDK from Code Laboratories ===October 1, 2011=== * Fixed `DC1394FrameGrabber` and `FlyCaptureFrameGrabber` to behave as expected with all Bayer/Raw/Mono/RGB/YUV cameras modes (within the limits of libdc1394 and PGR FlyCapture) (issue #91) * Fixed regression of `IplImage.copyFrom()` and `createFrom()` with `BufferedImage` objects of `SinglePixelPackedSampleModel` (issue #102) * C++ functions using `std::vector` objects as output parameters now work on Windows Vista and Windows 7 as well ... ...

近期下载者

相关文件


收藏者