Skip to content
Closed
Show file tree
Hide file tree
Changes from all 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
5 changes: 5 additions & 0 deletions examples/c/test_tracker.c
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,11 @@ int main(int arg, char** args) {

fprintf(stderr, "Trying to init PSMoveTracker...");
PSMoveTracker* tracker = psmove_tracker_new();
if (!tracker)
{
fprintf(stderr, "Could not init PSMoveTracker.\n");
return 1;
}
psmove_tracker_set_mirror(tracker, PSMove_True);
fprintf(stderr, "OK\n");

Expand Down
2 changes: 1 addition & 1 deletion external/PS3EYEDriver
Submodule PS3EYEDriver updated 4 files
+3 −3 src/ps3eye.cpp
+2 −0 src/ps3eye.h
+51 −0 src/ps3eyedriver.cpp
+22 −0 src/ps3eyedriver.h
1 change: 0 additions & 1 deletion src/tracker/camera_control.c
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,6 @@ camera_control_new(int cameraID)
#elif defined(CAMERA_CONTROL_USE_PS3EYE_DRIVER)
ps3eye_init();
int cams = ps3eye_count_connected();

if (cams <= cameraID) {
free(cc);
return NULL;
Expand Down
24 changes: 21 additions & 3 deletions src/tracker/platform/camera_control_macosx.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
**/

#include "../camera_control.h"

#include "../camera_control_private.h"
#include "psmove_osxsupport.h"

void
Expand All @@ -44,8 +44,26 @@ camera_control_set_parameters(CameraControl* cc,
int contrast, int brightness)
{
#if defined(CAMERA_CONTROL_USE_PS3EYE_DRIVER)
// TODO: Implement setting those parameters on cc->eye
psmove_WARNING("Unimplemented: Setting of PS3EYEDriver parameters\n");
ps3eye_set_parameter(cc->eye, PS3EYE_EXPOSURE, exposure);

/** Many of the values passed to this function do not work with PS3EYEDriver.
* comment out these functions until a sane value scheme is implemented.
* ps3eye_set_parameter(cc->eye, PS3EYE_AUTO_GAIN, autoG);
* ps3eye_set_parameter(cc->eye, PS3EYE_GAIN, gain);
* ps3eye_set_parameter(cc->eye, PS3EYE_AUTO_WHITEBALANCE, autoWB);
* ps3eye_set_parameter(cc->eye, PS3EYE_CONTRAST, contrast);
* ps3eye_set_parameter(cc->eye, PS3EYE_BRIGHTNESS, brightness);
* ps3eye_set_parameter(cc->eye, PS3EYE_REDBALANCE, wbRed);
* ps3eye_set_parameter(cc->eye, PS3EYE_BLUEBALANCE, wbGreen);
**/
psmove_WARNING("Only PS3EYEDriver parameter 'exposure' set by ps3eye_set_parameter.\n");
/** Some PS3EYEDriver parameters that could be set are not set by this function
* ps3eye_set_parameter(cc->eye, PS3EYE_SHARPNESS, autoG);
* ps3eye_set_parameter(cc->eye, PS3EYE_HUE, ???);
* ps3eye_set_parameter(cc->eye, PS3EYE_HFLIP, ??);
* ps3eye_set_parameter(cc->eye, PS3EYE_VFLIP, ??);
**/

#else
macosx_camera_set_exposure_lock(1);
#endif
Expand Down
273 changes: 154 additions & 119 deletions src/tracker/platform/camera_control_win32.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,92 +39,100 @@

void camera_control_backup_system_settings(CameraControl* cc, const char* file) {
#if !defined(CAMERA_CONTROL_USE_CL_DRIVER) && defined(PSMOVE_USE_PSEYE)
HKEY hKey;
DWORD l = sizeof(DWORD);
DWORD AutoAEC = 0;
DWORD AutoAGC = 0;
DWORD AutoAWB = 0;
DWORD Exposure = 0;
DWORD Gain = 0;
DWORD wbB = 0;
DWORD wbG = 0;
DWORD wbR = 0;
char* PATH = CL_DRIVER_REG_PATH;
int err = RegOpenKeyEx(HKEY_CURRENT_USER, PATH, 0, KEY_ALL_ACCESS, &hKey);
if (err != ERROR_SUCCESS) {
printf("Error: %d Unable to open reg-key: [HKCU]\%s!", err, PATH);
return;
}
RegQueryValueEx(hKey, "AutoAEC", NULL, NULL, (LPBYTE) &AutoAEC, &l);
RegQueryValueEx(hKey, "AutoAGC", NULL, NULL, (LPBYTE) &AutoAGC, &l);
RegQueryValueEx(hKey, "AutoAWB", NULL, NULL, (LPBYTE) &AutoAWB, &l);
RegQueryValueEx(hKey, "Exposure", NULL, NULL, (LPBYTE) &Exposure, &l);
RegQueryValueEx(hKey, "Gain", NULL, NULL, (LPBYTE) &Gain, &l);
RegQueryValueEx(hKey, "WhiteBalanceB", NULL, NULL, (LPBYTE) &wbB, &l);
RegQueryValueEx(hKey, "WhiteBalanceG", NULL, NULL, (LPBYTE) &wbG, &l);
RegQueryValueEx(hKey, "WhiteBalanceR", NULL, NULL, (LPBYTE) &wbR, &l);

dictionary* ini = dictionary_new(0);
iniparser_set(ini, "PSEye", 0);
iniparser_set_int(ini, "PSEye:AutoAEC", AutoAEC);
iniparser_set_int(ini, "PSEye:AutoAGC", AutoAGC);
iniparser_set_int(ini, "PSEye:AutoAWB", AutoAWB);
iniparser_set_int(ini, "PSEye:Exposure", Exposure);
iniparser_set_int(ini, "PSEye:Gain", Gain);
iniparser_set_int(ini, "PSEye:WhiteBalanceB", wbB);
iniparser_set_int(ini, "PSEye:WhiteBalanceG", wbG);
iniparser_set_int(ini, "PSEye:WhiteBalanceR", wbG);
iniparser_save_ini(ini, file);
dictionary_del(ini);
HKEY hKey;
DWORD l = sizeof(DWORD);
DWORD AutoAEC = 0;
DWORD AutoAGC = 0;
DWORD AutoAWB = 0;
DWORD Exposure = 0;
DWORD Gain = 0;
DWORD wbB = 0;
DWORD wbG = 0;
DWORD wbR = 0;
char* PATH = CL_DRIVER_REG_PATH;
int err = RegOpenKeyEx(HKEY_CURRENT_USER, PATH, 0, KEY_ALL_ACCESS, &hKey);
if (err != ERROR_SUCCESS) {
printf("Error: %d Unable to open reg-key: [HKCU]\%s!", err, PATH);
return;
}
RegQueryValueEx(hKey, "AutoAEC", NULL, NULL, (LPBYTE) &AutoAEC, &l);
RegQueryValueEx(hKey, "AutoAGC", NULL, NULL, (LPBYTE) &AutoAGC, &l);
RegQueryValueEx(hKey, "AutoAWB", NULL, NULL, (LPBYTE) &AutoAWB, &l);
RegQueryValueEx(hKey, "Exposure", NULL, NULL, (LPBYTE) &Exposure, &l);
RegQueryValueEx(hKey, "Gain", NULL, NULL, (LPBYTE) &Gain, &l);
RegQueryValueEx(hKey, "WhiteBalanceB", NULL, NULL, (LPBYTE) &wbB, &l);
RegQueryValueEx(hKey, "WhiteBalanceG", NULL, NULL, (LPBYTE) &wbG, &l);
RegQueryValueEx(hKey, "WhiteBalanceR", NULL, NULL, (LPBYTE) &wbR, &l);

dictionary* ini = dictionary_new(0);
iniparser_set(ini, "PSEye", 0);
iniparser_set_int(ini, "PSEye:AutoAEC", AutoAEC);
iniparser_set_int(ini, "PSEye:AutoAGC", AutoAGC);
iniparser_set_int(ini, "PSEye:AutoAWB", AutoAWB);
iniparser_set_int(ini, "PSEye:Exposure", Exposure);
iniparser_set_int(ini, "PSEye:Gain", Gain);
iniparser_set_int(ini, "PSEye:WhiteBalanceB", wbB);
iniparser_set_int(ini, "PSEye:WhiteBalanceG", wbG);
iniparser_set_int(ini, "PSEye:WhiteBalanceR", wbG);
iniparser_save_ini(ini, file);
dictionary_del(ini);
#endif
}

void camera_control_restore_system_settings(CameraControl* cc, const char* file) {
#if !defined(CAMERA_CONTROL_USE_CL_DRIVER) && defined(PSMOVE_USE_PSEYE)
int NOT_FOUND = -1;
int val;
HKEY hKey;
DWORD l = sizeof(DWORD);

char* PATH = CL_DRIVER_REG_PATH;
int err = RegOpenKeyEx(HKEY_CURRENT_USER, PATH, 0, KEY_ALL_ACCESS, &hKey);
if (err != ERROR_SUCCESS) {
printf("Error: %d Unable to open reg-key: [HKCU]\%s!", err, PATH);
return;
}

dictionary* ini = iniparser_load(file);
val = iniparser_getint(ini, "PSEye:AutoAEC", NOT_FOUND);
if (val != NOT_FOUND)
RegSetValueExA(hKey, "AutoAEC", 0, REG_DWORD, (CONST BYTE*) &val, l);

val = iniparser_getint(ini, "PSEye:AutoAGC", NOT_FOUND);
if (val != NOT_FOUND)
RegSetValueExA(hKey, "AutoAGC", 0, REG_DWORD, (CONST BYTE*) &val, l);
int NOT_FOUND = -1;
int val;
HKEY hKey;
DWORD l = sizeof(DWORD);

char* PATH = CL_DRIVER_REG_PATH;
int err = RegOpenKeyEx(HKEY_CURRENT_USER, PATH, 0, KEY_ALL_ACCESS, &hKey);
if (err != ERROR_SUCCESS) {
printf("Error: %d Unable to open reg-key: [HKCU]\%s!", err, PATH);
return;
}

dictionary* ini = iniparser_load(file);
val = iniparser_getint(ini, "PSEye:AutoAEC", NOT_FOUND);
if (val != NOT_FOUND){
RegSetValueExA(hKey, "AutoAEC", 0, REG_DWORD, (CONST BYTE*) &val, l);
}

val = iniparser_getint(ini, "PSEye:AutoAGC", NOT_FOUND);
if (val != NOT_FOUND){
RegSetValueExA(hKey, "AutoAGC", 0, REG_DWORD, (CONST BYTE*) &val, l);
}

val = iniparser_getint(ini, "PSEye:AutoAWB", NOT_FOUND);
if (val != NOT_FOUND)
RegSetValueExA(hKey, "AutoAWB", 0, REG_DWORD, (CONST BYTE*) &val, l);
if (val != NOT_FOUND){
RegSetValueExA(hKey, "AutoAWB", 0, REG_DWORD, (CONST BYTE*) &val, l);
}

val = iniparser_getint(ini, "PSEye:Exposure", NOT_FOUND);
if (val != NOT_FOUND)
RegSetValueExA(hKey, "Exposure", 0, REG_DWORD, (CONST BYTE*) &val, l);
if (val != NOT_FOUND){
RegSetValueExA(hKey, "Exposure", 0, REG_DWORD, (CONST BYTE*) &val, l);
}

val = iniparser_getint(ini, "PSEye:Gain", NOT_FOUND);
if (val != NOT_FOUND)
RegSetValueExA(hKey, "Gain", 0, REG_DWORD, (CONST BYTE*) &val, l);
if (val != NOT_FOUND){
RegSetValueExA(hKey, "Gain", 0, REG_DWORD, (CONST BYTE*) &val, l);
}

val = iniparser_getint(ini, "PSEye:WhiteBalanceR", NOT_FOUND);
if (val != NOT_FOUND)
RegSetValueExA(hKey, "WhiteBalanceR", 0, REG_DWORD, (CONST BYTE*) &val, l);
if (val != NOT_FOUND){
RegSetValueExA(hKey, "WhiteBalanceR", 0, REG_DWORD, (CONST BYTE*) &val, l);
}

val = iniparser_getint(ini, "PSEye:WhiteBalanceB", NOT_FOUND);
if (val != NOT_FOUND)
RegSetValueExA(hKey, "WhiteBalanceB", 0, REG_DWORD, (CONST BYTE*) &val, l);
if (val != NOT_FOUND){
RegSetValueExA(hKey, "WhiteBalanceB", 0, REG_DWORD, (CONST BYTE*) &val, l);
}

val = iniparser_getint(ini, "PSEye:WhiteBalanceG", NOT_FOUND);
if (val != NOT_FOUND)
RegSetValueExA(hKey, "WhiteBalanceG", 0, REG_DWORD, (CONST BYTE*) &val, l);
if (val != NOT_FOUND){
RegSetValueExA(hKey, "WhiteBalanceG", 0, REG_DWORD, (CONST BYTE*) &val, l);
}

iniparser_freedict(ini);
#endif
Expand All @@ -133,60 +141,87 @@ 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) {
#if defined(CAMERA_CONTROL_USE_CL_DRIVER)
if (autoE >= 0)
CLEyeSetCameraParameter(cc->camera, CLEYE_AUTO_EXPOSURE, autoE > 0);
if (autoG >= 0)
CLEyeSetCameraParameter(cc->camera, CLEYE_AUTO_GAIN, autoG > 0);
if (autoWB >= 0)
CLEyeSetCameraParameter(cc->camera, CLEYE_AUTO_WHITEBALANCE, autoWB > 0);
if (exposure >= 0)
CLEyeSetCameraParameter(cc->camera, CLEYE_EXPOSURE, round((511 * exposure) / 0xFFFF));
if (gain >= 0)
CLEyeSetCameraParameter(cc->camera, CLEYE_GAIN, round((79 * gain) / 0xFFFF));
if (wbRed >= 0)
CLEyeSetCameraParameter(cc->camera, CLEYE_WHITEBALANCE_RED, round((255 * wbRed) / 0xFFFF));
if (wbGreen >= 0)
CLEyeSetCameraParameter(cc->camera, CLEYE_WHITEBALANCE_GREEN, round((255 * wbGreen) / 0xFFFF));
if (wbBlue >= 0)
CLEyeSetCameraParameter(cc->camera, CLEYE_WHITEBALANCE_BLUE, round((255 * wbBlue) / 0xFFFF));
if (autoE >= 0){
CLEyeSetCameraParameter(cc->camera, CLEYE_AUTO_EXPOSURE, autoE > 0);
}
if (autoG >= 0){
CLEyeSetCameraParameter(cc->camera, CLEYE_AUTO_GAIN, autoG > 0);
}
if (autoWB >= 0){
CLEyeSetCameraParameter(cc->camera, CLEYE_AUTO_WHITEBALANCE, autoWB > 0);
}
if (exposure >= 0){
CLEyeSetCameraParameter(cc->camera, CLEYE_EXPOSURE, round((511 * exposure) / 0xFFFF));
}
if (gain >= 0){
CLEyeSetCameraParameter(cc->camera, CLEYE_GAIN, round((79 * gain) / 0xFFFF));
}
if (wbRed >= 0){
CLEyeSetCameraParameter(cc->camera, CLEYE_WHITEBALANCE_RED, round((255 * wbRed) / 0xFFFF));
}
if (wbGreen >= 0){
CLEyeSetCameraParameter(cc->camera, CLEYE_WHITEBALANCE_GREEN, round((255 * wbGreen) / 0xFFFF));
}
if (wbBlue >= 0){
CLEyeSetCameraParameter(cc->camera, CLEYE_WHITEBALANCE_BLUE, round((255 * wbBlue) / 0xFFFF));
}
#elif defined(PSMOVE_USE_PSEYE)
int val;
HKEY hKey;
DWORD l = sizeof(DWORD);
char* PATH = CL_DRIVER_REG_PATH;
int err = RegOpenKeyEx(HKEY_CURRENT_USER, PATH, 0, KEY_ALL_ACCESS, &hKey);
if (err != ERROR_SUCCESS) {
printf("Error: %d Unable to open reg-key: [HKCU]\%s!", err, PATH);
return;
}
val = autoE > 0;
RegSetValueExA(hKey, "AutoAEC", 0, REG_DWORD, (CONST BYTE*) &val, l);
val = autoG > 0;
RegSetValueExA(hKey, "AutoAGC", 0, REG_DWORD, (CONST BYTE*) &val, l);
val = autoWB > 0;
RegSetValueExA(hKey, "AutoAWB", 0, REG_DWORD, (CONST BYTE*) &val, l);
val = round((511 * exposure) / 0xFFFF);
RegSetValueExA(hKey, "Exposure", 0, REG_DWORD, (CONST BYTE*) &val, l);
val = round((79 * gain) / 0xFFFF);
RegSetValueExA(hKey, "Gain", 0, REG_DWORD, (CONST BYTE*) &val, l);
val = round((255 * wbRed) / 0xFFFF);
RegSetValueExA(hKey, "WhiteBalanceR", 0, REG_DWORD, (CONST BYTE*) &val, l);
val = round((255 * wbGreen) / 0xFFFF);
RegSetValueExA(hKey, "WhiteBalanceG", 0, REG_DWORD, (CONST BYTE*) &val, l);
val = round((255 * wbBlue) / 0xFFFF);
RegSetValueExA(hKey, "WhiteBalanceB", 0, REG_DWORD, (CONST BYTE*) &val, l);

// restart the camera capture with openCv
if (cc->capture) {
int val;
HKEY hKey;
DWORD l = sizeof(DWORD);
char* PATH = CL_DRIVER_REG_PATH;
int err = RegOpenKeyEx(HKEY_CURRENT_USER, PATH, 0, KEY_ALL_ACCESS, &hKey);
if (err != ERROR_SUCCESS) {
printf("Error: %d Unable to open reg-key: [HKCU]\%s!", err, PATH);
return;
}
val = autoE > 0;
RegSetValueExA(hKey, "AutoAEC", 0, REG_DWORD, (CONST BYTE*) &val, l);
val = autoG > 0;
RegSetValueExA(hKey, "AutoAGC", 0, REG_DWORD, (CONST BYTE*) &val, l);
val = autoWB > 0;
RegSetValueExA(hKey, "AutoAWB", 0, REG_DWORD, (CONST BYTE*) &val, l);
val = round((511 * exposure) / 0xFFFF);
RegSetValueExA(hKey, "Exposure", 0, REG_DWORD, (CONST BYTE*) &val, l);
val = round((79 * gain) / 0xFFFF);
RegSetValueExA(hKey, "Gain", 0, REG_DWORD, (CONST BYTE*) &val, l);
val = round((255 * wbRed) / 0xFFFF);
RegSetValueExA(hKey, "WhiteBalanceR", 0, REG_DWORD, (CONST BYTE*) &val, l);
val = round((255 * wbGreen) / 0xFFFF);
RegSetValueExA(hKey, "WhiteBalanceG", 0, REG_DWORD, (CONST BYTE*) &val, l);
val = round((255 * wbBlue) / 0xFFFF);
RegSetValueExA(hKey, "WhiteBalanceB", 0, REG_DWORD, (CONST BYTE*) &val, l);

// restart the camera capture with openCv
if (cc->capture) {
cvReleaseCapture(&cc->capture);
}

int width, height;
get_metrics(&width, &height);

cc->capture = cvCaptureFromCAM(cc->cameraID);
cvSetCaptureProperty(cc->capture, CV_CAP_PROP_FRAME_WIDTH, width);
cvSetCaptureProperty(cc->capture, CV_CAP_PROP_FRAME_HEIGHT, height);
ps3eye_set_parameter(cc->eye, PS3EYE_EXPOSURE, exposure);
/** Many of the values passed to this function do not work with PS3EYEDriver.
* comment out these functions until a sane value scheme is implemented.
* ps3eye_set_parameter(cc->eye, PS3EYE_AUTO_GAIN, autoG);
* ps3eye_set_parameter(cc->eye, PS3EYE_GAIN, gain);
* ps3eye_set_parameter(cc->eye, PS3EYE_AUTO_WHITEBALANCE, autoWB);
* ps3eye_set_parameter(cc->eye, PS3EYE_CONTRAST, contrast);
* ps3eye_set_parameter(cc->eye, PS3EYE_BRIGHTNESS, brightness);
* ps3eye_set_parameter(cc->eye, PS3EYE_REDBALANCE, wbRed);
* ps3eye_set_parameter(cc->eye, PS3EYE_BLUEBALANCE, wbGreen);
**/
psmove_WARNING("Only PS3EYEDriver parameter 'exposure' set by ps3eye_set_parameter.\n");
/** Some PS3EYEDriver parameters that could be set are not set by this function
* ps3eye_set_parameter(cc->eye, PS3EYE_SHARPNESS, autoG);
* ps3eye_set_parameter(cc->eye, PS3EYE_HUE, ???);
* ps3eye_set_parameter(cc->eye, PS3EYE_HFLIP, ??);
* ps3eye_set_parameter(cc->eye, PS3EYE_VFLIP, ??);
**/

int width, height;
get_metrics(&width, &height);

cc->capture = cvCaptureFromCAM(cc->cameraID);
cvSetCaptureProperty(cc->capture, CV_CAP_PROP_FRAME_WIDTH, width);
cvSetCaptureProperty(cc->capture, CV_CAP_PROP_FRAME_HEIGHT, height);
#endif
}

Loading