安装 Java 和 OpenCV 在 Linux 下是相对简单的。下面我将介绍在 Ubuntu 上安装 Java 和 OpenCV 的步骤。

1. 安装 Java

在 Ubuntu 上,您可以通过默认的包管理工具 apt 来安装 OpenJDK(Open Java Development Kit)。

sudo apt update
sudo apt install default-jdk

这将安装 OpenJDK,并设置为默认的 Java 运行时环境。

2. 配置 Java 环境变量

安装完成后,您可能需要设置 JAVA_HOME 等 Java 相关环境变量。编辑 ~/.bashrc 文件并添加以下行:

export JAVA_HOME=/usr/lib/jvm/default-java
export PATH=$PATH:$JAVA_HOME/bin

使更改生效:

source ~/.bashrc

3. 安装 OpenCV

在 Ubuntu 上安装 OpenCV 可以使用 apt 包管理器。但是请注意,这将安装的可能是较旧的版本。如果您需要安装最新版本,可以考虑从源代码构建。

sudo apt update
sudo apt install libopencv-dev python3-opencv

这将安装 OpenCV 开发文件和 Python 绑定。

4. 测试 OpenCV

您可以编写一个简单的 Python 脚本来测试 OpenCV 是否安装成功。例如,创建一个名为 test_opencv.py 的文件,内容如下:

import cv2

# 读取图像
image = cv2.imread('test_image.jpg')

# 显示图像
cv2.imshow('Image', image)
cv2.waitKey(0)
cv2.destroyAllWindows()

确保将 test_image.jpg 替换为您计算机上存在的图像文件。

运行脚本:

python3 test_opencv.py

如果一切顺利,应该会打开一个窗口显示您的图像。

至此,您已经成功在 Ubuntu 上安装了 Java 和 OpenCV。

GitHub 加速计划 / opencv31 / opencv
142
15
下载
OpenCV: 开源计算机视觉库
最近提交(Master分支:3 个月前 )
d9a139f9 Animated WebP Support #25608 related issues #24855 #22569 ### Pull Request Readiness Checklist See details at https://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request - [x] I agree to contribute to the project under Apache 2 License. - [x] To the best of my knowledge, the proposed patch is not based on a code under GPL or another license that is incompatible with OpenCV - [x] The PR is proposed to the proper branch - [x] There is a reference to the original bug report and related work - [ ] There is accuracy test, performance test and test data in opencv_extra repository, if applicable Patch to opencv_extra has the same branch name. - [ ] The feature is well documented and sample code can be built with the project CMake 1 天前
09030615 V4l default image size #25500 Added ability to set default image width and height for V4L capture. This is required for cameras that does not support 640x480 resolution because otherwise V4L capture cannot be opened and failed with "Pixel format of incoming image is unsupported by OpenCV" and then with "can't open camera by index" message. Because of the videoio architecture it is not possible to insert actions between CvCaptureCAM_V4L::CvCaptureCAM_V4L and CvCaptureCAM_V4L::open so the only way I found is to use environment variables to preselect the resolution. Related bug report is [#25499](https://github.com/opencv/opencv/issues/25499) Maybe (but not confirmed) this is also related to [#24551](https://github.com/opencv/opencv/issues/24551) This fix was made and verified in my local environment: capture board AVMATRIX VC42, Ubuntu 20, NVidia Jetson Orin. ### Pull Request Readiness Checklist See details at https://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request - [X] I agree to contribute to the project under Apache 2 License. - [X] To the best of my knowledge, the proposed patch is not based on a code under GPL or another license that is incompatible with OpenCV - [X] The PR is proposed to the proper branch - [X] There is a reference to the original bug report and related work - [ ] There is accuracy test, performance test and test data in opencv_extra repository, if applicable Patch to opencv_extra has the same branch name. - [ ] The feature is well documented and sample code can be built with the project CMake 1 天前
Logo

旨在为数千万中国开发者提供一个无缝且高效的云端环境,以支持学习、使用和贡献开源项目。

更多推荐