我正在尝试使用本教程在我的 Mac 上安装 OpenCV:https://medium.com/macoclock/setting-up-mac-for-opencv-java-development-with-intellij-idea-fd2153eb634f
当我这样做时:
<块引用>brew 安装 opencv
我收到:
==> Searching for similarly named formulae...
These similarly named formulae were found:
opencv opencv@2 opencv@3
To install one of them, run (for example):
brew install opencv
Error: No available formula or cask with the name "opencv".
==> Searching taps on GitHub...
Error: No formulae found in taps.
它显示“opencv”公式,为什么不安装它? 如何修复?
我也做过:
> xcode-select --install
xcode-select: error: command line tools are already installed, use "Software Update" to install updates
和
> brew install ant
Warning: ant 1.10.9 is already installed and up-to-date
To reinstall 1.10.9, run `brew reinstall ant`
尝试时
<块引用>brew install --build-from-source opencv
然后收到同样的错误。
也试过了:
> brew uninstall opencv
Error: No available formula or cask with the name "opencv".
答案 0 :(得分:1)
显然,通过自制软件安装 OpenCV 比 brew install opencv
更重要。
您需要确保已安装 XCode 命令行工具以及 ANT。然后你需要运行
brew install --build-from-source opencv
查看 documentation 以了解详细信息。
也可能是自制软件的问题 - 所以更新 brew 并运行医生。
答案 1 :(得分:0)
我找到了通过 Maven 获取 OpenCV 的更简单方法。
添加到 pom.xml:
<dependencies>
<!-- https://mvnrepository.com/artifact/org.openpnp/opencv -->
<dependency>
<groupId>org.openpnp</groupId>
<artifactId>opencv</artifactId>
<version>4.3.0-3</version>
</dependency>
</dependencies>
添加依赖后,需要加载库使用。通常,您会使用以下行:
System.loadLibrary(Core.NATIVE_LIBRARY_NAME);
但是它不适用于这种方法。您需要将其更改为以下几行之一:
nu.pattern.OpenCV.loadShared();
nu.pattern.OpenCV.loadLocally(); // Use in case loadShared() doesn't work
所以测试的最终结果是:
import org.opencv.core.Core;
public class HelloCV {
static {
nu.pattern.OpenCV.loadShared();
// nu.pattern.OpenCV.loadLocally(); // Use in case loadShared() doesn't work
}
public static void main(String[] args) {
System.out.println(Core.VERSION);
System.out.println(Core.VERSION_MAJOR);
System.out.println(Core.VERSION_MINOR);
System.out.println(Core.VERSION_REVISION);
System.out.println(Core.NATIVE_LIBRARY_NAME);
System.out.println(Core.getBuildInformation());
}
}