问题
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.
Note: I am able to build and use OpenCV-2.4.10 in Python. The problem is building with the WITH_OPENMP
flag.
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 ..
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)
回答1:
I had a similiar question. cmake with -D WITH_OPENMP=ON worked fine for me.
来源:https://stackoverflow.com/questions/29494503/how-to-compile-opencv-with-openmp