javacv-examples:在Java虚拟机上使用JavaCV OpenCV库的示例

  • E9_902308
    了解作者
  • 16.4MB
    文件大小
  • zip
    文件格式
  • 0
    收藏次数
  • VIP专享
    资源类型
  • 0
    下载次数
  • 2022-06-15 02:03
    上传日期
JavaCV-示例 该项目包含使用和来自项目的其他库包装器的。 -在罗伯特Laganière的书“OpenCV计算机视觉应用编程食谱”介绍的例子JavaCV版本。 Cookbook中的原始示例是C ++,在此将它们转换为使用JavaCV API。 使用库的示例。 将用于Flir / Point Grey 。 demo-将用于Flir / Point Grey 示例。
内容介绍
OpenCV Cookbook Examples ========================= | [Next: Chapter 1>](src/main/scala/opencv_cookbook/chapter01) | Overview -------- **OpenCV Cookbook Examples** illustrate use of OpenCV with [JavaCV][javacv]. The Examples started as a port of C++ code from Robert Laganière's book "[OpenCV 2 Computer Vision Application Programming Cookbook](https://www.packtpub.com/application-development/opencv-2-computer-vision-application-programming-cookbook)". Later updated for the second edition of the book "[OpenCV Computer Vision Application Programming Cookbook Second Edition](https://www.packtpub.com/application-development/opencv-3-computer-vision-application-programming-cookbook)". The examples in the book use [OpenCV](http://opencv.org/) C++ API. Here they are translated to use [JavaCV](https://github.com/bytedeco/javacv) and [JavaCPP-Presets](https://github.com/bytedeco/javacpp-presets) APIs. [OpenCV](http://opencv.org/) (Open Source Computer Vision) is a library of several hundred algorithms for computer vision and video analysis. OpenCV can be us on JVM using two approaches. First are Java [wrappers provided by OpenCV](http://docs.opencv.org/doc/tutorials/introduction/desktop_java/java_dev_intro.html). Second are wrappers based on [JavaCPP](https://github.com/bytedeco/javacpp) (C++ wrapper engine for JVM) called [OpenCV JavaCPP Presets](https://github.com/bytedeco/javacpp-presets). There are also JavaCPP presets for other computer vision related libraries like: [FFmpeg](http://ffmpeg.org/), [libdc1394](http://damien.douxchamps.net/ieee1394/libdc1394/), [PGR FlyCapture](http://www.ptgrey.com/products/pgrflycapture/), [OpenKinect](http://openkinect.org/), [videoInput](http://muonics.net/school/spring05/videoInput/), [ARToolKitPlus](http://studierstube.icg.tugraz.at/handheld_ar/artoolkitplus.php), [flandmark](http://cmp.felk.cvut.cz/~uricamic/flandmark/), and [others](https://github.com/bytedeco/javacpp-presets). JavaCV combines libraries in JavaCPP Presets and add some additional functionality that makes them easier use on JVM. The *OpenCV Cookbook Examples* project illustrates use of OpenCV through JavaCV and OpenCV JavaCPP Presets. The current version is updated to match the second edition of the Robert Laganière's book "[OpenCV Computer Vision Application Programming Cookbook Second Edition](https://www.packtpub.com/application-development/opencv-3-computer-vision-application-programming-cookbook)". It is intended for use with OpenCV v.4 (JavaCV v.1). While code in the examples is primarily written in [Scala](http://www.scala-lang.org), one of the leading JVM languages. It can be easily converted to Java and other languages running on JVM, for instance, [Groovy](http://groovy.codehaus.org/). The use of the JavaCV API is very similar in most JVM languages. Some examples are provided in Java version. Quick Sample ------------ Here is a quick preview that compares an original C++ example with code in Scala and Java using JavaCV wrapper. Here is the original C++ example that opens an image (without error checking), creates a window, displays image in the window, and waits for 5 seconds before exiting. ```cpp #include <opencv2/core/core.hpp> #include <opencv2/highgui/highgui.hpp> #include <opencv2/imgcodecs/imgcodecs.hpp> int main() { // Read an image cv::Mat src = cv::imread("data/boldt.jpg"); display(src, "Input") // Apply Laplacian filter cv::Mat dest; cv::Laplacian(src, dest, src.depth(), 1, 3, 0, BORDER_DEFAULT); display(dest, "Laplacian"); // wait key for 5000 ms cv::waitKey(5000); return 1; } //--------------------------------------------------------------------------- void display(Mat image, char* caption) { // Create image window named "My Image" cv::namedWindow(caption); // Show image on window cv::imshow(caption, image); } ``` The above C++ example translated to Scala using JavaCV wrapper: ```scala import javax.swing._ import org.bytedeco.javacv._ import org.bytedeco.opencv.global.opencv_core._ import org.bytedeco.opencv.global.opencv_imgcodecs._ import org.bytedeco.opencv.global.opencv_imgproc._ import org.bytedeco.opencv.opencv_core._ object MyFirstOpenCVApp extends App { // Read an image. val src = imread("data/boldt.jpg") display(src, "Input") // Apply Laplacian filter val dest = new Mat() Laplacian(src, dest, src.depth(), 1, 3, 0, BORDER_DEFAULT) display(dest, "Laplacian") //--------------------------------------------------------------------------- /** Display `image` with given `caption`. */ def display(image: Mat, caption: String): Unit = { // Create image window named "My Image." val canvas = new CanvasFrame(caption, 1) // Request closing of the application when the image window is closed. canvas.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE) // Convert from OpenCV Mat to Java Buffered image for display val converter = new OpenCVFrameConverter.ToMat() // Show image on window canvas.showImage(converter.convert(image)) } } ``` Now the same example expressed in a Java. Note that use of JavaCV API is exactly the same as in Scala and Java code. The only practical difference is that in Java code is more verbose, you have to explicitly provide type for each variable, in Scala it is optional. ```java import org.bytedeco.javacv.CanvasFrame; import org.bytedeco.javacv.OpenCVFrameConverter; import org.bytedeco.opencv.opencv_core.Mat; import javax.swing.*; import static org.bytedeco.opencv.global.opencv_core.BORDER_DEFAULT; import static org.bytedeco.opencv.global.opencv_imgcodecs.imread; import static org.bytedeco.opencv.global.opencv_imgproc.Laplacian; public class MyFirstOpenCVAppInJava { public static void main(String[] args) { // Read an image. final Mat src = imread("data/boldt.jpg"); display(src, "Input"); // Apply Laplacian filter final Mat dest = new Mat(); Laplacian(src, dest, src.depth(), 1, 3, 0, BORDER_DEFAULT); display(dest, "Laplacian"); } //--------------------------------------------------------------------------- static void display(Mat image, String caption) { // Create image window named "My Image". final CanvasFrame canvas = new CanvasFrame(caption, 1.0); // Request closing of the application when the image window is closed. canvas.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); // Convert from OpenCV Mat to Java Buffered image for display final OpenCVFrameConverter<Mat> converter = new OpenCVFrameConverter.ToMat(); // Show image on window. canvas.showImage(converter.convert(image)); } } ``` OpenCV Documentation is Your Friend ----------------------------------- If you are looking for a particular OpenCV operation, use the [OpenCV documentation](http://docs.opencv.org/). The Quick Search box is particularly helpful. The documentation contains descriptions of alternative ways how C/C++ OpenCV API can be used. How to use JavaCV Examples -------------------------- The *OpenCV Cookbook Examples* project is intended as a companion to the Robert Laganière's book "[OpenCV Computer Vision Application Programming Cookbook Second Edition](https://www.packtpub.com/application-development/opencv-3-computer-vision-application-programming-cookbook)". The recommended way is to read the Cookbook and refer to JavaCV examples when in doubt how to translate the Cookbook's C++ code to JavaCV. The Cookbook provides explanation how the algorithms work. The JavaCV examples provide only very brief comments related to specifics of JavaCV API. The simplest way to use the JavaCV examples is to browse the code located in [src/main] online. You can also download it to you computer either use Git or as a ZIP file. With a minimal setup you can easily execute the examples on you own computer. This is one of the benefits of JavaCV - it provides
评论
    相关推荐
    • opencv 计算机视觉 编程攻略
      计算机视觉编程攻略 opencv 结构清晰,介绍详细
    • OpenCV3计算机视觉
      对于计算机视觉的人来说是一本福利,很值得入手此书。
    • opencv计算机视觉——鼠标响应
      1、OpenCV 2 计算机视觉编程手册_中文版(必学 ) 2、OpenCV 2 Computer.Vision.Application.Programming. 3、OpenCV实例精解(必学) 4、学习OpenCV(中文版) 5、基于OpenCV计算机视觉技术实现 6、深入理解OpenCV...
    • 基于OpenCV计算机视觉技术实现
      《基于OpenCV计算机视觉技术实现》介绍了大约200多个典型的技术问题,覆盖了基于OpenCV基础编程的主要内容,利用大量生动有趣的编程案例和编程技巧,从解决问题和答疑解惑入手,以因特网上最新资料为蓝本,深入浅...
    • 基于OpenCV计算机视觉技术实现
      这是包含《基于OpenCV计算机视觉技术实现》的原书电子版(分章节),和工程代码,资料很全,一般的都是只有代码,没有书,我是把两份集合打包分享给大家。希望对你有帮助。
    • opencv3计算机视觉leaningopcvPracticalIntroduction
      A Practical Introduction to Computer Vision with OpenCV,OpenCV 3计算机视觉 第2版,LearningOpenCV3(第3版)经过大量的筛选,找出三本学习opencv技术最佳图书组合。pdf格式,清晰有目录,打包下载。
    • 基于opencv计算机视觉实现
      是基于opencv计算机视觉实现这本书中的所有源代码
    • OpenCV 2 计算机视觉编程手册
      OpenCV 2 计算机视觉编程手册 源代码
    • 基于OpenCV计算机视觉技术实现
      基于OpenCV计算机视觉技术实现,可以学学,很不错哦,基于OpenCV计算机视觉技术实现,可以学学,很不错哦
    • OpenCV计算机视觉常用测试图
      OpenCV计算机视觉的常用测试图,里面包含baboon、man、monarch、sailboat、soccer、lena、tiffany等!里面还有标准测试图