• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1if get_option('opencv').disabled()
2  opencv_dep = disabler()
3  subdir_done()
4endif
5
6gstopencv_sources = [
7  'gstcvdilate.cpp',
8  'gstcvdilateerode.cpp',
9  'gstcvequalizehist.cpp',
10  'gstcverode.cpp',
11  'gstcvlaplace.cpp',
12  'gstcvsmooth.cpp',
13  'gstcvsobel.cpp',
14  'gstdisparity.cpp',
15  'gstedgedetect.cpp',
16  'gstfaceblur.cpp',
17  'gstfacedetect.cpp',
18  'gstgrabcut.cpp',
19  'gsthanddetect.cpp',
20  'gstmotioncells.cpp',
21  'gstopencv.cpp',
22  'gstretinex.cpp',
23  'gstsegmentation.cpp',
24  'gstskindetect.cpp',
25  'gsttemplatematch.cpp',
26  'gsttextoverlay.cpp',
27  'MotionCells.cpp',
28  'motioncells_wrapper.cpp',
29  'gstdewarp.cpp',
30  'camerautils.cpp',
31  'cameraevent.cpp',
32  'gstcameracalibrate.cpp',
33  'gstcameraundistort.cpp',
34  'gstcvtracker.cpp'
35]
36
37libopencv_headers = [
38  'opencv2/bgsegm.hpp',
39  'opencv2/calib3d.hpp',
40  'opencv2/core.hpp',
41  'opencv2/imgproc.hpp',
42  'opencv2/objdetect.hpp',
43  'opencv2/opencv.hpp',
44  'opencv2/video.hpp',
45  'opencv2/tracking.hpp',
46]
47
48libopencv4_headers = [
49  'opencv4/opencv2/bgsegm.hpp',
50  'opencv4/opencv2/calib3d.hpp',
51  'opencv4/opencv2/core.hpp',
52  'opencv4/opencv2/imgproc.hpp',
53  'opencv4/opencv2/objdetect.hpp',
54  'opencv4/opencv2/opencv.hpp',
55  'opencv4/opencv2/video.hpp',
56  'opencv4/opencv2/tracking.hpp',
57]
58
59gstopencv_cargs = ['-DGST_HAAR_CASCADES_DIR="@0@"']
60
61opencv_dep = dependency('opencv', version : ['>= 3.0.0', '< 3.5.0'], required : false)
62opencv_found = opencv_dep.found()
63
64if opencv_found
65  foreach h : libopencv_headers
66    if not cxx.has_header(h)
67      message('Needed header "' + h + '" not found')
68      opencv_found = false
69    endif
70  endforeach
71endif
72
73if not opencv_found
74  opencv_dep = dependency('opencv4', version : ['>= 4.0.0', '< 4.7.0'], required : false)
75  opencv_found = opencv_dep.found()
76  if opencv_found
77    foreach h : libopencv4_headers
78      if not cxx.has_header(h)
79        message('Needed header "' + h + '" not found')
80        opencv_found = false
81      endif
82    endforeach
83  endif
84endif
85
86if opencv_found
87  opencv_prefix = opencv_dep.get_variable('prefix')
88  gstopencv_cargs += ['-DOPENCV_PREFIX="' + opencv_prefix + '"']
89
90  # Check the data dir used by opencv for its xml data files
91  # Use prefix from pkg-config to be compatible with cross-compilation
92  r = run_command('test', '-d', opencv_prefix + '/share/opencv', check: false)
93  if r.returncode() == 0
94    gstopencv_cargs += '-DOPENCV_PATH_NAME="opencv"'
95  else
96    r = run_command('test', '-d', opencv_prefix + '/share/OpenCV', check: false)
97    if r.returncode() == 0
98      gstopencv_cargs += '-DOPENCV_PATH_NAME="OpenCV"'
99    else
100      r = run_command('test', '-d', opencv_prefix + '/share/opencv4', check: false)
101      if r.returncode() == 0
102        gstopencv_cargs += '-DOPENCV_PATH_NAME="opencv4"'
103      else
104        message('Unable to detect OpenCV data directory')
105        opencv_found = false
106      endif
107    endif
108  endif
109endif
110
111if opencv_found
112  # opencv4 seems to ship with .pc file that references non-existent include dir
113  # (/usr/include/opencv4/opencv instead of /usr/include/opencv4/opencv2)
114  # clang 10 complains about the following header in opencv4
115  # /usr/include/opencv4/opencv2/flann/logger.h:83:36: error: format string is not a string literal [-Werror,-Wformat-nonliteral]
116  gstopencv_cargs += cxx.get_supported_arguments(['-Wno-missing-include-dirs', '-Wno-format-nonliteral'])
117
118  gstopencv = library('gstopencv',
119    gstopencv_sources,
120    cpp_args : gst_plugins_bad_args + gstopencv_cargs + [ '-DGST_USE_UNSTABLE_API' ],
121    link_args : [noseh_link_args, '-lopencv_tracking'],
122    include_directories : [configinc, libsinc],
123    dependencies : [gstbase_dep, gstvideo_dep, opencv_dep, gstopencv_dep],
124    install : true,
125    install_dir : plugins_install_dir,
126  )
127  pkgconfig.generate(gstopencv, install_dir : plugins_pkgconfig_install_dir)
128  plugins += [gstopencv]
129elif get_option('opencv').enabled()
130  error('OpenCV support enabled but required dependencies were not found.')
131endif
132