3

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)

Community
  • 1
  • 1
NRKirby
  • 1,584
  • 4
  • 21
  • 38
  • Based on the information you provided I don't think it's a problem related to OpenMP. Did you install your build of OpenCV correctly so that Python can find it? – nils Apr 07 '15 at 15:35
  • Yes, I should have been more explicit. I can build & use OpenCV no problem it is just when I try building with `WITH_OPENMP=ON` flag – NRKirby Apr 07 '15 at 16:04
  • So the problem is not building OpenCV with openmp, but importing it in Python if you build it with openmp. If you build OpenCV without openmp, that you can import it in Python without problems. Correct? – Antonio Apr 07 '15 at 21:46
  • Yes, I cannot import Python when I build OpenCV with OpenMP but I would say that the problem then lies with building with OpenMP – NRKirby Apr 08 '15 at 06:55

1 Answers1

11

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