Skip to content

Commit

Permalink
ClientKit: Remove dependency on OpenCV from Imaging.
Browse files Browse the repository at this point in the history
  • Loading branch information
CrossVR committed Sep 12, 2015
1 parent e9bf4b5 commit ff960be
Show file tree
Hide file tree
Showing 10 changed files with 66 additions and 83 deletions.
96 changes: 48 additions & 48 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -154,21 +154,54 @@ endif()

if(BUILD_SERVER)
find_package(libfunctionality REQUIRED)
endif()
find_package(OpenCV REQUIRED)
if(WIN32)
set(OSVR_COPY_OPENCV ON)
else()
set(OSVR_COPY_OPENCV OFF)
endif()
if(ANDROID)
include(OpenCVAndroid)
endif()
# Include dir specifically required by 3.0 and up, but missing from config.
if(NOT OpenCV_VERSION VERSION_LESS 3.0.0)
list(REMOVE_DUPLICATES OpenCV_INCLUDE_DIRS)
set_target_properties(opencv_core PROPERTIES
INTERFACE_INCLUDE_DIRECTORIES "${OpenCV_INCLUDE_DIRS}")
find_package(OpenCV REQUIRED)
if(WIN32)
set(OSVR_COPY_OPENCV ON)
else()
set(OSVR_COPY_OPENCV OFF)
endif()
if(ANDROID)
include(OpenCVAndroid)
endif()
# Include dir specifically required by 3.0 and up, but missing from config.
if(NOT OpenCV_VERSION VERSION_LESS 3.0.0)
list(REMOVE_DUPLICATES OpenCV_INCLUDE_DIRS)
set_target_properties(opencv_core PROPERTIES
INTERFACE_INCLUDE_DIRECTORIES "${OpenCV_INCLUDE_DIRS}")
endif()

set(OPENCV_MODULES_USED)
if(NOT OpenCV_VERSION_MAJOR LESS 3)
list(APPEND OPENCV_MODULES_USED opencv_hal)
endif()
list(APPEND OPENCV_MODULES_USED opencv_core)

set(OPENCV_CORE_MODULES ${OPENCV_MODULES_USED})

# Extra OpenCV components.
# We set this up here so that if we need to copy DLLs, we can do it in the main
# library builds where it's easier to get the right directory on Windows in a build tree.
if(BUILD_OPENCV_CAMERA_PLUGIN)
if(OpenCV_VERSION_MAJOR LESS 3)
set(OPENCV_CAMERA_EXTRA_LIBS opencv_highgui)
else()
set(OPENCV_CAMERA_EXTRA_LIBS opencv_videoio)
endif()
list(APPEND OPENCV_MODULES_USED ${OPENCV_CAMERA_EXTRA_LIBS})
endif()

if(BUILD_VIDEOTRACKER_PLUGIN)
set(VIDEOTRACKER_EXTRA_LIBS
opencv_imgproc
opencv_features2d
opencv_calib3d
opencv_highgui
opencv_imgproc
opencv_flann)
list(APPEND OPENCV_MODULES_USED ${VIDEOTRACKER_EXTRA_LIBS})
endif()

list(REMOVE_DUPLICATES OPENCV_MODULES_USED)
endif()

find_package(Threads REQUIRED)
Expand All @@ -181,39 +214,6 @@ endif()

include(CompilerFeatures)

set(OPENCV_MODULES_USED)
if(NOT OpenCV_VERSION_MAJOR LESS 3)
list(APPEND OPENCV_MODULES_USED opencv_hal)
endif()
list(APPEND OPENCV_MODULES_USED opencv_core)

set(OPENCV_CORE_MODULES ${OPENCV_MODULES_USED})

# Extra OpenCV components.
# We set this up here so that if we need to copy DLLs, we can do it in the main
# library builds where it's easier to get the right directory on Windows in a build tree.
if(BUILD_OPENCV_CAMERA_PLUGIN)
if(OpenCV_VERSION_MAJOR LESS 3)
set(OPENCV_CAMERA_EXTRA_LIBS opencv_highgui)
else()
set(OPENCV_CAMERA_EXTRA_LIBS opencv_videoio)
endif()
list(APPEND OPENCV_MODULES_USED ${OPENCV_CAMERA_EXTRA_LIBS})
endif()

if(BUILD_VIDEOTRACKER_PLUGIN)
set(VIDEOTRACKER_EXTRA_LIBS
opencv_imgproc
opencv_features2d
opencv_calib3d
opencv_highgui
opencv_imgproc
opencv_flann)
list(APPEND OPENCV_MODULES_USED ${VIDEOTRACKER_EXTRA_LIBS})
endif()

list(REMOVE_DUPLICATES OPENCV_MODULES_USED)

###
# Figure out what Boost compiled libraries we need.
###
Expand Down
8 changes: 4 additions & 4 deletions examples/clients/Imaging.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ bool gotSomething = false;

void imagingCallback(void *userdata,
osvr::util::time::TimeValue const &timestamp,
osvr::clientkit::ImagingReportOpenCV report) {
osvr::clientkit::ImagingReport report) {
if (report.frame.empty()) {
std::cout << "Error, frame empty!" << std::endl;
return;
Expand All @@ -57,8 +57,8 @@ void imagingCallback(void *userdata,
}

cv::imshow(windowNameAndInstructions, report.frame);
osvr::clientkit::ImagingReportOpenCV &lastReport =
*static_cast<osvr::clientkit::ImagingReportOpenCV *>(userdata);
osvr::clientkit::ImagingReport &lastReport =
*static_cast<osvr::clientkit::ImagingReport *>(userdata);
lastReport = report;
}
int main() {
Expand All @@ -68,7 +68,7 @@ int main() {

/// We keep a copy of the last report to avoid de-allocating the image
/// buffer until we have a new report.
osvr::clientkit::ImagingReportOpenCV lastReport;
osvr::clientkit::ImagingReport lastReport;

// Register the imaging callback.
osvr::clientkit::registerImagingCallback(camera, &imagingCallback,
Expand Down
18 changes: 6 additions & 12 deletions inc/osvr/ClientKit/Imaging.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,11 @@
#include <osvr/ClientKit/ImagingC.h>
#include <osvr/Util/ImagingReportTypesC.h>
#include <osvr/Util/TimeValue.h>
#include <osvr/Util/OpenCVTypeDispatch.h>
#include <osvr/Util/Deletable.h>

// Library/third-party includes
#include <boost/shared_ptr.hpp>
#include <boost/noncopyable.hpp>
#include <opencv2/core/core.hpp>

// Standard includes
// - none
Expand All @@ -49,7 +47,7 @@ namespace clientkit {
/// @{
/// @brief Register a callback to receive each new full frame of imaging
/// data.
void registerImagingCallback(Interface &iface, ImagingCallbackOpenCV cb,
void registerImagingCallback(Interface &iface, ImagingCallback cb,
void *userdata);
#ifndef OSVR_DOXYGEN_EXTERNAL
/// @brief Implementation details
Expand All @@ -65,7 +63,7 @@ namespace clientkit {
/// @brief Constructor - private so that only the factory
/// (registration) function can create it.
ImagingCallbackRegistration(osvr::clientkit::Interface iface,
ImagingCallbackOpenCV cb,
ImagingCallback cb,
void *userdata)
: m_cb(cb), m_userdata(userdata),
m_ctx(iface.getContext().get()) {
Expand Down Expand Up @@ -94,29 +92,25 @@ namespace clientkit {
const struct OSVR_ImagingReport *report) {
ImagingCallbackRegistration *self =
static_cast<ImagingCallbackRegistration *>(userdata);
ImagingReportOpenCV newReport;
ImagingReport newReport;
newReport.sensor = report->sensor;
newReport.buffer.reset(report->state.data,
ImagingDeleter(self->m_ctx));
newReport.frame = cv::Mat(
report->state.metadata.height, report->state.metadata.width,
util::computeOpenCVMatType(report->state.metadata),
newReport.buffer.get());
self->m_cb(self->m_userdata, *timestamp, newReport);
}

ImagingCallbackOpenCV m_cb;
ImagingCallback m_cb;
void *m_userdata;
OSVR_ClientContext m_ctx;
friend void osvr::clientkit::registerImagingCallback(
Interface &iface, ImagingCallbackOpenCV cb, void *userdata);
Interface &iface, ImagingCallback cb, void *userdata);
};
} // namespace detail

#endif // OSVR_DOXYGEN_EXTERNAL

inline void registerImagingCallback(Interface &iface,
ImagingCallbackOpenCV cb,
ImagingCallback cb,
void *userdata) {
util::boost_util::DeletablePtr ptr(
new detail::ImagingCallbackRegistration(iface, cb, userdata));
Expand Down
11 changes: 3 additions & 8 deletions inc/osvr/ClientKit/Imaging_decl.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@

// Library/third-party includes
#include <boost/shared_ptr.hpp>
#include <opencv2/core/core.hpp>

// Standard includes
// - none
Expand All @@ -50,23 +49,19 @@ namespace clientkit {
/// @brief The user-friendly imaging report. Note that passing this around
/// by value is OK (doesn't copy the image), and the easiest way to ensure
/// that the image buffer doesn't get freed before you're done using it.
struct ImagingReportOpenCV {
struct ImagingReport {
/// @brief The device sensor number this frame came from.
OSVR_ChannelCount sensor;

/// @brief An OpenCV Mat header for accessing the image data in the
/// buffer. Does not store the data internally (to reduce copies)!
cv::Mat frame;

/// @brief A shared pointer with custom deleter that owns the underlying
/// image data buffer for the frame.
ImageBufferPtr buffer;
};

/// @brief The user-friendly imaging callback type
typedef void (*ImagingCallbackOpenCV)(
typedef void (*ImagingCallback)(
void *userdata, util::time::TimeValue const &timestamp,
ImagingReportOpenCV report);
ImagingReport report);

/// @}
} // end namespace clientkit
Expand Down
2 changes: 1 addition & 1 deletion inc/osvr/PluginKit/ImagingInterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@
// Internal Includes
#include <osvr/PluginKit/DeviceInterface.h>
#include <osvr/PluginKit/ImagingInterfaceC.h>
#include <osvr/PluginKit/OpenCVTypeDispatch.h>
#include <osvr/Util/ChannelCountC.h>
#include <osvr/Util/OpenCVTypeDispatch.h>

// Library/third-party includes
#include <opencv2/core/core_c.h>
Expand Down
File renamed without changes.
1 change: 0 additions & 1 deletion src/osvr/Common/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,6 @@ target_link_libraries(${LIBNAME_FULL}
osvrUtilCpp
PRIVATE
jsoncpp_lib
opencv_core
vendored-vrpn
eigen-headers
osvr_cxx11_flags
Expand Down
8 changes: 1 addition & 7 deletions src/osvr/Common/ImagingComponent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,9 @@
#include <osvr/Common/BaseDevice.h>
#include <osvr/Common/Serialization.h>
#include <osvr/Common/Buffer.h>
#include <osvr/Util/OpenCVTypeDispatch.h>
#include <osvr/Util/Flag.h>
#include <osvr/Util/Verbosity.h>

// Library/third-party includes
#include <opencv2/core/core.hpp>

// Standard includes
#include <sstream>
#include <utility>
Expand Down Expand Up @@ -71,9 +67,7 @@ namespace common {

template <typename T>
void allocateBuffer(T &, size_t bytes, std::true_type const &) {
m_imgBuf.reset(reinterpret_cast<OSVR_ImageBufferElement *>(
cv::fastMalloc(bytes)),
&cv::fastFree);
m_imgBuf.reset(reinterpret_cast<OSVR_ImageBufferElement *>(malloc(bytes)));
}

template <typename T>
Expand Down
4 changes: 3 additions & 1 deletion src/osvr/PluginKit/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ set(API
"${HEADER_LOCATION}/PluginKitC.h"
"${HEADER_LOCATION}/PluginRegistration.h"
"${HEADER_LOCATION}/PluginRegistrationC.h"
"${HEADER_LOCATION}/TrackerInterfaceC.h")
"${HEADER_LOCATION}/TrackerInterfaceC.h"
"${HEADER_LOCATION}/OpenCVTypeDispatch.h")

set(SOURCE
AnalogInterfaceC.cpp
Expand Down Expand Up @@ -51,6 +52,7 @@ target_link_libraries(${LIBNAME_FULL}
osvrConnection
osvrUtilCpp
osvrCommon
opencv_core
vendored-vrpn
boost_thread)

Expand Down
1 change: 0 additions & 1 deletion src/osvr/Util/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ set(API
"${HEADER_LOCATION}/MacroToolsC.h"
"${HEADER_LOCATION}/Microsleep.h"
"${HEADER_LOCATION}/NumberTypeManipulation.h"
"${HEADER_LOCATION}/OpenCVTypeDispatch.h"
"${HEADER_LOCATION}/PluginCallbackTypesC.h"
"${HEADER_LOCATION}/PluginRegContextC.h"
"${HEADER_LOCATION}/PointerWrapper.h"
Expand Down

0 comments on commit ff960be

Please sign in to comment.