python - 与 Python 和 OpenCv 链接

标签 python linux opencv cmake

我正在使用 OpenCv 库在 python 中编写程序。我的项目文件夹是 Foo,里面有一个图像和可执行文件。我的 CmakeLists.txt 如下所示:

cmake_minimum_required(VERSION 2.8)
project(Foo)
find_package( OpenCV REQUIRED )
add_executable(Foo Im.py)
target_link_libraries(Foo ${OpenCV_LIBS} ${python2.7} )

当我执行 cmake . 时,出现以下错误:

-- Configuring done
CMake Error: CMake can not determine linker language for target: Foo
CMake Error: Cannot determine link language for target "Foo".
-- Generating done
-- Build files have been written to: /home/user_name/OpenCv/Foo

我正在使用 python 2.7 和 linux 16.04。

最佳答案

CMake 用于编译源代码(例如 C++ 或 C 代码)。

OpenCV 库可以与 C、C++ 或 Python 一起使用。 在这里,我猜想您希望将 Python 与 OpenCV 库一起使用,因此您不需要 CMake,因为 Python 是一种解释型语言,而不是像 C++ 这样的编译型语言。

您可以使用以下命令执行您的脚本:

python3 path/to/your/script.py

或者如果您使用该语言的早期版本(Python 2):

python2 path/to/your/script.py

关于python - 与 Python 和 OpenCv 链接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45568762/

相关文章:

linux - mod_rewrite REQUEST_URI 混淆

opencv - 如何使用opencv从顶 View 识别斑马线?

c++ - OpenCV HOGDescriptor 错误

android - 是否可以在 kubuntu12.04 (xubuntu) 中构建 AOSP 项目 (Gingerbread)?

c - 在基于arm32镜像的容器中,当目录为空时,readdir返回EOVERFLOW

c - 如何将网络摄像头提供给 GTK 窗口?

python - 在 gunicorn 中使用额外的命令行参数

python - psycopg2 查询返回 None

Python:同时复制列表和删除元素

python - 如何在 python 的正则表达式中指定一系列 unicode 字符?