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](". Later updated for the second edition of the book "[OpenCV Computer Vision Application Programming Cookbook Second Edition](". The examples in the book use [OpenCV]( C++ API. Here they are translated to use [JavaCV]( and [JavaCPP-Presets]( APIs. [OpenCV]( (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]( Second are wrappers based on [JavaCPP]( (C++ wrapper engine for JVM) called [OpenCV JavaCPP Presets]( There are also JavaCPP presets for other computer vision related libraries like: [FFmpeg](, [libdc1394](, [PGR FlyCapture](, [OpenKinect](, [videoInput](, [ARToolKitPlus](, [flandmark](, and [others]( 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](". It is intended for use with OpenCV v.4 (JavaCV v.1). While code in the examples is primarily written in [Scala](, one of the leading JVM languages. It can be easily converted to Java and other languages running on JVM, for instance, [Groovy]( 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 import import 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; import static; import static; 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]( 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](". 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计算机视觉技术实现
    • opencv3计算机视觉leaningopcvPracticalIntroduction
      A Practical Introduction to Computer Vision with OpenCV,OpenCV 3计算机视觉 第2版,LearningOpenCV3(第3版)经过大量的筛选,找出三本学习opencv技术最佳图书组合。pdf格式,清晰有目录,打包下载。
    • 基于opencv计算机视觉实现
    • OpenCV 2 计算机视觉编程手册
      OpenCV 2 计算机视觉编程手册 源代码
    • 基于OpenCV计算机视觉技术实现
    • OpenCV计算机视觉常用测试图