Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OpenCV 3.1 + MingW build fix #217

Merged
merged 5 commits into from
Mar 11, 2016
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions contrib/build_scripts/msvc/build_msvc_common.bat
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ IF %ERRORLEVEL% NEQ 0 (
REM Clone OpenCV
IF NOT EXIST %OPENCV_DIR% (
cd %PSMOVE_API_EXTERNAL_DIR%
git clone --depth 1 --branch 2.4.11 git://github.com/Itseez/opencv.git
git clone --depth 1 --branch 3.1.0 git://github.com/Itseez/opencv.git
) ELSE (
echo.
echo OpenCV dir already exists; assuming it has been cloned already
Expand All @@ -128,14 +128,14 @@ IF NOT EXIST build mkdir build
cd build

IF "%MSVC_VERSION%"=="2015" (
cmake .. -G "Visual Studio 14 Win64" -DBUILD_SHARED_LIBS=0 -DBUILD_WITH_STATIC_CRT=OFF -DBUILD_PERF_TESTS=OFF -DBUILD_TESTS=OFF -DBUILD_DOCS=OFF -DBUILD_opencv_apps=OFF -DBUILD_opencv_flann=ON -DBUILD_opencv_features2d=ON -DBUILD_opencv_objdetect=OFF -DBUILD_opencv_photo=OFF -DBUILD_opencv_ts=OFF -DBUILD_opencv_ml=OFF -DBUILD_opencv_video=OFF -DBUILD_opencv_java=OFF -DWITH_OPENEXR=OFF -DWITH_FFMPEG=OFF -DWITH_JASPER=OFF -DWITH_TIFF=OFF
cmake .. -G "Visual Studio 14 Win64" -DBUILD_SHARED_LIBS=0 -DBUILD_WITH_STATIC_CRT=OFF -DBUILD_PERF_TESTS=OFF -DBUILD_TESTS=OFF -DBUILD_DOCS=OFF -DBUILD_opencv_apps=OFF -DBUILD_opencv_flann=ON -DBUILD_opencv_features2d=ON -DBUILD_opencv_objdetect=OFF -DBUILD_opencv_photo=OFF -DBUILD_opencv_ts=OFF -DBUILD_opencv_ml=ON -DBUILD_opencv_video=OFF -DBUILD_opencv_java=OFF -DWITH_OPENEXR=OFF -DWITH_FFMPEG=OFF -DWITH_JASPER=OFF -DWITH_TIFF=OFF
IF !ERRORLEVEL! NEQ 0 (
echo Failed to generate OpenCV solution
goto Error
)
) ELSE (
IF "%MSVC_VERSION%" == "2013" (
cmake .. -G "Visual Studio 12 Win64" -DBUILD_SHARED_LIBS=0 -DBUILD_WITH_STATIC_CRT=OFF -DBUILD_PERF_TESTS=OFF -DBUILD_TESTS=OFF -DBUILD_DOCS=OFF -DBUILD_opencv_apps=OFF -DBUILD_opencv_flann=ON -DBUILD_opencv_features2d=ON -DBUILD_opencv_objdetect=OFF -DBUILD_opencv_photo=OFF -DBUILD_opencv_ts=OFF -DBUILD_opencv_ml=OFF -DBUILD_opencv_video=OFF -DBUILD_opencv_java=OFF -DWITH_OPENEXR=OFF -DWITH_FFMPEG=OFF -DWITH_JASPER=OFF -DWITH_TIFF=OFF
cmake .. -G "Visual Studio 12 Win64" -DBUILD_SHARED_LIBS=0 -DBUILD_WITH_STATIC_CRT=OFF -DBUILD_PERF_TESTS=OFF -DBUILD_TESTS=OFF -DBUILD_DOCS=OFF -DBUILD_opencv_apps=OFF -DBUILD_opencv_flann=ON -DBUILD_opencv_features2d=ON -DBUILD_opencv_objdetect=OFF -DBUILD_opencv_photo=OFF -DBUILD_opencv_ts=OFF -DBUILD_opencv_ml=ON -DBUILD_opencv_video=OFF -DBUILD_opencv_java=OFF -DWITH_OPENEXR=OFF -DWITH_FFMPEG=OFF -DWITH_JASPER=OFF -DWITH_TIFF=OFF
IF !ERRORLEVEL! NEQ 0 (
echo Failed to generate OpenCV solution
goto Error
Expand Down
2 changes: 1 addition & 1 deletion contrib/build_scripts/osx/build-osx-snapshot
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ cd $PSMOVEAPI_CHECKOUT
if [ ! -d $OPENCV_INSTALL_DIR ]; then
cd external
if [ ! -d opencv ]; then
git clone git://github.com/Itseez/opencv.git
git clone --depth 1 --branch 3.1.0 git://github.com/Itseez/opencv.git
fi
cd opencv
rm -rf build
Expand Down
6 changes: 3 additions & 3 deletions docs/README.win64_msvc
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,12 @@ Manual build
2. OpenCV (Optional -- only needed to build the positional tracker)

In `psmoveapi/external`
git clone --depth 1 --branch 2.4.11 git://github.com/Itseez/opencv.git
git clone --depth 1 --branch 3.1.0 git://github.com/Itseez/opencv.git
`cd opencv`
`mkdir build`
`cd build`
VS2013: `cmake .. -G "Visual Studio 12 Win64" -DBUILD_SHARED_LIBS=0 -DBUILD_WITH_STATIC_CRT=OFF -DBUILD_PERF_TESTS=OFF -DBUILD_TESTS=OFF -DBUILD_DOCS=OFF -DBUILD_opencv_apps=OFF -DBUILD_opencv_flann=ON -DBUILD_opencv_features2d=ON -DBUILD_opencv_objdetect=OFF -DBUILD_opencv_photo=OFF -DBUILD_opencv_ts=OFF -DBUILD_opencv_ml=OFF -DBUILD_opencv_video=OFF -DBUILD_opencv_java=OFF -DWITH_OPENEXR=OFF -DWITH_FFMPEG=OFF -DWITH_JASPER=OFF -DWITH_TIFF=OFF`
VS2015: `cmake .. -G "Visual Studio 14 Win64" -DBUILD_SHARED_LIBS=0 -DBUILD_WITH_STATIC_CRT=OFF -DBUILD_PERF_TESTS=OFF -DBUILD_TESTS=OFF -DBUILD_DOCS=OFF -DBUILD_opencv_apps=OFF -DBUILD_opencv_flann=ON -DBUILD_opencv_features2d=ON -DBUILD_opencv_objdetect=OFF -DBUILD_opencv_photo=OFF -DBUILD_opencv_ts=OFF -DBUILD_opencv_ml=OFF -DBUILD_opencv_video=OFF -DBUILD_opencv_java=OFF -DWITH_OPENEXR=OFF -DWITH_FFMPEG=OFF -DWITH_JASPER=OFF -DWITH_TIFF=OFF`
VS2013: `cmake .. -G "Visual Studio 12 Win64" -DBUILD_SHARED_LIBS=0 -DBUILD_WITH_STATIC_CRT=OFF -DBUILD_PERF_TESTS=OFF -DBUILD_TESTS=OFF -DBUILD_DOCS=OFF -DBUILD_opencv_apps=OFF -DBUILD_opencv_flann=ON -DBUILD_opencv_features2d=ON -DBUILD_opencv_objdetect=OFF -DBUILD_opencv_photo=OFF -DBUILD_opencv_ts=OFF -DBUILD_opencv_ml=ON -DBUILD_opencv_video=OFF -DBUILD_opencv_java=OFF -DWITH_OPENEXR=OFF -DWITH_FFMPEG=OFF -DWITH_JASPER=OFF -DWITH_TIFF=OFF`
VS2015: `cmake .. -G "Visual Studio 14 Win64" -DBUILD_SHARED_LIBS=0 -DBUILD_WITH_STATIC_CRT=OFF -DBUILD_PERF_TESTS=OFF -DBUILD_TESTS=OFF -DBUILD_DOCS=OFF -DBUILD_opencv_apps=OFF -DBUILD_opencv_flann=ON -DBUILD_opencv_features2d=ON -DBUILD_opencv_objdetect=OFF -DBUILD_opencv_photo=OFF -DBUILD_opencv_ts=OFF -DBUILD_opencv_ml=ON -DBUILD_opencv_video=OFF -DBUILD_opencv_java=OFF -DWITH_OPENEXR=OFF -DWITH_FFMPEG=OFF -DWITH_JASPER=OFF -DWITH_TIFF=OFF`

Open the solution in psmoveapi\external\opencv\build\OpenCV.sln
Change the target to Release or Debug (as desired) at the top of the Visual Studio window
Expand Down
9 changes: 9 additions & 0 deletions external/msvc-support/unistd.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,15 @@ typedef unsigned __int64 uint64_t;
#define snprintf _snprintf // Not exactly the same, but close enough.
#endif

#ifdef __cplusplus
extern "C"
{
#endif

int usleep(__int64 useconds);

#ifdef __cplusplus
}
#endif

#endif /* unistd.h */
12 changes: 0 additions & 12 deletions src/math/psmove_math.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,6 @@
#define k_real_half_pi 0.5f*k_real_pi

//-- macros ----
#ifdef isfinite
#define is_valid_float(x) (!isnan(x) && isfinite(x))
#else
#define is_valid_float(x) (!isnan(x))
#endif

#define is_nearly_equal(a, b, epsilon) (fabsf(a-b) <= epsilon)
#define is_nearly_zero(x) is_nearly_equal(x, 0.0f, k_real_epsilon)

Expand All @@ -66,12 +60,6 @@
#define sqr(x) (x*x)
#endif

#ifdef NDEBUG
#define assert_valid_float(x) assert(is_valid_float(x))
#else
#define assert_valid_float(x) ((void)0)
#endif

//-- inline -----
#ifdef __cplusplus
extern "C" {
Expand Down
13 changes: 13 additions & 0 deletions src/math/psmove_quaternion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,19 @@

#include <assert.h>

//-- macros ----
#ifdef isfinite
#define is_valid_float(x) (!std::isnan(x) && isfinite(x))
#else
#define is_valid_float(x) (!std::isnan(x))
#endif

#ifdef NDEBUG
#define assert_valid_float(x) assert(is_valid_float(x))
#else
#define assert_valid_float(x) ((void)0)
#endif

//-- globals ----
const glm::quat g_psmove_quaternion_zero = glm::quat(0, 0, 0, 0);
const glm::quat *k_psmove_quaternion_zero = &g_psmove_quaternion_zero;
Expand Down
9 changes: 9 additions & 0 deletions src/tracker/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,15 @@ source_group("Source Files\\iniparser" FILES ${INIPARSER_SRC})


if(PSMOVE_BUILD_TRACKER)
IF(MSVC)
# Due to a bug in OpenCV 3.0+, C source files that call cvGetSize will crash when built by MSVC.
# psmove_tracker.c is such a file, so we need to force the C++ compiler to be used for it, even though it's a C file.
# Once the OpenCV bug is fixed, this can/should be removed.
#
# See https://github.com/Itseez/opencv/issues/6221 for more info.
set_source_files_properties( ${CMAKE_CURRENT_LIST_DIR}/psmove_tracker.c PROPERTIES LANGUAGE CXX )
ENDIF(MSVC)

include_directories(${ROOT_DIR}/external/glm)
add_library(psmoveapi_tracker SHARED
${PSMOVEAPI_TRACKER_SRC}
Expand Down
88 changes: 48 additions & 40 deletions src/tracker/psmove_tracker.c
Original file line number Diff line number Diff line change
Expand Up @@ -62,45 +62,53 @@
#define PSEYE_BACKUP_FILE "PSEye_backup.ini"
#define COLOR_MAPPING_DAT "colormapping.dat"

static const PSMoveTrackerSettings tracker_default_settings = {
.camera_frame_width = 0,
.camera_frame_height = 0,
.camera_frame_rate = 0,
.camera_auto_gain = PSMove_False,
.camera_gain = 0,
.camera_auto_white_balance = PSMove_False,
.camera_exposure = (255 * 15) / 0xFFFF,
.camera_brightness = 0,
.camera_mirror = PSMove_False,
.exposure_mode = Exposure_LOW,
.calibration_blink_delay = 200,
.calibration_diff_t = 20,
.calibration_min_size = 50,
.calibration_max_distance = 30,
.calibration_size_std = 10,
.color_mapping_max_age = 2 * 60 * 60,
.dimming_factor = 1.f,
.color_hue_filter_range = 20,
.color_saturation_filter_range = 85,
.color_value_filter_range = 85,
.tracker_adaptive_xy = 1,
.tracker_adaptive_z = 1,
.color_adaption_quality_t = 35.f,
.color_update_rate = 1.f,
.search_tile_width = 0,
.search_tile_height = 0,
.search_tiles_horizontal = 0,
.search_tiles_count = 0,
.roi_adjust_fps_t = 160,
.tracker_quality_t1 = 0.3f,
.tracker_quality_t2 = 0.7f,
.tracker_quality_t3 = 4.7f,
.color_update_quality_t1 = 0.8f,
.color_update_quality_t2 = 0.2f,
.color_update_quality_t3 = 6.f,
.intrinsics_xml = "intrinsics.xml",
.distortion_xml = "distortion.xml"
};
/**
* Helper function to create the default tracker settings. Needed so this file can be compiled as both C and C++ (C++ does not support designated initializers)
**/
static const PSMoveTrackerSettings create_tracker_default_settings()
{
PSMoveTrackerSettings defaults;

defaults.camera_frame_width = 0;
defaults.camera_frame_height = 0;
defaults.camera_frame_rate = 0;
defaults.camera_auto_gain = PSMove_False;
defaults.camera_gain = 0;
defaults.camera_auto_white_balance = PSMove_False;
defaults.camera_exposure = (255 * 15) / 0xFFFF;
defaults.camera_brightness = 0;
defaults.camera_mirror = PSMove_False;
defaults.exposure_mode = Exposure_LOW;
defaults.calibration_blink_delay = 200;
defaults.calibration_diff_t = 20;
defaults.calibration_min_size = 50;
defaults.calibration_max_distance = 30;
defaults.calibration_size_std = 10;
defaults.color_mapping_max_age = 2 * 60 * 60;
defaults.dimming_factor = 1.f;
defaults.color_hue_filter_range = 20;
defaults.color_saturation_filter_range = 85;
defaults.color_value_filter_range = 85;
defaults.tracker_adaptive_xy = 1;
defaults.tracker_adaptive_z = 1;
defaults.color_adaption_quality_t = 35.f;
defaults.color_update_rate = 1.f;
defaults.search_tile_width = 0;
defaults.search_tile_height = 0;
defaults.search_tiles_horizontal = 0;
defaults.search_tiles_count = 0;
defaults.roi_adjust_fps_t = 160;
defaults.tracker_quality_t1 = 0.3f;
defaults.tracker_quality_t2 = 0.7f;
defaults.tracker_quality_t3 = 4.7f;
defaults.color_update_quality_t1 = 0.8f;
defaults.color_update_quality_t2 = 0.2f;
defaults.color_update_quality_t3 = 6.f;
defaults.intrinsics_xml = "intrinsics.xml";
defaults.distortion_xml = "distortion.xml";

return defaults;
}

/**
* Syntactic sugar - iterate over all valid controllers of a tracker
Expand Down Expand Up @@ -382,7 +390,7 @@ psmove_tracker_remember_color(PSMoveTracker *tracker, struct PSMove_RGBValue rgb
void
psmove_tracker_settings_set_default(PSMoveTrackerSettings *settings)
{
*settings = tracker_default_settings;
*settings = create_tracker_default_settings();
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this is the only place where the default settings are used, we could make it so that the function takes a pointer to the object that should be set to defaults. Avoids two object copies. Also the "const" on the return value isn't really useful if returned by value.

static void set_tracker_default_settings(PSMoveTrackerSettings *settings)
{
    settings->camera_frame_width = 0;
    settings->camera_frame_height = 0;
    settings->camera_frame_rate = 0;
    settings->camera_auto_gain = PSMove_False;
    settings->camera_gain = 0;
    // ...
}

Come to think of it, at this point you could just move the setting code directly to psmove_tracker_settings_set_default, getting rid of the extra function:

void psmove_tracker_settings_set_default(PSMoveTrackerSettings *settings)
{
    settings->camera_frame_width = 0;
    settings->camera_frame_height = 0;
    settings->camera_frame_rate = 0;
    settings->camera_auto_gain = PSMove_False;
    settings->camera_gain = 0;
    // ...
}

Please also take care of indentation, don't mix tabs with spaces, and use 4 spaces indentation.

}

PSMoveTracker *psmove_tracker_new() {
Expand Down
8 changes: 8 additions & 0 deletions src/tracker/tracker_helpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@
((a).y - (b).y) * \
((a).y - (b).y))

#ifdef __cplusplus
extern "C" {
#endif

/**
* Variance and average of an array of doubles
*
Expand Down Expand Up @@ -88,4 +92,8 @@ th_scalar_mul(CvScalar a, double b);
CvScalar
th_brg2hsv(CvScalar bgr);

#ifdef __cplusplus
}
#endif

#endif // TRACKER_HELPERS_H