Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

ROI Size Test Application, Tracker improvements

  • Loading branch information...
commit ccb3faa41acce4ecdcdfe5e953cd92726aff72fb 1 parent c0f5604
@thp authored
View
2  CMakeLists.txt
@@ -346,7 +346,7 @@ if(PSMOVE_BUILD_TESTS)
endforeach(TESTNAME)
if(PSMOVE_BUILD_TRACKER)
- foreach(TESTNAME tracker capture_performance)
+ foreach(TESTNAME tracker capture_performance record_video roi_size)
add_executable(test_${TESTNAME} examples/c/test_${TESTNAME}.c)
target_link_libraries(test_${TESTNAME} psmoveapi psmoveapi_tracker)
endforeach(TESTNAME)
View
6 examples/c/test_capture_performance.c
@@ -129,9 +129,6 @@ main(int argc, char *argv[])
&(context.capture_retrieve),
&(context.capture_converted));
- psmove_tracker_annotate(context.tracker);
- save(i, &context);
-
float grab = _psmove_timestamp_value(_psmove_timestamp_diff(context.capture_grab, context.capture_begin));
float retrieve = _psmove_timestamp_value(_psmove_timestamp_diff(context.capture_retrieve, context.capture_grab));
float converted = _psmove_timestamp_value(_psmove_timestamp_diff(context.capture_converted, context.capture_retrieve));
@@ -145,6 +142,9 @@ main(int argc, char *argv[])
fprintf(fp, ",%.10f", tracking);
}
fprintf(fp, "\n");
+
+ psmove_tracker_annotate(context.tracker);
+ save(i, &context);
}
fclose(fp);
View
97 examples/c/test_record_video.c
@@ -0,0 +1,97 @@
+
+ /**
+ * 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.
+ **/
+
+#include <stdio.h>
+
+#include <time.h>
+#include <unistd.h>
+#include <assert.h>
+
+#include "opencv2/core/core_c.h"
+#include "opencv2/highgui/highgui_c.h"
+
+#include "psmove.h"
+#include "psmove_tracker.h"
+
+int main(int arg, char** args) {
+ int count = psmove_count_connected();
+ PSMove *moves[count];
+
+ int i;
+ void *frame;
+ int result;
+
+ if (count == 0) {
+ printf("No controllers connected.\n");
+ return 1;
+ }
+
+ PSMoveTracker* tracker = psmove_tracker_new();
+
+ for (i=0; i<count; i++) {
+ moves[i] = psmove_connect_by_id(i);
+ assert(moves[i] != NULL);
+
+ while (psmove_tracker_enable(tracker, moves[i])
+ != Tracker_CALIBRATED);
+ }
+
+ unsigned char r, g, b;
+ psmove_tracker_get_camera_color(tracker, moves[0], &r, &g, &b);
+ printf("Controller color: %02x%02x%02x\n", r, g, b);
+
+ CvVideoWriter *writer = cvCreateVideoWriter("out.avi",
+ CV_FOURCC('M','J','P','G'), 30, cvSize(640, 480), 1);
+
+ while ((cvWaitKey(1) & 0xFF) != 27) {
+ psmove_tracker_update_image(tracker);
+ psmove_tracker_update(tracker, NULL);
+
+ frame = psmove_tracker_get_frame(tracker);
+ if (frame) {
+ cvWriteFrame(writer, frame);
+ }
+
+ psmove_tracker_annotate(tracker);
+ frame = psmove_tracker_get_frame(tracker);
+ if (frame) {
+ cvShowImage("live camera feed", frame);
+ }
+ }
+
+ cvReleaseVideoWriter(&writer);
+
+ for (i=0; i<count; i++) {
+ psmove_disconnect(moves[i]);
+ }
+
+ psmove_tracker_free(tracker);
+ return 0;
+}
+
View
204 examples/c/test_roi_size.c
@@ -0,0 +1,204 @@
+
+ /**
+ * 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.
+ **/
+
+
+
+#include <unistd.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <assert.h>
+
+#include "psmove.h"
+#include "psmove_tracker.h"
+
+/* This performance test application uses private APIs */
+#include "../../src/psmove_private.h"
+#include "../../src/tracker/psmove_tracker_private.h"
+
+/* OpenCV used for saving screenshots */
+#include "opencv2/core/core_c.h"
+#include "opencv2/highgui/highgui_c.h"
+
+struct TestContext {
+ int count;
+ PSMoveTracker *tracker;
+ PSMove **moves;
+
+ /* Capture timestamps */
+ PSMove_timestamp capture_begin;
+ PSMove_timestamp capture_grab;
+ PSMove_timestamp capture_retrieve;
+ PSMove_timestamp capture_converted;
+};
+
+void
+setup(struct TestContext *context)
+{
+ int i;
+
+ context->count = psmove_count_connected();
+ context->tracker = psmove_tracker_new();
+ psmove_tracker_set_mirror(context->tracker, PSMove_True);
+ context->moves = calloc(context->count, sizeof(PSMove *));
+
+ for (i=0; i<context->count; i++) {
+ context->moves[i] = psmove_connect_by_id(i);
+ assert(context->moves[i]);
+ while (psmove_tracker_enable(context->tracker,
+ context->moves[i]) != Tracker_CALIBRATED);
+ }
+
+ _psmove_tracker_fix_roi_size(context->tracker);
+}
+
+void
+teardown(struct TestContext *context)
+{
+ int i;
+
+ for (i=0; i<context->count; i++) {
+ psmove_tracker_disable(context->tracker,
+ context->moves[i]);
+ psmove_disconnect(context->moves[i]);
+ }
+
+ free(context->moves);
+ psmove_tracker_free(context->tracker);
+}
+
+#define ITERATIONS 500
+
+void
+save(int i, int roi_size, struct TestContext *context)
+{
+ void *frame = psmove_tracker_get_frame(context->tracker);
+ char path[512];
+ snprintf(path, sizeof(path), "roi_perf_%03d_%03d.jpg", roi_size, i);
+ int imgParams[] = { CV_IMWRITE_JPEG_QUALITY, 90, 0 };
+ cvSaveImage(path, frame, imgParams);
+}
+
+int
+main(int argc, char *argv[])
+{
+ printf("\n -- PS Move API ROI Performance Test -- \n\n");
+ int roi_sizes[] = {480, 240, 120};
+ int roi;
+ int rois = sizeof(roi_sizes)/sizeof(roi_sizes[0]);
+
+ float data[ITERATIONS][rois];
+ float position[ITERATIONS][rois][3]; // x, y, r
+
+ /**
+ * Test file for this test is available from:
+ * http://code.google.com/p/moveonpc/downloads/detail?name=test_roi_size.avi
+ *
+ * You need to have exactly one controller connected.
+ **/
+ setenv(PSMOVE_TRACKER_FILENAME_ENV, "test_roi_size.avi", 1);
+ setenv(PSMOVE_TRACKER_COLOR_ENV, "723a8c", 1);
+
+ for (roi=0; roi<rois; roi++) {
+ char tmp[10];
+ sprintf(tmp, "%d", roi_sizes[roi]);
+ printf("Testing tracking performance: %s\n", tmp);
+
+ setenv("PSMOVE_TRACKER_ROI_SIZE", tmp, 1);
+
+ struct TestContext context;
+ setup(&context);
+ assert(context.count == 1);
+
+ int i;
+ for (i=0; i<ITERATIONS; i++) {
+ psmove_tracker_update_image(context.tracker);
+
+ int j;
+ for (j=0; j<context.count; j++) {
+ PSMove_timestamp track_begin = _psmove_timestamp();
+ psmove_tracker_update(context.tracker, context.moves[j]);
+ PSMove_timestamp track_end = _psmove_timestamp();
+
+ float tracking = _psmove_timestamp_value(_psmove_timestamp_diff(track_end, track_begin));
+ data[i][roi] = tracking;
+
+ float x, y, r;
+ psmove_tracker_get_position(context.tracker, context.moves[j], &x, &y, &r);
+ position[i][roi][0] = x;
+ position[i][roi][1] = y;
+ position[i][roi][2] = r;
+ }
+
+ psmove_tracker_annotate(context.tracker);
+ if (i % 50 == 0) {
+ save(i, roi_sizes[roi], &context);
+ }
+ }
+
+ teardown(&context);
+ }
+
+ FILE *fp = fopen("roi_size.csv", "w");
+ assert(fp != NULL);
+
+ /* Header */
+ fprintf(fp, "frame");
+ int j;
+ for (roi=0; roi<rois; roi++) {
+ fprintf(fp, ",roi%d", roi_sizes[roi]);
+ }
+ for (roi=0; roi<rois; roi++) {
+ fprintf(fp, ",x%d,y%d,r%d",
+ roi_sizes[roi],
+ roi_sizes[roi],
+ roi_sizes[roi]);
+ }
+ fprintf(fp, "\n");
+
+ /* Data */
+ int i;
+ for (i=0; i<ITERATIONS; i++) {
+ fprintf(fp, "%d", i);
+ for (roi=0; roi<rois; roi++) {
+ fprintf(fp, ",%.10f", data[i][roi]);
+ }
+ for (roi=0; roi<rois; roi++) {
+ fprintf(fp, ",%.10f,%.10f,%.10f",
+ position[i][roi][0],
+ position[i][roi][1],
+ position[i][roi][2]);
+ }
+ fprintf(fp, "\n");
+ }
+
+ fclose(fp);
+
+ return 0;
+}
+
View
3  include/psmove_tracker.h
@@ -53,6 +53,9 @@ extern "C" {
/* Name of the environment variable used to set the biggest ROI size */
#define PSMOVE_TRACKER_ROI_SIZE_ENV "PSMOVE_TRACKER_ROI_SIZE"
+/* Name of the environment variable used to set a fixed tracker color */
+#define PSMOVE_TRACKER_COLOR_ENV "PSMOVE_TRACKER_COLOR"
+
/* Name of the environment variables for the camera image size */
#define PSMOVE_TRACKER_WIDTH_ENV "PSMOVE_TRACKER_WIDTH"
#define PSMOVE_TRACKER_HEIGHT_ENV "PSMOVE_TRACKER_HEIGHT"
View
52 src/tracker/psmove_tracker.c
@@ -57,7 +57,7 @@
#define CALIB_MIN_SIZE 50 // minimum size of the estimated glowing sphere during calibration process (in pixel)
#define CALIB_SIZE_STD 10 // maximum standard deviation (in %) of the glowing spheres found during calibration process
#define CALIB_MAX_DIST 30 // maximum displacement of the separate found blobs
-#define COLOR_FILTER_RANGE_H 12 // +- H-Range of the hsv-colorfilter
+#define COLOR_FILTER_RANGE_H 20 // +- H-Range of the hsv-colorfilter
#define COLOR_FILTER_RANGE_S 85 // +- s-Range of the hsv-colorfilter
#define COLOR_FILTER_RANGE_V 85 // +- v-Range of the hsv-colorfilter
@@ -120,6 +120,7 @@ struct _TrackedController {
int roi_x, roi_y; // x/y - Coordinates of the ROI
int roi_level; // the current index for the level of ROI
+ enum PSMove_Bool roi_level_fixed; // true if the ROI level should be fixed
float mx, my; // x/y - Coordinates of center of mass of the blob
float x, y, r; // x/y - Coordinates of the controllers sphere and its radius
int search_tile; // current search quadrant when controller is not found (reset to 0 if found)
@@ -839,6 +840,21 @@ enum PSMove_Bool
psmove_tracker_blinking_calibration(PSMoveTracker *tracker, PSMove *move,
struct PSMove_RGBValue rgb, CvScalar *color, CvScalar *hsv_color)
{
+ char *color_str = psmove_util_get_env_string(PSMOVE_TRACKER_COLOR_ENV);
+ if (color_str != NULL) {
+ int r, g, b;
+ if (sscanf(color_str, "%02x%02x%02x", &r, &g, &b) == 3) {
+ printf("r: %d, g: %d, b: %d\n", r, g, b);
+ *color = cvScalar(r, g, b, 0);
+ *hsv_color = th_brg2hsv(*color);
+ free(color_str);
+ return PSMove_True;
+ } else {
+ psmove_WARNING("Cannot parse color: '%s'\n", color_str);
+ }
+ free(color_str);
+ }
+
psmove_tracker_update_image(tracker);
IplImage* frame = tracker->frame;
assert(frame != NULL);
@@ -1248,14 +1264,8 @@ psmove_tracker_update_controller(PSMoveTracker *tracker, TrackedController *tc)
cvInRangeS(roi_i, min, max, roi_m);
#ifdef DEBUG_WINDOWS
- if (!tc->next){
- cvShowImage("binary:0", roi_m);
- cvShowImage("hsv:0", roi_i);
- }
- else{
- cvShowImage("binary:1", roi_m);
- cvShowImage("hsv:1", roi_i);
- }
+ cvShowImage("binary:0", roi_m);
+ cvShowImage("hsv:0", roi_i);
#endif
// find the biggest contour in the image
@@ -1379,7 +1389,12 @@ psmove_tracker_update_controller(PSMoveTracker *tracker, TrackedController *tc)
for (i = 0; i < ROIS; i++) {
if (br.width > tracker->roiI[i]->width && br.height > tracker->roiI[i]->height)
break;
- tc->roi_level = i;
+
+ if (tc->roi_level_fixed) {
+ tc->roi_level = 0;
+ } else {
+ tc->roi_level = i;
+ }
// update easy accessors
roi_i = tracker->roiI[tc->roi_level];
roi_m = tracker->roiM[tc->roi_level];
@@ -1401,7 +1416,11 @@ psmove_tracker_update_controller(PSMoveTracker *tracker, TrackedController *tc)
tc->roi_x += roi_i->width / 2;
tc->roi_y += roi_i->height / 2;
- tc->roi_level = tc->roi_level - 1;
+ if (tc->roi_level_fixed) {
+ tc->roi_level = 0;
+ } else {
+ tc->roi_level = tc->roi_level - 1;
+ }
// update easy accessors
roi_i = tracker->roiI[tc->roi_level];
roi_m = tracker->roiM[tc->roi_level];
@@ -1890,3 +1909,14 @@ _psmove_tracker_retrieve_stats(PSMoveTracker *tracker,
*ts_converted = tracker->ts_camera_converted;
}
+void
+_psmove_tracker_fix_roi_size(PSMoveTracker *tracker)
+{
+ psmove_return_if_fail(tracker != NULL);
+
+ TrackedController *tc;
+ for_each_controller (tracker, tc) {
+ tc->roi_level_fixed = PSMove_True;
+ }
+}
+
View
2  src/tracker/psmove_tracker_private.h
@@ -45,6 +45,8 @@ ADDCALL _psmove_tracker_retrieve_stats(PSMoveTracker *tracker,
PSMove_timestamp *ts_begin, PSMove_timestamp *ts_grab,
PSMove_timestamp *ts_retrieve, PSMove_timestamp *ts_converted);
+ADDAPI void
+ADDCALL _psmove_tracker_fix_roi_size(PSMoveTracker *tracker);
#ifdef __cplusplus
}
Please sign in to comment.
Something went wrong with that request. Please try again.