0

I'd like to use OpenCV's interactive calibration tool with GigE camera but I'm running into compile errors:

/usr/bin/ld: /home/move/Downloads/PV_API/lib-pc/x64/4.7/libPvAPI.a(PvTimer.o): in function `cPvTimer::Arm(unsigned int)':
PvTimer.cpp:(.text+0x3bc): undefined reference to `timer_settime'
/usr/bin/ld: /home/move/Downloads/PV_API/lib-pc/x64/4.7/libPvAPI.a(PvTimer.o): in function `cPvTimer::Disarm()':
PvTimer.cpp:(.text+0x429): undefined reference to `timer_settime'
/usr/bin/ld: /home/move/Downloads/PV_API/lib-pc/x64/4.7/libPvAPI.a(PvTimer.o): in function `cPvTimer::~cPvTimer()':
PvTimer.cpp:(.text+0x69c): undefined reference to `timer_delete'
/usr/bin/ld: /home/move/Downloads/PV_API/lib-pc/x64/4.7/libPvAPI.a(PvTimer.o): in function `cPvTimer::cPvTimer(unsigned int)':
PvTimer.cpp:(.text+0x8ad): undefined reference to `timer_create'
/usr/bin/ld: /home/move/Downloads/PV_API/lib-pc/x64/4.7/libPvAPI.a(PvTimer.o): in function `cPvTimer::cPvTimer()':
PvTimer.cpp:(.text+0xacd): undefined reference to `timer_create'
collect2: error: ld returned 1 exit status
make[2]: *** [modules/videoio/CMakeFiles/opencv_videoio.dir/build.make:293: lib/libopencv_videoio.so.4.6.0] Error 1
make[1]: *** [CMakeFiles/Makefile2:1898: modules/videoio/CMakeFiles/opencv_videoio.dir/all] Error 2
make: *** [Makefile:163: all] Error 2

I am aware that PV_API is deprecated. I downloaded the legacy PV_API from the Allied Vision website. Due to limited time I'd like to avoid interfacing with the camera's SDK directly if I can. (I did found these relevant answers [1], [2] that recommend not doing what I'm trying to do).

My hunch is that if I can pass -lrt to opencv_videoio's library I might get away with it .

I did try this using CMAKE_CXX_FLAGS and add_link_options(), but no joy.

For reference here's the diff of my attempt:

diff --git a/modules/videoio/CMakeLists.txt b/modules/videoio/CMakeLists.txt
index 377029f45f..dffdfbe7c8 100644
--- a/modules/videoio/CMakeLists.txt
+++ b/modules/videoio/CMakeLists.txt
@@ -260,6 +260,9 @@ if(VIDEOIO_ENABLE_PLUGINS)
   ocv_target_compile_definitions(${the_module} PRIVATE ENABLE_PLUGINS)
 endif()

+set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -lrt")
+# add_link_options("-lrt")
+
 ocv_target_link_libraries(${the_module} LINK_PRIVATE ${tgts})

 # copy FFmpeg dll to the output folder
diff --git a/modules/videoio/cmake/detect_pvapi.cmake b/modules/videoio/cmake/detect_pvapi.cmake
index f2c6d4bcea..038db96c0e 100644
--- a/modules/videoio/cmake/detect_pvapi.cmake
+++ b/modules/videoio/cmake/detect_pvapi.cmake
@@ -17,5 +17,7 @@ if(NOT HAVE_PVAPI)
 endif()

 if(HAVE_PVAPI)
+  # add_link_options("-lrt")
+  set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -lrt")
   ocv_add_external_target(pvapi "${PVAPI_INCLUDE}" "${PVAPI_LIBRARY}" "HAVE_PVAPI")
 endif()

Maybe I'm not using the CMake magic or I'm doing it in the wrong place?

Has anyone ran into this recently? What's the simplest way to get OpenCV apps to build with GigE support on Ubuntu?

genpfault
  • 51,148
  • 11
  • 85
  • 139
George Profenza
  • 50,687
  • 19
  • 144
  • 218
  • I'm don't know OpenCV's build system, but from the code you posted, there's already a line `ocv_target_link_libraries(${the_module} LINK_PRIVATE ${tgts})` - maybe change that to `ocv_target_link_libraries(${the_module} LINK_PRIVATE ${tgts} -lrt)`? (Or just `rt` instead of `-lrt` in that line, depending on how their macro works.) – chris_se Mar 15 '23 at 16:45
  • @chris_se Thanks for that Chris. Just tried it and unfortunately getting the same error – George Profenza Mar 15 '23 at 16:54
  • 1
    Another guess: change `ocv_add_external_target(pvapi "${PVAPI_INCLUDE}" "${PVAPI_LIBRARY}" "HAVE_PVAPI")` to `ocv_add_external_target(pvapi "${PVAPI_INCLUDE}" "${PVAPI_LIBRARY};-lrt" "HAVE_PVAPI")` (or instead of the `;` in there use a space if that doesn't work) – chris_se Mar 15 '23 at 17:01
  • 2
    Frankly, you'd probably be better off just using PvAPI directly. From what I recall, it's not really that complex, there are decent code examples provided, and the documentation is quite good too. Turning the result into a `cv::Mat` is trivial. You'd likely be already capturing frames instead of mucking about with CMake now. Eventually you'd want to use it directly anyway, since the OpenCV wrapper is rather limited. | It might be deprecated, but if it supports your camera, who cares. I've had it running in production 24/7 for over 10 years just fine. No need to fix what ain't broken. – Dan Mašek Mar 15 '23 at 23:57
  • 1
    @DanMašek I see your point. I'm trying to get away with it the lazy way (and may end up doing more work ironically). – George Profenza Mar 16 '23 at 09:01
  • @chris_se if you could post `ocv_add_external_target(pvapi "${PVAPI_INCLUDE}" "${PVAPI_LIBRARY};-lrt" "HAVE_PVAPI")` in an answer I'd be happy to accept that. I've compiled opencv with PV_API support now. (I cam getting "Unable to open video source" and I did update [calibPipeline.cpp](https://github.com/opencv/opencv/blob/4.x/apps/interactive-calibration/calibPipeline.cpp#L37) to use `mCapture.open(mCaptureParams.camID + cv::CAP_PVAPI)` but it didn't work when passing `0` (or the IP of the camera). This may be a separate question) – George Profenza Mar 16 '23 at 09:17

1 Answers1

1

From looking at the build system snippets you posted here, change

ocv_add_external_target(pvapi "${PVAPI_INCLUDE}" "${PVAPI_LIBRARY}" "HAVE_PVAPI")

to

ocv_add_external_target(pvapi "${PVAPI_INCLUDE}" "${PVAPI_LIBRARY};-lrt" "HAVE_PVAPI")

to include the -lrt library when linking against that external target within the OpenCV CMake build system. (A proper "fix" would probably automatically add that on Linux/glibc systems by means of some autodetection logic, but since this is deprecated anyway...)

chris_se
  • 1,006
  • 1
  • 7