فهرست منبع

CMake: Detect OpenCV/ARToolKit, build p3vision

For now, p3vision is only built if either OpenCV or
ARToolKit is available. It does contain some generic
webcam access code, so it might be worth building it
when that's available.
Sam Edwards 7 سال پیش
والد
کامیت
9222bc6d31
6فایلهای تغییر یافته به همراه185 افزوده شده و 32 حذف شده
  1. 43 0
      cmake/modules/FindARToolKit.cmake
  2. 79 0
      cmake/modules/FindOpenCV.cmake
  3. 0 12
      dtool/LocalSetup.cmake
  4. 21 20
      dtool/Package.cmake
  5. 5 0
      panda/CMakeLists.txt
  6. 37 0
      panda/src/vision/CMakeLists.txt

+ 43 - 0
cmake/modules/FindARToolKit.cmake

@@ -0,0 +1,43 @@
+# Filename: FindARToolKit.cmake
+# Authors: CFSworks (3 Nov, 2018)
+#
+# Usage:
+#   find_package(ARToolKit [REQUIRED] [QUIET])
+#
+# Once done this will define:
+#   ARTOOLKIT_FOUND       - system has ARToolKit
+#   ARTOOLKIT_INCLUDE_DIR - the include directory containing ARToolKit header files
+#   ARTOOLKIT_LIBRARIES   - the paths to the ARToolKit client libraries
+#
+
+if(NOT ARTOOLKIT_INCLUDE_DIR)
+  find_path(ARTOOLKIT_INCLUDE_DIR "AR/ar.h")
+
+  mark_as_advanced(ARTOOLKIT_INCLUDE_DIR)
+endif()
+
+if(NOT ARTOOLKIT_AR_LIBRARY)
+  find_library(ARTOOLKIT_AR_LIBRARY
+    NAMES "AR" "libAR")
+
+  mark_as_advanced(ARTOOLKIT_AR_LIBRARY)
+endif()
+
+if(NOT ARTOOLKIT_ARMulti_LIBRARY)
+  find_library(ARTOOLKIT_ARMulti_LIBRARY
+    NAMES "ARMulti" "libARMulti")
+
+  mark_as_advanced(ARTOOLKIT_ARMulti_LIBRARY)
+endif()
+
+set(ARTOOLKIT_LIBRARIES)
+if(ARTOOLKIT_AR_LIBRARY)
+  list(APPEND ARTOOLKIT_LIBRARIES "${ARTOOLKIT_AR_LIBRARY}")
+endif()
+if(ARTOOLKIT_ARMulti_LIBRARY)
+  list(APPEND ARTOOLKIT_LIBRARIES "${ARTOOLKIT_ARMulti_LIBRARY}")
+endif()
+
+include(FindPackageHandleStandardArgs)
+find_package_handle_standard_args(ARToolKit DEFAULT_MSG
+  ARTOOLKIT_INCLUDE_DIR ARTOOLKIT_LIBRARIES)

+ 79 - 0
cmake/modules/FindOpenCV.cmake

@@ -0,0 +1,79 @@
+# Filename: FindOpenCV.cmake
+# Authors: CFSworks (3 Nov, 2018)
+#
+# Usage:
+#   find_package(OpenCV [REQUIRED] [QUIET])
+#
+# This supports the following components:
+#   calib3d
+#   contrib
+#   core
+#   features2d
+#   flann
+#   gpu
+#   highgui
+#   imgproc
+#   legacy
+#   ml
+#   nonfree
+#   objdetect
+#   photo
+#   stitching
+#   superres
+#   video
+#   videostab
+#
+# Once done this will define:
+#   OPENCV_FOUND        - system has OpenCV
+#   OpenCV_INCLUDE_DIRS - the include dir(s) containing OpenCV header files
+#   OpenCV_comp_LIBRARY - the path to the OpenCV library for the particular
+#                         component
+#   OpenCV_LIBS         - the paths to the OpenCV libraries for the requested
+#                         component(s)
+#
+
+set(OpenCV_INCLUDE_DIRS)
+if(NOT OpenCV_V1_INCLUDE_DIR)
+  find_path(OpenCV_V1_INCLUDE_DIR
+    NAMES "cv.h"
+    PATH_SUFFIXES "opencv")
+
+  mark_as_advanced(OpenCV_V1_INCLUDE_DIR)
+endif()
+if(OpenCV_V1_INCLUDE_DIR)
+  list(APPEND OpenCV_INCLUDE_DIRS "${OpenCV_V1_INCLUDE_DIR}")
+endif()
+
+if(NOT OpenCV_V2_INCLUDE_DIR)
+  find_path(OpenCV_V2_INCLUDE_DIR "opencv2/core/core.hpp")
+
+  mark_as_advanced(OpenCV_V2_INCLUDE_DIR)
+endif()
+if(OpenCV_V2_INCLUDE_DIR)
+  list(APPEND OpenCV_INCLUDE_DIRS "${OpenCV_V2_INCLUDE_DIR}")
+endif()
+
+set(OpenCV_LIBS)
+foreach(_component calib3d contrib core features2d flann gpu highgui imgproc
+                  legacy ml nonfree objdetect photo stitching superres video
+                  videostab)
+
+  list(FIND OpenCV_FIND_COMPONENTS "${_component}" _index)
+  if(_index GREATER -1 OR _component STREQUAL "core")
+    if(NOT OpenCV_${_component}_LIBRARY)
+      find_library(OpenCV_${_component}_LIBRARY
+        NAMES "opencv_${_component}")
+    endif()
+
+    if(OpenCV_${_component}_LIBRARY)
+      list(APPEND OpenCV_LIBS "${OpenCV_${_component}_LIBRARY}")
+      set(OpenCV_${_component}_FOUND ON)
+    endif()
+  endif()
+  unset(_index)
+endforeach(_component)
+unset(_component)
+
+include(FindPackageHandleStandardArgs)
+find_package_handle_standard_args(OpenCV HANDLE_COMPONENTS
+  REQUIRED_VARS OpenCV_INCLUDE_DIRS OpenCV_LIBS)

+ 0 - 12
dtool/LocalSetup.cmake

@@ -161,12 +161,6 @@ else()
   message("- Not building Tinydisplay")
 endif()
 
-if(HAVE_OPENCV)
-  message("+ OpenCV")
-else()
-  message("- Did not find OpenCV")
-endif()
-
 if(HAVE_AWESOMIUM)
   message("+ AWESOMIUM")
 else()
@@ -191,12 +185,6 @@ else()
   message("- Did not find Assimp")
 endif()
 
-if(HAVE_ARTOOLKIT)
-  message("+ ARToolKit")
-else()
-  message("- Did not find ARToolKit")
-endif()
-
 if(HAVE_ROCKET)
   if(HAVE_ROCKET_PYTHON)
     message("+ libRocket with Python bindings")

+ 21 - 20
dtool/Package.cmake

@@ -463,21 +463,30 @@ package_option(DX9
 
 config_package(DX9 "Direct3D 9.x")
 
-########
-# TODO #
-########
+#
+# ------------ Vision tools ------------
+#
+
+# OpenCV
+find_package(OpenCV QUIET COMPONENTS core highgui)
+
+package_option(OPENCV
+  "Enable support for OpenCV.  This will be built into the 'vision' package."
+  FOUND_AS OpenCV)
 
-# Find and configure OpenCV
-#find_package(OpenCV)
-#config_package(OPENCV COMMENT "OpenCV")
+config_package(OPENCV "OpenCV")
 
-# Find and configure FFMPEG
-#find_package(FFMPEG)
-#config_package(FFMPEG)
+# ARToolKit
+find_package(ARToolKit QUIET)
 
-# Find and configure ODE
-#find_package(ODE)
-#config_package(ODE)
+package_option(ARTOOLKIT
+  "Enable support for ARToolKit.  This will be built into the 'vision' package.")
+
+config_package(ARTOOLKIT "ARToolKit")
+
+########
+# TODO #
+########
 
 # Find and configure Awesomium
 #find_package(Awesomium)
@@ -505,10 +514,6 @@ config_package(DX9 "Direct3D 9.x")
 #find_package(Assimp)
 #config_package(ASSIMP COMMENT "Assimp")
 
-# Find and configure ARToolKit
-#find_package(ARToolKit)
-#config_package(ARTOOLKIT COMMENT "ARToolKit")
-
 # Find and configure libRocket
 #find_package(Rocket)
 #config_package(ROCKET COMMENT "libRocket")
@@ -531,10 +536,6 @@ config_package(DX9 "Direct3D 9.x")
 # unset(USE_ROCKET_PYTHON CACHE)
 #endif()
 
-# Find and configure Bullet
-#find_package(Bullet)
-#config_package(BULLET COMMENT "Bullet Physics")
-
 # Find and configure Vorbis
 #find_package(Vorbis)
 #config_package(VORBIS COMMENT "Vorbis Ogg decoder")

+ 5 - 0
panda/CMakeLists.txt

@@ -54,6 +54,7 @@ add_subdirectory(src/recorder)
 add_subdirectory(src/testbed)
 add_subdirectory(src/text)
 add_subdirectory(src/tform)
+add_subdirectory(src/vision)
 add_subdirectory(src/vrpn)
 add_subdirectory(src/wgldisplay)
 add_subdirectory(src/windisplay)
@@ -110,6 +111,10 @@ if(HAVE_PYTHON)
     add_python_module(ode p3ode IMPORT panda3d.core)
   endif()
 
+  if(HAVE_OPENCV OR HAVE_ARTOOLKIT)
+    add_python_module(vision p3vision IMPORT panda3d.core)
+  endif()
+
   if(HAVE_VRPN)
     add_python_module(vrpn p3vrpn IMPORT panda3d.core)
   endif()

+ 37 - 0
panda/src/vision/CMakeLists.txt

@@ -0,0 +1,37 @@
+if(NOT HAVE_OPENCV AND NOT HAVE_ARTOOLKIT)
+  return()
+endif()
+
+set(P3VISION_HEADERS
+  arToolKit.h arToolKit.I
+  config_vision.h
+  openCVTexture.h openCVTexture.I
+  webcamVideoCursorOpenCV.h
+  webcamVideoCursorV4L.h
+  webcamVideo.h webcamVideo.I
+  webcamVideoOpenCV.h
+  webcamVideoV4L.h
+)
+
+set(P3VISION_SOURCES
+  arToolKit.cxx
+  config_vision.cxx
+  openCVTexture.cxx
+  webcamVideoCursorOpenCV.cxx
+  webcamVideoCursorV4L.cxx
+  webcamVideo.cxx
+  webcamVideoDS.cxx
+  webcamVideoOpenCV.cxx
+  webcamVideoV4L.cxx
+)
+
+composite_sources(p3vision P3VISION_SOURCES)
+add_library(p3vision ${P3VISION_HEADERS} ${P3VISION_SOURCES})
+set_target_properties(p3vision PROPERTIES DEFINE_SYMBOL BUILDING_VISION)
+target_link_libraries(p3vision panda
+  PKG::OPENCV PKG::ARTOOLKIT)
+set_target_properties(p3vision PROPERTIES CXX_EXCEPTIONS ON)
+target_interrogate(p3vision ALL)
+
+install(TARGETS p3vision DESTINATION lib RUNTIME DESTINATION bin)
+install(FILES ${P3VISION_HEADERS} DESTINATION include/panda3d)