直接使用Homebrew安装即可,运行命令:
brew install cmake
brew install ant
下载完openCV、cmake和ant以后,将openCV解压,然后进入openCV-4.5.0文件夹下,创建build文件夹用来存放编译文件,然后进入到build文件夹下进行build:
mkdir build
cd build/
cmake -G "Unix Makefiles" ..
build完成后会有如下输出:
可以看到和java相关的都为Yes才算通过。
1,若是此处Java 相关的为NO,则在build前先export一下jdk的环境变量然后再build,不然在待会编译的时候不会生成jar。
2,由于我使用的是jdk1.8,而安装最新ant使用的是jdk11,因此需要指定一下jdk版本,具体位置在:opencv-4.5.0/modules/java/jar/build.xml.in 打开此文件,在javac下添加target和source属性
build成功之后就可以进行编译了:
sudo make
编译成功后如下图:
编译完成就可以安装了:
sudo make install
安装完成后,会在/usr/local/lib下出现许多 libopencv*相关的jar包,至此opercv安装成功。
注意:此处要将/usr/local/share/java/opencv4/libopencv_java450.dylib文件拷贝到jdk的lib目录下,不然在使用的时候会报找不到类库的问题。
在idea下新建java的项目,然后添加编译好的opencv-450.jar包用来连接opencv:File——>Project Structures——>Models——>Dependinces选择添加对应的jar包:
添加成功后,在opencv的安装目录下有个示例文件夹:opencv-4.5.0/samples/java,可以将里面的内容拷贝出来几个类进行测试,我使用的是BasicGeometricDrawing.java,代码如下:
import org.opencv.core.*;
import org.opencv.core.Point;
import org.opencv.highgui.HighGui;
import org.opencv.imgproc.Imgproc;
import java.util.*;
import java.util.List;
class GeometricDrawingRun{
private static final int W = 400;
public void run(){
//! [create_images]
/// Windows names
String atom_window = "Drawing 1: Atom";
String rook_window = "Drawing 2: Rook";
/// Create black empty images
Mat atom_image = Mat.zeros( W, W, CvType.CV_8UC3 );
Mat rook_image = Mat.zeros( W, W, CvType.CV_8UC3 );
//! [create_images]
//! [draw_atom]
/// 1. Draw a simple atom:
/// -----------------------
MyEllipse( atom_image, 90.0 );
MyEllipse( atom_image, 0.0 );
MyEllipse( atom_image, 45.0 );
MyEllipse( atom_image, -45.0 );
/// 1.b. Creating circles
MyFilledCircle( atom_image, new Point( W/2, W/2) );
//! [draw_atom]
//! [draw_rook]
/// 2. Draw a rook
/// ------------------
/// 2.a. Create a convex polygon
MyPolygon( rook_image );
//! [rectangle]
/// 2.b. Creating rectangles
Imgproc.rectangle( rook_image,
new Point( 0, 7*W/8 ),
new Point( W, W),
new Scalar( 0, 255, 255 ),
//! [rectangle]
/// 2.c. Create a few lines
MyLine( rook_image, new Point( 0, 15*W/16 ), new Point( W, 15*W/16 ) );
MyLine( rook_image, new Point( W/4, 7*W/8 ), new Point( W/4, W ) );
MyLine( rook_image, new Point( W/2, 7*W/8 ), new Point( W/2, W ) );
MyLine( rook_image, new Point( 3*W/4, 7*W/8 ), new Point( 3*W/4, W ) );
//! [draw_rook]
/// 3. Display your stuff!
HighGui.imshow( atom_window, atom_image );
HighGui.moveWindow( atom_window, 0, 200 );
HighGui.imshow( rook_window, rook_image );
HighGui.moveWindow( rook_window, W, 200 );
HighGui.waitKey( 0 );
System.exit(0);
/// Function Declaration
* @function MyEllipse
* @brief Draw a fixed-size ellipse with different angles
//! [my_ellipse]
private void MyEllipse( Mat img, double angle ) {
int thickness = 2;
int lineType = 8;
int shift = 0;
Imgproc.ellipse( img,
new Point( W/2, W/2 ),
new Size( W/4, W/16 ),
angle,
360.0,
new Scalar( 255, 0, 0 ),
thickness,
lineType,
shift );
//! [my_ellipse]
* @function MyFilledCircle
* @brief Draw a fixed-size filled circle
//! [my_filled_circle]
private void MyFilledCircle( Mat img, Point center ) {
int thickness = -1;
int lineType = 8;
int shift = 0;
Imgproc.circle( img,
center,
W/32,
new Scalar( 0, 0, 255 ),
thickness,
lineType,
shift );
//! [my_filled_circle]
* @function MyPolygon
* @function Draw a simple concave polygon (rook)
//! [my_polygon]
private void MyPolygon( Mat img ) {
int lineType = 8;
int shift = 0;
/** Create some points */
Point[] rook_points = new Point[20];
rook_points[0] = new Point( W/4, 7*W/8 );
rook_points[1] = new Point( 3*W/4, 7*W/8 );
rook_points[2] = new Point( 3*W/4, 13*W/16 );
rook_points[3] = new Point( 11*W/16, 13*W/16 );
rook_points[4] = new Point( 19*W/32, 3*W/8 );
rook_points[5] = new Point( 3*W/4, 3*W/8 );
rook_points[6] = new Point( 3*W/4, W/8 );
rook_points[7] = new Point( 26*W/40, W/8 );
rook_points[8] = new Point( 26*W/40, W/4 );
rook_points[9] = new Point( 22*W/40, W/4 );
rook_points[10] = new Point( 22*W/40, W/8 );
rook_points[11] = new Point( 18*W/40, W/8 );
rook_points[12] = new Point( 18*W/40, W/4 );
rook_points[13] = new Point( 14*W/40, W/4 );
rook_points[14] = new Point( 14*W/40, W/8 );
rook_points[15] = new Point( W/4, W/8 );
rook_points[16] = new Point( W/4, 3*W/8 );
rook_points[17] = new Point( 13*W/32, 3*W/8 );
rook_points[18] = new Point( 5*W/16, 13*W/16 );
rook_points[19] = new Point( W/4, 13*W/16 );
MatOfPoint matPt = new MatOfPoint();
matPt.fromArray(rook_points);
List<MatOfPoint> ppt = new ArrayList<MatOfPoint>();
ppt.add(matPt);
Imgproc.fillPoly(img,
new Scalar( 255, 255, 255 ),
lineType,
shift,
new Point(0,0) );
//! [my_polygon]
* @function MyLine
* @brief Draw a simple line
//! [my_line]
private void MyLine( Mat img, Point start, Point end ) {
int thickness = 2;
int lineType = 8;
int shift = 0;
Imgproc.line( img,
start,
new Scalar( 0, 0, 0 ),
thickness,
lineType,
shift );
//! [my_line]
public class BasicGeometricDrawing {
public static void main(String[] args) {
// Load the native library.
System.loadLibrary(Core.NATIVE_LIBRARY_NAME);
new GeometricDrawingRun().run();
运行main方法后出现如下图证明成功了:
整个环境的安装和调试花了将尽3天时间,查了大量的资料踩了很多坑,总算是安装成功了,之后还会有opencv部署和使用相关的文章,欢迎一起探讨。特别说明一下,若是在运行的时候出现jdk版本的问题或者是类库找不到的问题,一定要重新编译安装,否则不会生效。
问题:安装opencv后share文件夹下一直不出现java安装包。如下修改后,最后出来。system后 加上 "arch" ,"-arm64"1、修改opencv配置。
下载地址:https://opencv.org/opencv-3-2/
要选择对应版本,本人是windows
2、下载下来之后发现是一个exe文件,双击运行。然后会有一个文件让你下载下来
点进去可以选择对应的版本,以及语言
3、把jar包放到本机中jdk下的bin...
本人在Mac系统上尝试下载opencv源码,然后通过cmake,make,make install命令编译安装,都失败,各种依赖缺失报错。最后通过brew install --build-from-source opencv安装成功。 这里面虽然通过brew install成功了,但是背后还是cmake,make,make install,为什么这么说,因为在执行brew install之前,做了很多准备工作。 0、这里使用的是brew install,它安装的时候,直接把各种缺少的依赖给装
将 \build\java\x64(x64 或者 x86 根据操作系统的位数选择) 目录中的 opencv_java455.dll 文件拷贝到 C:\Window...
SpringBoot环境下配置Java版OpenCV
opencv是享受盛誉的图像处理库,可惜是个c库,但是早些年其也提供了java版本的接口,但是国内其资料和教程实在太少,并且在JavaCV混得风生水起的情况下,OpenCV-Java的生存环境越来越恶劣。
但是近期图像处理大作业,脑子抽了想要模仿Photopea做Web版Ps网站,顺便搭起了前后端分离项目,后端语言定了Java,又不想额外花时间去学习JavaCV,所以就选择了OpenCV-Java(其实有Python版,而且生态比Java好不是一丁半点,
mac上面最方便快捷的安装方法是使用Homebrew,如果你的设备没有安装homebrew,你可以从这里下载并安装
Homebrew安装完成后,检查一下你是否已经安装了XCode 命令行工具,在终端执行以下命令:
xcode-select --install
如果出现error: command line tools are already installed 你就可以直接开始安装OpenCV了,如果...
安装地址 :(Java Download | Java 8, Java 11, Java 13 - Linux, Windows & macOS)
注意:Architecture类型一定要选择正确,不然编写java代码会报下面的错,这是因为mac系统...
1、首先我们先到官网下载opencv的包,在官网下载到的是一个可运行文件,其实就是一个解压程序,运行后会把opencv的相关文件解压到填写的路径。2、 在编辑环境变量窗口,点击新建,然后将opencv文件夹里的bin路径复制进去,如下图所示,针对你想配置的环境是32位还是64位的来选择合适的bin,如果是32位的则选择x86文件夹下的bin,反之则选择64下的bin。具体可以点击这里,在这就不啰嗦...
https://github.com/zq2599/blog_demos
内容:所有原创文章分类汇总及配套源码,涉及Java、Docker、Kubernetes、DevOPS等;
在《三分钟:极速体验JAVA版目标检测(YOLO4)》一文中,咱们体验了YOLO4强大的物体识别能力,如下图:
如果您已看过《三分钟:极速体验JAVA版目标检测(YOLO.
opencv 源码
https://opencv.org/releases
![下载sources](https://img-blog.csdnimg.cn/2019112818423848.png?x-oss-process...