int main(int arg, char** args) { int count = psmove_count_connected(); int i; void *frame; if (count == 0) { printf("No controllers connected.\n"); return 1; } PSMove **moves = (PSMove **)calloc(count, sizeof(PSMove *)); 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); free(moves); return 0; }
void MoveHandler::updateTracker() { float xPos = 0.0f; float yPos = 0.0f; float ledRadius = 0.0f; psmove_tracker_update_image(this->tracker); psmove_tracker_update(this->tracker, NULL); #if DEBUG psmove_tracker_annotate(this->tracker); frame = psmove_tracker_get_frame(this->tracker); if (frame) { cvShowImage("Live camera feed", frame); } #endif psmove_tracker_get_position(this->tracker, this->USBController, &xPos, &yPos, &ledRadius); this->x = xPos; this->y = yPos; this->radius = ledRadius; }