如何使用 OpenMP 编译 OpenCV [英] How to compile OpenCV with OpenMP

查看:147
本文介绍了如何使用 OpenMP 编译 OpenCV的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这篇 SOF 帖子中的用户建议使用 WITH_OPENMP 构建 OpenCV代码> 标志以启用(某些)多核支持.我曾尝试使用 OpenMP 构建 OpenCV-2.4.10,但我无法在 Python 中导入 cv2.

A user in this SOF post suggests building OpenCV with a WITH_OPENMP flag to enable (some) multi-core support. I have tried building OpenCV-2.4.10 with OpenMP but I am unable to then import cv2 in Python.

注意:我能够在 Python 中构建和使用 OpenCV-2.4.10.问题是使用 WITH_OPENMP 标志构建.

Note: I am able to build and use OpenCV-2.4.10 in Python. The problem is building with the WITH_OPENMP flag.

我正在替换 opencv-2.4.10/cmake/OpenCVFindLibsPerf.cmake 中的第 49-58 行,正如 这篇 博客文章,内容如下:

I am replacing lines 49-58 in opencv-2.4.10/cmake/OpenCVFindLibsPerf.cmake, as suggested in this blog post, with the following:

# --- OpenMP ---
if(NOT HAVE_TBB AND NOT HAVE_CSTRIPES)
  include (FindOpenMP)      # --- since cmake version 2.6.3 
   if (OPENMP_FOUND)
      set (HAVE_OPENMP TRUE)
      set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS}")
      set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${OpenMP_C_FLAGS}")
   else()
      set ( HAVE_OPENMP FALSE)
   endif()
else()
set(HAVE_OPENMP 0)
endif()

然后在构建前执行这个命令:

And then executing this command before building:

    cmake -D WITH_OPENMP=ON -D CMAKE_BUILD_TYPE=RELEASE \
    -D CMAKE_INSTALL_PREFIX=/usr/local -D BUILD_NEW_PYTHON_SUPPORT=ON \
    -D INSTALL_C_EXAMPLES=ON -D INSTALL_PYTHON_EXAMPLES=ON  \
    -D BUILD_EXAMPLES=ON ..

WITH_OPENMP=ON 是在这里使用的正确标志吗?问题是否在于使用 OpenCV-2.4.10?(我注意到我引用的博客文章是关于 OpenCV-2.4.6.1)

Is WITH_OPENMP=ON the correct flag to use here? Does the problem lie with using OpenCV-2.4.10? (I notice the blog post I referenced is with OpenCV-2.4.6.1)

推荐答案

我有一个类似的问题.带有 -D WITH_OPENMP=ON 的 cmake 对我来说效果很好.

I had a similiar question. cmake with -D WITH_OPENMP=ON worked fine for me.

这篇关于如何使用 OpenMP 编译 OpenCV的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆