Browse files

Tracker: Initial exposure control support

  • Loading branch information...
1 parent 7cfb5b5 commit 11d3a9c2b061fe9cbee20bc05916f3243c07e526 @thp committed Nov 27, 2012
View
7 CMakeLists.txt
@@ -46,6 +46,9 @@ option(PSMOVE_USE_PSEYE "Enable tweaks for the PS Eye camera" ON)
# Use the CL Eye SDK to interface with the PS Eye camera (Windows only)
option(PSMOVE_USE_CL_EYE_SDK "Use the CL Eye SDK driver on Windows" OFF)
+# To show the OpenCV camera capture window everytime (useful for debugging)
+option(PSMOVE_USE_DEBUG_CAPTURE "Always show camera capture input" OFF)
+
# Make a debug build with helpful output for debugging / maintenance
option(PSMOVE_USE_DEBUG "Build for debugging" OFF)
@@ -116,6 +119,10 @@ if (PSMOVE_USE_LOCAL_OPENCV)
endif()
endif()
+if (PSMOVE_USE_DEBUG_CAPTURE)
+ add_definitions(-DCAMERA_CONTROL_DEBUG_CAPTURED_IMAGE)
+endif()
+
set(INFO_USE_CL_EYE_SDK "No (Windows only)")
IF(${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
View
18 bindings/swig/psmove.i
@@ -12,6 +12,7 @@
%rename PSMove_Connection_Type ConnectionType;
%rename PSMove_Frame Frame;
%rename PSMoveTracker_Status Status;
+%rename PSMoveTracker_Exposure Exposure;
%rename PSMove_RemoteConfig RemoteConfig;
%module psmoveapi
@@ -25,6 +26,7 @@
%rename PSMove_Connection_Type ConnectionType;
%rename PSMove_Frame Frame;
%rename PSMoveTracker_Status Status;
+%rename PSMoveTracker_Exposure Exposure;
%rename PSMove_RemoteConfig RemoteConfig;
%module psmoveapi_csharp
@@ -219,6 +221,9 @@ void reinit();
/* Dimming factor */
float dimming;
+ /* Exposure mode */
+ enum PSMoveTracker_Exposure exposure;
+
PSMoveTracker() {
return psmove_tracker_new();
}
@@ -440,6 +445,19 @@ PSMoveTracker_dimming_set(PSMoveTracker *tracker, float dimming)
}
void
+PSMoveTracker_exposure_set(PSMoveTracker *tracker,
+ enum PSMoveTracker_Exposure exposure)
+{
+ psmove_tracker_set_exposure(tracker, exposure);
+}
+
+enum PSMoveTracker_Exposure
+PSMoveTracker_exposure_get(PSMoveTracker *tracker)
+{
+ return psmove_tracker_get_exposure(tracker);
+}
+
+void
PSMoveTracker_get_color(PSMoveTracker *tracker, PSMove *move,
unsigned char *r, unsigned char *g, unsigned char *b)
{
View
1 examples/c/test_opengl.cpp
@@ -93,6 +93,7 @@ Tracker::Tracker()
m_fusion(psmove_fusion_new(m_tracker, 1., 1000.))
{
psmove_tracker_set_mirror(m_tracker, PSMove_True);
+ psmove_tracker_set_exposure(m_tracker, Exposure_HIGH);
psmove_tracker_set_dimming(m_tracker, .01);
m_moves = (PSMove**)calloc(m_count, sizeof(PSMove*));
View
1 examples/c/test_opengl2.cpp
@@ -151,6 +151,7 @@ Tracker::Tracker()
m_fusion(psmove_fusion_new(m_tracker, 1., 1000.))
{
psmove_tracker_set_mirror(m_tracker, PSMove_True);
+ psmove_tracker_set_exposure(m_tracker, Exposure_HIGH);
psmove_tracker_set_dimming(m_tracker, .01);
m_moves = (PSMove**)calloc(m_count, sizeof(PSMove*));
View
1 examples/c/test_opengl3.cpp
@@ -145,6 +145,7 @@ Tracker::Tracker()
m_fusion(psmove_fusion_new(m_tracker, 1., 1000.))
{
psmove_tracker_set_mirror(m_tracker, PSMove_True);
+ psmove_tracker_set_exposure(m_tracker, Exposure_HIGH);
psmove_tracker_set_dimming(m_tracker, .01);
m_moves = (PSMove**)calloc(m_move_count, sizeof(PSMove*));
View
60 examples/python/test_exposure.py
@@ -0,0 +1,60 @@
+
+#
+# PS Move API - An interface for the PS Move Motion Controller
+# Copyright (c) 2012 Thomas Perl <m@thp.io>
+# All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions are met:
+#
+# 1. Redistributions of source code must retain the above copyright
+# notice, this list of conditions and the following disclaimer.
+#
+# 2. Redistributions in binary form must reproduce the above copyright
+# notice, this list of conditions and the following disclaimer in the
+# documentation and/or other materials provided with the distribution.
+#
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
+# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+# POSSIBILITY OF SUCH DAMAGE.
+#
+
+
+import sys
+import os
+sys.path.insert(0, os.path.join(os.path.dirname(__file__), '..', '..', 'build'))
+
+import psmove
+import time
+
+move = psmove.PSMove()
+tracker = psmove.PSMoveTracker()
+
+while tracker.enable(move) != psmove.Tracker_CALIBRATED:
+ pass
+
+while True:
+ tracker.update_image()
+ tracker.update()
+
+ while move.poll():
+ pressed, released = move.get_button_events()
+ if pressed & psmove.Btn_TRIANGLE:
+ tracker.exposure = psmove.Exposure_LOW
+ elif pressed & psmove.Btn_CIRCLE:
+ tracker.exposure = psmove.Exposure_MEDIUM
+ elif pressed & psmove.Btn_CROSS:
+ tracker.exposure = psmove.Exposure_HIGH
+ elif pressed & psmove.Btn_SQUARE:
+ tracker.exposure = psmove.Exposure_DYNAMIC
+
+ time.sleep(.1)
+
View
15 include/psmove_tracker.h
@@ -77,6 +77,15 @@ enum PSMoveTracker_Status {
Tracker_TRACKING, /*!< Calibrated and successfully tracked in the camera */
};
+/*! Exposure modes */
+enum PSMoveTracker_Exposure {
+ Exposure_LOW, /*!< Very low exposure: Good tracking, no environment visible */
+ Exposure_MEDIUM, /*!< Middle ground: Good tracking, environment visibile */
+ Exposure_HIGH, /*!< High exposure: Fair tracking, but good environment */
+ Exposure_DYNAMIC, /*!< Experimental dynamic exposure algorithm */
+ Exposure_INVALID, /*!< Invalid exposure value (for returning failures) */
+};
+
/**
* Create a new PS Move tracker and set up tracking
*
@@ -120,6 +129,12 @@ ADDAPI float
ADDCALL psmove_tracker_get_dimming(PSMoveTracker *tracker);
ADDAPI void
+ADDCALL psmove_tracker_set_exposure(PSMoveTracker *tracker, enum PSMoveTracker_Exposure exposure);
+
+ADDAPI enum PSMoveTracker_Exposure
+ADDCALL psmove_tracker_get_exposure(PSMoveTracker *tracker);
+
+ADDAPI void
ADDCALL psmove_tracker_enable_deinterlace(PSMoveTracker *tracker,
enum PSMove_Bool enabled);
View
6 src/tracker/camera_control.c
@@ -210,6 +210,12 @@ camera_control_query_frame(CameraControl* cc)
result = cc->frame3chUndistort;
}
+
+#if defined(CAMERA_CONTROL_DEBUG_CAPTURED_IMAGE)
+ cvShowImage("camera input", result);
+ cvWaitKey(1);
+#endif
+
return result;
}
View
1 src/tracker/platform/camera_control_linux.c
@@ -115,7 +115,6 @@ void camera_control_restore_system_settings(CameraControl* cc, const char* file)
void camera_control_set_parameters(CameraControl* cc, int autoE, int autoG, int autoWB, int exposure, int gain, int wbRed, int wbGreen, int wbBlue, int contrast,
int brightness) {
- return;
int fd = open_v4l2_device(cc->cameraID);
if (fd != -1) {
View
47 src/tracker/psmove_tracker.c
@@ -49,9 +49,8 @@
# include "platform/psmove_linuxsupport.h"
#endif
-//#define PRINT_DEBUG_STATS // shall graphical statistics be printed to the image
+#define PRINT_DEBUG_STATS // shall graphical statistics be printed to the image
//#define DEBUG_WINDOWS // shall additional windows be shown
-#define GOOD_EXPOSURE 2051 // a very low exposure that was found to be good for tracking
#define ROIS 4 // the number of levels of regions of interest (roi)
#define BLINKS 4 // number of diff images to create during calibration
#define BLINK_DELAY 100 // number of milliseconds to wait between a blink
@@ -170,6 +169,7 @@ struct _PSMoveTracker {
IplConvKernel* kCalib; // kernel used for morphological operations during calibration
CvScalar rHSV; // the range of the color filter
+ enum PSMoveTracker_Exposure exposure_mode; // exposure mode
float dimming_factor; // dimming factor used on LED RGB values
TrackedController controllers[PSMOVE_TRACKER_MAX_CONTROLLERS]; // controller data
@@ -456,6 +456,44 @@ psmove_tracker_get_dimming(PSMoveTracker *tracker)
}
void
+psmove_tracker_set_exposure(PSMoveTracker *tracker,
+ enum PSMoveTracker_Exposure exposure)
+{
+ psmove_return_if_fail(tracker != NULL);
+ tracker->exposure_mode = exposure;
+
+ switch (tracker->exposure_mode) {
+ case Exposure_LOW:
+ tracker->exposure = 2051;
+ break;
+ case Exposure_MEDIUM:
+ tracker->exposure = 20000;
+ break;
+ case Exposure_HIGH:
+ tracker->exposure = 40000;
+ break;
+ case Exposure_DYNAMIC:
+ // use dynamic exposure (a lighting condition specific exposure)
+ tracker->exposure = psmove_tracker_adapt_to_light(tracker, 25, 2051, 4051);
+ break;
+ default:
+ psmove_DEBUG("Invalid exposure mode: %s\n", exposure);
+ tracker->exposure = 2051;
+ break;
+ }
+
+ camera_control_set_parameters(tracker->cc, 0, 0, 0, tracker->exposure,
+ 0, 0xffff, 0xffff, 0xffff, -1, -1);
+}
+
+enum PSMoveTracker_Exposure
+psmove_tracker_get_exposure(PSMoveTracker *tracker)
+{
+ psmove_return_val_if_fail(tracker != NULL, Exposure_INVALID);
+ return tracker->exposure_mode;
+}
+
+void
psmove_tracker_enable_deinterlace(PSMoveTracker *tracker,
enum PSMove_Bool enabled)
{
@@ -552,10 +590,7 @@ psmove_tracker_new_with_camera(int camera) {
#endif
// use static exposure
- tracker->exposure = GOOD_EXPOSURE;
- // use dynamic exposure (This function would enable a lighting condition specific exposure.)
- //tracker->exposure = psmove_tracker_adapt_to_light(tracker, 25, 2051, 4051);
- camera_control_set_parameters(tracker->cc, 0, 0, 0, tracker->exposure, 0, 0xffff, 0xffff, 0xffff, -1, -1);
+ psmove_tracker_set_exposure(tracker, Exposure_LOW);
// just query a frame so that we know the camera works
IplImage* frame = NULL;

0 comments on commit 11d3a9c

Please sign in to comment.