「java开发opencv」JAVA开发运维招聘

博主:adminadmin 2022-12-09 09:18:15 69

本篇文章给大家谈谈java开发opencv,以及JAVA开发运维招聘对应的知识点,希望对各位有所帮助,不要忘了收藏本站喔。

本文目录一览:

如何在Eclipse中配置OpenCV开发环境

其实opencv对图片的开发更多的是使用c++、python、和matlab。用Java语言的还是很少的。现在对我用Java的eclipse来实现的开发环境做一个小结。

我下载的是opencv-2.4.10。

1、首先我们需要安装opencv,安装的过程其实就是一个解压缩的过程。我的安装目录是 D:\Program Files (x86)\opencv

里面有两个文件夹,我们主要用到build文件夹里的东西,一会稍后详细再说用到哪些东西。

2.我们需要在eclipse里面创建一个Java工程。Java工程创建完之后我们需要为它配置jar包。

步骤:

选定工程右键--build path--configure build path

找到我们安装opencv的目录下的build文件夹里,有一个Java文件,进入Java文件夹,你会看到一个opencv-2140.jar的jar包,选中它,进行添加。

然后你需要点开刚才应用的jar包,再选中native library location 选择edit 编辑,找到

D:\Program Files (x86)\opencv\opencv\build\x64

这里注意,不同的系统有不同的选择哦。注意如果是64位操作系统,这里要选择x64,如果是32位操作系统就选x86,选错了回报做的。

小编这里是64位的win7,所以选的是x64

接下来就是点击确定,那么我们的环境算是配置完成。

现在在工程里建立一个类测试一下我们的环境是否正常运行。

代码如下

package opencv_test;

import org.opencv.core.Core;

import org.opencv.core.CvType;

import org.opencv.core.Mat;

import org.opencv.core.MatOfKeyPoint;

import org.opencv.features2d.DescriptorExtractor;

import org.opencv.features2d.FeatureDetector;

public class test {

/**

* @param args

*/

public static void main(String[] args) {

// TODO Auto-generated method stub

System.loadLibrary("opencv_java2410");

Mat m = Mat.eye(3, 3, CvType.CV_8UC1);

System.out.println("m = " + m.dump());

}

}

输出结果:

最后在添加一个读取图片的小示例

System.loadLibrary( Core.NATIVE_LIBRARY_NAME );

Mat test_mat = Highgui.imread("F:/rgbd_dataset_freiburg1_360/pcd/1305031790.645155.pcd");

Mat test_mat = Highgui.imread("C:/Users/Administrator/Desktop/2]TOH]6F75N5ZR5YTW4Y}{Q.jpg");

System.out.println(test_mat.dump());

在java环境下编写opencv,用哪款java软件比较好

本来是要写一个简单的Base64编码程序,把一个图像文件利用Base64编码转换成一个txt文档;由于之前一直用C++做图像处理,所以对OpenCV各种恋恋不舍,再加上Java语言本身提供的像素操作实在是让我觉得不爽,所以想在Java中使用OpenCV。(备注:开发工具是Eclipse)

主要的参考资料为:

1

2

步骤总结如下:

1 在OpenCV官网上下载OpenCV-2.4.4,在里下载javacv-0.4-cppjars.zip,这里注意匹配问题,Javacv0.4可以支持OpenCV-2.4.4

2 安装OpenCV2.4.4,注意安装的路径中不要出现中文;添加系统环境变量PATH:

D:\OpenCV-2.4.4\opencv\build\x86\vc9\bin;

参考博客中使用的是OpenCV2.4.2,添加的还有什么tbb环境变量,在OpenCV2.4.4中压根就没有common文件夹,所以这一项可以忽略。

3 安装完成之后,可以在Visual Studio中测试OpenCV2.4.4是否好用;在这里注意项目包含文件和库文件的添加:(由于我的操作系统不是Win7的正式发布版,所以无法安装VS2010等以上版本,所以依旧在VS2008中进行测试)

工具-选项-项目和解决方案-VC++目录

包含文件:D:\OpenCV-2.4.4\opencv\build\include

D:\OpenCV-2.4.4\opencv\build\include\opencv

D:\OpenCV-2.4.4\opencv\build\include\opencv2

库文件: D:\OpenCV-2.4.4\opencv\build\x86\vc9\lib

4 OpenCV2.4.4测试成功安装完成之后,进入到Eclipse,新建Java Project,并在该工程目录下新建文件夹lib和libs\armeabi(这里我也不太清楚是为什么,按照参考博文来的,暂时好用就行~==!);然后把下载的javacv-0.4-cppjars.zip解压,解压后的文件全部拷贝到libs文件夹下,并在Java工程目录下进行刷新,此步截图如下:

java可以用opencv的哪些功能

整个项目的结构图:

编写DetectFaceDemo.java,代码如下:

[java] view

plaincopyprint?

package com.njupt.zhb.test;

import org.opencv.core.Core;

import org.opencv.core.Mat;

import org.opencv.core.MatOfRect;

import org.opencv.core.Point;

import org.opencv.core.Rect;

import org.opencv.core.Scalar;

import org.opencv.highgui.Highgui;

import org.opencv.objdetect.CascadeClassifier;

//

// Detects faces in an image, draws boxes around them, and writes the results

// to "faceDetection.png".

//

public class DetectFaceDemo {

public void run() {

System.out.println("\nRunning DetectFaceDemo");

System.out.println(getClass().getResource("lbpcascade_frontalface.xml").getPath());

// Create a face detector from the cascade file in the resources

// directory.

//CascadeClassifier faceDetector = new CascadeClassifier(getClass().getResource("lbpcascade_frontalface.xml").getPath());

//Mat image = Highgui.imread(getClass().getResource("lena.png").getPath());

//注意:源程序的路径会多打印一个‘/’,因此总是出现如下错误

/*

* Detected 0 faces Writing faceDetection.png libpng warning: Image

* width is zero in IHDR libpng warning: Image height is zero in IHDR

* libpng error: Invalid IHDR data

*/

//因此,我们将第一个字符去掉

String xmlfilePath=getClass().getResource("lbpcascade_frontalface.xml").getPath().substring(1);

CascadeClassifier faceDetector = new CascadeClassifier(xmlfilePath);

Mat image = Highgui.imread(getClass().getResource("we.jpg").getPath().substring(1));

// Detect faces in the image.

// MatOfRect is a special container class for Rect.

MatOfRect faceDetections = new MatOfRect();

faceDetector.detectMultiScale(image, faceDetections);

System.out.println(String.format("Detected %s faces", faceDetections.toArray().length));

// Draw a bounding box around each face.

for (Rect rect : faceDetections.toArray()) {

Core.rectangle(image, new Point(rect.x, rect.y), new Point(rect.x + rect.width, rect.y + rect.height), new Scalar(0, 255, 0));

}

// Save the visualized detection.

String filename = "faceDetection.png";

System.out.println(String.format("Writing %s", filename));

Highgui.imwrite(filename, image);

}

}

package com.njupt.zhb.test;

import org.opencv.core.Core;

import org.opencv.core.Mat;

import org.opencv.core.MatOfRect;

import org.opencv.core.Point;

import org.opencv.core.Rect;

import org.opencv.core.Scalar;

import org.opencv.highgui.Highgui;

import org.opencv.objdetect.CascadeClassifier;

//

// Detects faces in an image, draws boxes around them, and writes the results

// to "faceDetection.png".

//

public class DetectFaceDemo {

public void run() {

System.out.println("\nRunning DetectFaceDemo");

System.out.println(getClass().getResource("lbpcascade_frontalface.xml").getPath());

// Create a face detector from the cascade file in the resources

// directory.

//CascadeClassifier faceDetector = new CascadeClassifier(getClass().getResource("lbpcascade_frontalface.xml").getPath());

//Mat image = Highgui.imread(getClass().getResource("lena.png").getPath());

//注意:源程序的路径会多打印一个‘/’,因此总是出现如下错误

/*

* Detected 0 faces Writing faceDetection.png libpng warning: Image

* width is zero in IHDR libpng warning: Image height is zero in IHDR

* libpng error: Invalid IHDR data

*/

//因此,我们将第一个字符去掉

String xmlfilePath=getClass().getResource("lbpcascade_frontalface.xml").getPath().substring(1);

CascadeClassifier faceDetector = new CascadeClassifier(xmlfilePath);

Mat image = Highgui.imread(getClass().getResource("we.jpg").getPath().substring(1));

// Detect faces in the image.

// MatOfRect is a special container class for Rect.

MatOfRect faceDetections = new MatOfRect();

faceDetector.detectMultiScale(image, faceDetections);

System.out.println(String.format("Detected %s faces", faceDetections.toArray().length));

// Draw a bounding box around each face.

for (Rect rect : faceDetections.toArray()) {

Core.rectangle(image, new Point(rect.x, rect.y), new Point(rect.x + rect.width, rect.y + rect.height), new Scalar(0, 255, 0));

}

// Save the visualized detection.

String filename = "faceDetection.png";

System.out.println(String.format("Writing %s", filename));

Highgui.imwrite(filename, image);

}

}

3.编写测试类:

[java] view

plaincopyprint?

package com.njupt.zhb.test;

public class TestMain {

public static void main(String[] args) {

System.out.println("Hello, OpenCV");

// Load the native library.

System.loadLibrary("opencv_java246");

new DetectFaceDemo().run();

}

}

//运行结果:

//Hello, OpenCV

//

//Running DetectFaceDemo

///E:/eclipse_Jee/workspace/JavaOpenCV246/bin/com/njupt/zhb/test/lbpcascade_frontalface.xml

//Detected 8 faces

//Writing faceDetection.png

package com.njupt.zhb.test;

public class TestMain {

public static void main(String[] args) {

System.out.println("Hello, OpenCV");

// Load the native library.

System.loadLibrary("opencv_java246");

new DetectFaceDemo().run();

}

}

//运行结果:

//Hello, OpenCV

//

//Running DetectFaceDemo

///E:/eclipse_Jee/workspace/JavaOpenCV246/bin/com/njupt/zhb/test/lbpcascade_frontalface.xml

//Detected 8 faces

//Writing faceDetection.png

opencv中的Dnn模块怎么用Java调用

1.检查环境变量设定。

比如:所编辑的Dll在目录“D:/cppProjects/nativecode/release”内,将这个路径复制添加到电脑的环境变量中的path变量内即可。

2.检查项目属性设定。

右击项目名|选择属性properties|在左边列表内选择“Java Build Path”|在右边选项卡用选择“source”|点开项目名前的“+”号,选择“Native library location”,“Edit”选择上面“D:/cppProjects/nativecode/release”路径。(当然如果将dll拷贝到workspace下也可以用相对路径。也可右击“src”设定其properties内Native Library项。)

用OpenCV开发人脸识别软件,用Java好还是用C/C++好

opencv是C++开发的,讲究执行效率还是用c/c++吧,毕竟java在这方面没优势

java servlet调用opencv的问题

1.检查环境变量设定。

比如:所编辑的Dll在目录“D:/cppProjects/nativecode/release”内,将这个路径复制添加到电脑的环境变量中的path变量内即可。

2.检查项目属性设定。

右击项目名|选择属性properties|在左边列表内选择“Java Build Path”|在右边选项卡用选择“source”|点开项目名前的“+”号,选择“Native library location”,“Edit”选择上面“D:/cppProjects/nativecode/release”路径。(当然如果将dll拷贝到workspace下也可以用相对路径。也可右击“src”设定其properties内Native Library项。)

java开发opencv的介绍就聊到这里吧,感谢你花时间阅读本站内容,更多关于JAVA开发运维招聘、java开发opencv的信息别忘了在本站进行查找喔。

The End

发布于:2022-12-09,除非注明,否则均为首码项目网原创文章,转载请注明出处。