diff --git a/src/psmoveconfigtool/AppStage_ColorCalibration.cpp b/src/psmoveconfigtool/AppStage_ColorCalibration.cpp index 900a97c4..a0ed7e1c 100644 --- a/src/psmoveconfigtool/AppStage_ColorCalibration.cpp +++ b/src/psmoveconfigtool/AppStage_ColorCalibration.cpp @@ -142,7 +142,8 @@ AppStage_ColorCalibration::AppStage_ColorCalibration(App *app) , m_menuState(AppStage_ColorCalibration::inactive) , m_video_buffer_state(nullptr) , m_videoDisplayMode(AppStage_ColorCalibration::eVideoDisplayMode::mode_bgr) - , m_trackerFramerate(0) + , m_trackerFrameWidth(0) + , m_trackerFrameRate(0) , m_trackerExposure(0) , m_trackerGain(0) , m_bTurnOnAllControllers(false) @@ -386,7 +387,7 @@ void AppStage_ColorCalibration::renderUI() if (m_bShowWindows) { ImGui::SetNextWindowPos(ImVec2(10.f, 10.f)); - ImGui::SetNextWindowSize(ImVec2(k_panel_width, 260)); + ImGui::SetNextWindowSize(ImVec2(k_panel_width, 280)); ImGui::Begin(k_window_title, nullptr, window_flags); if (ImGui::Button("Return to Main Menu")) @@ -417,36 +418,75 @@ void AppStage_ColorCalibration::renderUI() } ImGui::SameLine(); ImGui::Text("Video [F]ilter Mode: %s", k_video_display_mode_names[m_videoDisplayMode]); + + if (ImGui::Button("-##FrameWidth")) + { + if (m_trackerFrameWidth == 640) request_tracker_set_frame_width(m_trackerFrameWidth - 320); + } + ImGui::SameLine(); + if (ImGui::Button("+##FrameWidth")) + { + if (m_trackerFrameWidth == 320) request_tracker_set_frame_width(m_trackerFrameWidth + 320); + } + ImGui::SameLine(); + ImGui::Text("Frame Width: %.0f", m_trackerFrameWidth); int frame_rate_positive_change = 10; int frame_rate_negative_change = -10; - double val = m_trackerFramerate; - - if (val == 2) { frame_rate_positive_change = 1; frame_rate_negative_change = 0; } - else if (val == 3) { frame_rate_positive_change = 2; frame_rate_negative_change = -1; } - else if (val == 5) { frame_rate_positive_change = 3; frame_rate_negative_change = -0; } - else if (val == 8) { frame_rate_positive_change = 2; frame_rate_negative_change = -3; } - else if (val == 10) { frame_rate_positive_change = 5; frame_rate_negative_change = -2; } - else if (val == 15) { frame_rate_positive_change = 5; frame_rate_negative_change = -5; } - else if (val == 20) { frame_rate_positive_change = 5; frame_rate_negative_change = -5; } - else if (val == 25) { frame_rate_positive_change = 5; frame_rate_negative_change = -5; } - else if (val == 30) { { frame_rate_negative_change = -5; } } - else if (val == 60) { { frame_rate_positive_change = 15; } } - else if (val == 75) { frame_rate_positive_change = 0; frame_rate_negative_change = -15; } - else if (val == 83) { frame_rate_positive_change = 0; frame_rate_negative_change = -8; } - - if (ImGui::Button("-##Framerate")) + double val = m_trackerFrameRate; + if (m_trackerFrameWidth == 320) + { + if (val == 2) { frame_rate_positive_change = 1; frame_rate_negative_change = 0; } + else if (val == 3) { frame_rate_positive_change = 2; frame_rate_negative_change = -1; } + else if (val == 5) { frame_rate_positive_change = 2; frame_rate_negative_change = -0; } + else if (val == 7) { frame_rate_positive_change = 3; frame_rate_negative_change = -2; } + else if (val == 10) { frame_rate_positive_change = 2; frame_rate_negative_change = -3; } + else if (val == 12) { frame_rate_positive_change = 3; frame_rate_negative_change = -2; } + else if (val == 15) { frame_rate_positive_change = 4; frame_rate_negative_change = -3; } + else if (val == 17) { frame_rate_positive_change = 13; frame_rate_negative_change = -4; } + else if (val == 30) { frame_rate_positive_change = 7; frame_rate_negative_change = -13; } + else if (val == 37) { frame_rate_positive_change = 3; frame_rate_negative_change = -7; } + else if (val == 40) { frame_rate_positive_change = 10; frame_rate_negative_change = -3; } + else if (val == 50) { frame_rate_positive_change = 10; frame_rate_negative_change = -10; } + else if (val == 60) { frame_rate_positive_change = 15; frame_rate_negative_change = -10; } + else if (val == 75) { frame_rate_positive_change = 15; frame_rate_negative_change = -15; } + else if (val == 90) { frame_rate_positive_change = 10; frame_rate_negative_change = -15; } + else if (val == 100) { frame_rate_positive_change = 25; frame_rate_negative_change = -10; } + else if (val == 125) { frame_rate_positive_change = 12; frame_rate_negative_change = -25; } + else if (val == 137) { frame_rate_positive_change = 13; frame_rate_negative_change = -12; } + else if (val == 150) { frame_rate_positive_change = 37; frame_rate_negative_change = -13; } + else if (val == 187) { frame_rate_positive_change = 0; frame_rate_negative_change = -37; } + else if (val == 205) { frame_rate_positive_change = 0; frame_rate_negative_change = -18; } + else if (val == 290) { frame_rate_positive_change = 0; frame_rate_negative_change = -85; } + } + else { - request_tracker_set_frame_rate(m_trackerFramerate + frame_rate_negative_change); + if (val == 2) { frame_rate_positive_change = 1; frame_rate_negative_change = 0; } + else if (val == 3) { frame_rate_positive_change = 2; frame_rate_negative_change = -1; } + else if (val == 5) { frame_rate_positive_change = 3; frame_rate_negative_change = -0; } + else if (val == 8) { frame_rate_positive_change = 2; frame_rate_negative_change = -3; } + else if (val == 10) { frame_rate_positive_change = 5; frame_rate_negative_change = -2; } + else if (val == 15) { frame_rate_positive_change = 5; frame_rate_negative_change = -5; } + else if (val == 20) { frame_rate_positive_change = 5; frame_rate_negative_change = -5; } + else if (val == 25) { frame_rate_positive_change = 5; frame_rate_negative_change = -5; } + else if (val == 30) { { frame_rate_negative_change = -5; } } + else if (val == 60) { { frame_rate_positive_change = 15; } } + else if (val == 75) { frame_rate_positive_change = 0; frame_rate_negative_change = -15; } + else if (val == 83) { frame_rate_positive_change = 0; frame_rate_negative_change = -8; } + } + + if (ImGui::Button("-##FrameRate")) + { + request_tracker_set_frame_rate(m_trackerFrameRate + frame_rate_negative_change); } ImGui::SameLine(); - if (ImGui::Button("+##Framerate")) + if (ImGui::Button("+##FrameRate")) { - request_tracker_set_frame_rate(m_trackerFramerate + frame_rate_positive_change); + request_tracker_set_frame_rate(m_trackerFrameRate + frame_rate_positive_change); } ImGui::SameLine(); - ImGui::Text("Framerate: %.0f", m_trackerFramerate); + ImGui::Text("Frame Rate: %.0f", m_trackerFrameRate); if (ImGui::Button("-##Exposure")) { @@ -768,14 +808,10 @@ void AppStage_ColorCalibration::renderUI() } break; case eMenuState::blank1: - setState(eMenuState::blank3); - std::this_thread::sleep_for(std::chrono::milliseconds(auto_calib_sleep)); - break; - case eMenuState::blank2: setState(eMenuState::blank2); std::this_thread::sleep_for(std::chrono::milliseconds(auto_calib_sleep)); break; - case eMenuState::blank3: + case eMenuState::blank2: setState(eMenuState::autoConfig); std::this_thread::sleep_for(std::chrono::milliseconds(auto_calib_sleep)); break; @@ -1026,11 +1062,54 @@ void AppStage_ColorCalibration::release_video_buffers() m_video_buffer_state = nullptr; } +void AppStage_ColorCalibration::request_tracker_set_frame_width(double value) +{ + // Tell the psmove service that we want to change frame width. + RequestPtr request(new PSMoveProtocol::Request()); + request->set_type(PSMoveProtocol::Request_RequestType_SET_TRACKER_FRAME_WIDTH); + request->mutable_request_set_tracker_frame_width()->set_tracker_id(m_trackerView->tracker_info.tracker_id); + request->mutable_request_set_tracker_frame_width()->set_value(static_cast(value)); + request->mutable_request_set_tracker_frame_width()->set_save_setting(true); + + PSMRequestID request_id; + PSM_SendOpaqueRequest(&request, &request_id); + PSM_RegisterCallback(request_id, AppStage_ColorCalibration::handle_tracker_set_frame_width_response, this); + + // Exit and re-enter Color Calibration + m_app->getAppStage()->gotoColorCalib(); + request_exit_to_app_stage(AppStage_TrackerSettings::APP_STAGE_NAME); +} + +void AppStage_ColorCalibration::handle_tracker_set_frame_width_response( + const PSMResponseMessage *response, + void *userdata) +{ + PSMResult ResultCode = response->result_code; + PSMResponseHandle response_handle = response->opaque_response_handle; + AppStage_ColorCalibration *thisPtr = static_cast(userdata); + + switch (ResultCode) + { + case PSMResult_Success: + { + const PSMoveProtocol::Response *response = GET_PSMOVEPROTOCOL_RESPONSE(response_handle); + thisPtr->m_trackerFrameWidth = response->result_set_tracker_frame_width().new_frame_width(); + } break; + case PSMResult_Error: + case PSMResult_Canceled: + case PSMResult_Timeout: + { + //###HipsterSloth $TODO - Replace with C_API style log + //CLIENT_LOG_INFO("AppStage_ColorCalibration") << "Failed to set the tracker frame width!"; + } break; + } +} + void AppStage_ColorCalibration::request_tracker_set_frame_rate(double value) { // Tell the psmove service that we want to change frame rate. RequestPtr request(new PSMoveProtocol::Request()); - request->set_type(PSMoveProtocol::Request_RequestType_SET_TRACKER_FRAMERATE); + request->set_type(PSMoveProtocol::Request_RequestType_SET_TRACKER_FRAME_RATE); request->mutable_request_set_tracker_frame_rate()->set_tracker_id(m_trackerView->tracker_info.tracker_id); request->mutable_request_set_tracker_frame_rate()->set_value(static_cast(value)); request->mutable_request_set_tracker_frame_rate()->set_save_setting(true); @@ -1053,7 +1132,7 @@ void AppStage_ColorCalibration::handle_tracker_set_frame_rate_response( case PSMResult_Success: { const PSMoveProtocol::Response *response = GET_PSMOVEPROTOCOL_RESPONSE(response_handle); - thisPtr->m_trackerFramerate = response->result_set_tracker_frame_rate().new_frame_rate(); + thisPtr->m_trackerFrameRate = response->result_set_tracker_frame_rate().new_frame_rate(); } break; case PSMResult_Error: case PSMResult_Canceled: @@ -1307,7 +1386,8 @@ void AppStage_ColorCalibration::handle_tracker_get_settings_response( case PSMResult_Success: { const PSMoveProtocol::Response *response = GET_PSMOVEPROTOCOL_RESPONSE(response_handle); - thisPtr->m_trackerFramerate = response->result_tracker_settings().frame_rate(); + thisPtr->m_trackerFrameWidth = response->result_tracker_settings().frame_width(); + thisPtr->m_trackerFrameRate = response->result_tracker_settings().frame_rate(); thisPtr->m_trackerExposure = response->result_tracker_settings().exposure(); thisPtr->m_trackerGain = response->result_tracker_settings().gain(); @@ -1496,7 +1576,7 @@ void AppStage_ColorCalibration::request_change_controller(int step) void AppStage_ColorCalibration::request_change_tracker(int step) { m_app->getAppStage()-> - set_autoConfig(m_bAutoChangeColor, m_bAutoChangeController, m_bAutoChangeTracker); + set_autoConfig(m_bAutoChangeColor, m_bAutoChangeController, m_bAutoChangeTracker); //int TrackerId = m_trackerView->tracker_info.tracker_id; if (tracker_index + step < tracker_count && tracker_index + step >= 0) { diff --git a/src/psmoveconfigtool/AppStage_ColorCalibration.h b/src/psmoveconfigtool/AppStage_ColorCalibration.h index 53ec16fd..b5c13192 100644 --- a/src/psmoveconfigtool/AppStage_ColorCalibration.h +++ b/src/psmoveconfigtool/AppStage_ColorCalibration.h @@ -48,7 +48,6 @@ class AppStage_ColorCalibration : public AppStage autoConfig, blank1, blank2, - blank3, changeController, changeTracker, @@ -107,6 +106,11 @@ class AppStage_ColorCalibration : public AppStage const PSMResponseMessage *response, void *userdata); + void request_tracker_set_frame_width(double value); + static void handle_tracker_set_frame_width_response( + const PSMResponseMessage *response, + void *userdata); + void request_tracker_set_frame_rate(double value); static void handle_tracker_set_frame_rate_response( const PSMResponseMessage *response, @@ -150,6 +154,7 @@ class AppStage_ColorCalibration : public AppStage void request_change_controller(int step); void request_change_tracker(int step); + void request_refresh_tracker(); inline TrackerColorPreset getColorPreset() { return m_colorPresets[m_masterTrackingColorType]; } @@ -176,7 +181,8 @@ class AppStage_ColorCalibration : public AppStage eVideoDisplayMode m_videoDisplayMode; // Tracker Settings state - double m_trackerFramerate; + double m_trackerFrameWidth; + double m_trackerFrameRate; double m_trackerExposure; double m_trackerGain; std::vector m_trackerOptions; diff --git a/src/psmoveconfigtool/AppStage_TrackerSettings.cpp b/src/psmoveconfigtool/AppStage_TrackerSettings.cpp index da7259cc..d7a00068 100644 --- a/src/psmoveconfigtool/AppStage_TrackerSettings.cpp +++ b/src/psmoveconfigtool/AppStage_TrackerSettings.cpp @@ -28,6 +28,7 @@ AppStage_TrackerSettings::AppStage_TrackerSettings(App *app) , m_selectedTrackerIndex(-1) , m_selectedControllerIndex(-1) , m_selectedHmdIndex(-1) + , m_gotoColorCalib(false) { } void AppStage_TrackerSettings::enter() @@ -329,7 +330,7 @@ void AppStage_TrackerSettings::renderUI() if (m_app->getIsLocalServer()) { - if (ImGui::Button("Calibrate Controller Tracking Colors")) + if (ImGui::Button("Calibrate Controller Tracking Colors") || m_gotoColorCalib) { const ControllerInfo *controller = get_selected_controller(); if (controller != NULL) { diff --git a/src/psmoveconfigtool/AppStage_TrackerSettings.h b/src/psmoveconfigtool/AppStage_TrackerSettings.h index 8a1ed6fa..a73977b2 100644 --- a/src/psmoveconfigtool/AppStage_TrackerSettings.h +++ b/src/psmoveconfigtool/AppStage_TrackerSettings.h @@ -49,6 +49,8 @@ class AppStage_TrackerSettings : public AppStage static const char *APP_STAGE_NAME; + void gotoColorCalib() { m_gotoColorCalib = true; } + protected: virtual bool onClientAPIEvent( PSMEventMessage::eEventType event, @@ -97,6 +99,8 @@ class AppStage_TrackerSettings : public AppStage int m_selectedTrackerIndex; int m_selectedControllerIndex; int m_selectedHmdIndex; + + bool m_gotoColorCalib; }; #endif // APP_STAGE_TRACKER_SETTINGS_H \ No newline at end of file diff --git a/src/psmoveprotocol/PSMoveProtocol.proto b/src/psmoveprotocol/PSMoveProtocol.proto index a1374905..edca5a6c 100644 --- a/src/psmoveprotocol/PSMoveProtocol.proto +++ b/src/psmoveprotocol/PSMoveProtocol.proto @@ -152,7 +152,9 @@ message Request { GET_SERVICE_VERSION= 39; - SET_TRACKER_FRAMERATE = 40; + SET_TRACKER_FRAME_RATE = 40; + SET_TRACKER_FRAME_WIDTH = 41; + SET_TRACKER_FRAME_HEIGHT = 42; } RequestType type = 2; @@ -439,13 +441,29 @@ message Request { } RequestSetHMDPredictionTime request_set_hmd_prediction_time = 37; - // Parameters for SET_TRACKER_FRAMERATE - message RequestSetTrackerFramerate { + // Parameters for SET_TRACKER_FRAME_RATE + message RequestSetTrackerFrameRate { int32 tracker_id = 1; float value = 2; bool save_setting= 3; } - RequestSetTrackerFramerate request_set_tracker_frame_rate = 38; + RequestSetTrackerFrameRate request_set_tracker_frame_rate = 38; + + // Parameters for SET_TRACKER_FRAME_WIDTH + message RequestSetTrackerFrameWidth { + int32 tracker_id = 1; + float value = 2; + bool save_setting= 3; + } + RequestSetTrackerFrameWidth request_set_tracker_frame_width = 39; + + // Parameters for SET_TRACKER_FRAME_HEIGHT + message RequestSetTrackerFrameHeight { + int32 tracker_id = 1; + float value = 2; + bool save_setting= 3; + } + RequestSetTrackerFrameHeight request_set_tracker_frame_height = 40; } // Reliable (TCP) responses to requests @@ -471,7 +489,9 @@ message Response { HMD_LIST= 16; HMD_LIST_UPDATED= 17; SERVICE_VERSION= 18; - TRACKER_FRAMERATE_UPDATED= 19; + TRACKER_FRAME_RATE_UPDATED= 19; + TRACKER_FRAME_WIDTH_UPDATED= 20; + TRACKER_FRAME_HEIGHT_UPDATED= 21; } enum ResultCode { @@ -584,6 +604,8 @@ message Response { repeated OptionSet option_sets= 3; repeated TrackingColorPreset color_presets = 4; float frame_rate= 5; + float frame_width= 6; + float frame_height= 7; } ResultTrackerSettings result_tracker_settings = 25; @@ -642,11 +664,23 @@ message Response { } ResultServiceVersion result_service_version = 32; - // This is returned in response to a SET_TRACKER_FRAMERATE request - message ResultSetTrackerFramerate { + // This is returned in response to a SET_TRACKER_FRAME_RATE request + message ResultSetTrackerFrameRate { float new_frame_rate= 1; } - ResultSetTrackerFramerate result_set_tracker_frame_rate = 33; + ResultSetTrackerFrameRate result_set_tracker_frame_rate = 33; + + // This is returned in response to a SET_TRACKER_FRAME_WIDTH request + message ResultSetTrackerFrameWidth { + float new_frame_width= 1; + } + ResultSetTrackerFrameWidth result_set_tracker_frame_width = 34; + + // This is returned in response to a SET_TRACKER_FRAME_HEIGHT request + message ResultSetTrackerFrameHeight { + float new_frame_height= 1; + } + ResultSetTrackerFrameHeight result_set_tracker_frame_height = 35; } // Unreliable (UDP) device data packet sent from service to clients diff --git a/src/psmoveservice/Device/Interface/DeviceInterface.h b/src/psmoveservice/Device/Interface/DeviceInterface.h index 5a6ca8d5..851d10c9 100644 --- a/src/psmoveservice/Device/Interface/DeviceInterface.h +++ b/src/psmoveservice/Device/Interface/DeviceInterface.h @@ -546,8 +546,14 @@ class ITrackerInterface : public IDeviceInterface virtual void loadSettings() = 0; virtual void saveSettings() = 0; - virtual void setFramerate(double value, bool bUpdateConfig) = 0; - virtual double getFramerate() const = 0; + virtual void setFrameWidth(double value, bool bUpdateConfig) = 0; + virtual double getFrameWidth() const = 0; + + virtual void setFrameHeight(double value, bool bUpdateConfig) = 0; + virtual double getFrameHeight() const = 0; + + virtual void setFrameRate(double value, bool bUpdateConfig) = 0; + virtual double getFrameRate() const = 0; virtual void setExposure(double value, bool bUpdateConfig) = 0; virtual double getExposure() const = 0; diff --git a/src/psmoveservice/Device/Manager/TrackerManager.cpp b/src/psmoveservice/Device/Manager/TrackerManager.cpp index efd85e82..81e830c9 100644 --- a/src/psmoveservice/Device/Manager/TrackerManager.cpp +++ b/src/psmoveservice/Device/Manager/TrackerManager.cpp @@ -24,6 +24,8 @@ TrackerManagerConfig::TrackerManagerConfig(const std::string &fnamebase) exclude_opposed_cameras = false; min_valid_projection_area= 16; disable_roi = false; + default_tracker_profile.frame_width = 640; + //default_tracker_profile.frame_height = 480; default_tracker_profile.frame_rate = 40; default_tracker_profile.exposure = 32; default_tracker_profile.gain = 32; @@ -54,6 +56,8 @@ TrackerManagerConfig::config2ptree() pt.put("disable_roi", disable_roi); + pt.put("default_tracker_profile.frame_width", default_tracker_profile.frame_width); + //pt.put("default_tracker_profile.frame_height", default_tracker_profile.frame_height); pt.put("default_tracker_profile.frame_rate", default_tracker_profile.frame_rate); pt.put("default_tracker_profile.exposure", default_tracker_profile.exposure); pt.put("default_tracker_profile.gain", default_tracker_profile.gain); @@ -80,6 +84,8 @@ TrackerManagerConfig::ptree2config(const boost::property_tree::ptree &pt) exclude_opposed_cameras = pt.get("excluded_opposed_cameras", exclude_opposed_cameras); min_valid_projection_area = pt.get("min_valid_projection_area", min_valid_projection_area); disable_roi = pt.get("disable_roi", disable_roi); + default_tracker_profile.frame_width = pt.get("default_tracker_profile.frame_width", 640); + //default_tracker_profile.frame_height = pt.get("default_tracker_profile.frame_height", 480); default_tracker_profile.frame_rate = pt.get("default_tracker_profile.frame_rate", 40); default_tracker_profile.exposure = pt.get("default_tracker_profile.exposure", 32); default_tracker_profile.gain = pt.get("default_tracker_profile.gain", 32); diff --git a/src/psmoveservice/Device/Manager/TrackerManager.h b/src/psmoveservice/Device/Manager/TrackerManager.h index 0af039b2..1b0df25c 100644 --- a/src/psmoveservice/Device/Manager/TrackerManager.h +++ b/src/psmoveservice/Device/Manager/TrackerManager.h @@ -16,6 +16,8 @@ typedef std::shared_ptr ServerTrackerViewPtr; //-- definitions ----- struct TrackerProfile { + float frame_width; + //float frame_height; float frame_rate; float exposure; float gain; @@ -23,6 +25,8 @@ struct TrackerProfile inline void clear() { + frame_width = 0.f; + // frame_height = 0.f; frame_rate = 0.f; exposure = 0.f; gain = 0; diff --git a/src/psmoveservice/Device/View/ServerTrackerView.cpp b/src/psmoveservice/Device/View/ServerTrackerView.cpp index 34a551f5..5236dc20 100644 --- a/src/psmoveservice/Device/View/ServerTrackerView.cpp +++ b/src/psmoveservice/Device/View/ServerTrackerView.cpp @@ -978,14 +978,110 @@ void ServerTrackerView::saveSettings() m_device->saveSettings(); } -double ServerTrackerView::getFramerate() const +double ServerTrackerView::getFrameWidth() const { - return m_device->getFramerate(); + return m_device->getFrameWidth(); } -void ServerTrackerView::setFramerate(double value, bool bUpdateConfig) +void ServerTrackerView::setFrameWidth(double value, bool bUpdateConfig) { - m_device->setFramerate(value, bUpdateConfig); + if (value == m_device->getFrameWidth()) return; + + // close buffer + if (m_shared_memory_accesor != nullptr) + { + delete m_shared_memory_accesor; + m_shared_memory_accesor = nullptr; + } + + // change frame width + m_device->setFrameWidth(value, bUpdateConfig); + + // reopen buffer + int width, height, stride; + + // Make sure the shared memory block has been removed first + boost::interprocess::shared_memory_object::remove(m_shared_memory_name); + + // Query the video frame first so that we know how big to make the buffer + if (m_device->getVideoFrameDimensions(&width, &height, &stride)) + { + assert(m_shared_memory_accesor == nullptr); + m_shared_memory_accesor = new SharedVideoFrameReadWriteAccessor(); + + if (!m_shared_memory_accesor->initialize(m_shared_memory_name, width, height, stride)) + { + delete m_shared_memory_accesor; + m_shared_memory_accesor = nullptr; + + SERVER_LOG_ERROR("ServerTrackerView::open()") << "Failed to allocated shared memory: " << m_shared_memory_name; + } + + // Allocate the OpenCV scratch buffers used for finding tracking blobs + m_opencv_buffer_state = new OpenCVBufferState(m_device); + } + else + { + SERVER_LOG_ERROR("ServerTrackerView::open()") << "Failed to video frame dimensions"; + } +} + +double ServerTrackerView::getFrameHeight() const +{ + return m_device->getFrameHeight(); +} + +void ServerTrackerView::setFrameHeight(double value, bool bUpdateConfig) +{ + if (value == m_device->getFrameHeight()) return; + + // close buffer + if (m_shared_memory_accesor != nullptr) + { + delete m_shared_memory_accesor; + m_shared_memory_accesor = nullptr; + } + + // change frame height + m_device->setFrameHeight(value, bUpdateConfig); + + // reopen buffer + int width, height, stride; + + // Make sure the shared memory block has been removed first + boost::interprocess::shared_memory_object::remove(m_shared_memory_name); + + // Query the video frame first so that we know how big to make the buffer + if (m_device->getVideoFrameDimensions(&width, &height, &stride)) + { + assert(m_shared_memory_accesor == nullptr); + m_shared_memory_accesor = new SharedVideoFrameReadWriteAccessor(); + + if (!m_shared_memory_accesor->initialize(m_shared_memory_name, width, height, stride)) + { + delete m_shared_memory_accesor; + m_shared_memory_accesor = nullptr; + + SERVER_LOG_ERROR("ServerTrackerView::open()") << "Failed to allocated shared memory: " << m_shared_memory_name; + } + + // Allocate the OpenCV scratch buffers used for finding tracking blobs + m_opencv_buffer_state = new OpenCVBufferState(m_device); + } + else + { + SERVER_LOG_ERROR("ServerTrackerView::open()") << "Failed to video frame dimensions"; + } +} + +double ServerTrackerView::getFrameRate() const +{ + return m_device->getFrameRate(); +} + +void ServerTrackerView::setFrameRate(double value, bool bUpdateConfig) +{ + m_device->setFrameRate(value, bUpdateConfig); } double ServerTrackerView::getExposure() const diff --git a/src/psmoveservice/Device/View/ServerTrackerView.h b/src/psmoveservice/Device/View/ServerTrackerView.h index bb35801d..f30fab9b 100644 --- a/src/psmoveservice/Device/View/ServerTrackerView.h +++ b/src/psmoveservice/Device/View/ServerTrackerView.h @@ -48,8 +48,14 @@ class ServerTrackerView : public ServerDeviceView void loadSettings(); void saveSettings(); - double getFramerate() const; - void setFramerate(double value, bool bUpdateConfig); + double getFrameWidth() const; + void setFrameWidth(double value, bool bUpdateConfig); + + double getFrameHeight() const; + void setFrameHeight(double value, bool bUpdateConfig); + + double getFrameRate() const; + void setFrameRate(double value, bool bUpdateConfig); double getExposure() const; void setExposure(double value, bool bUpdateConfig); diff --git a/src/psmoveservice/PSMoveTracker/PS3EyeTracker.cpp b/src/psmoveservice/PSMoveTracker/PS3EyeTracker.cpp index 6c5db996..33208de8 100644 --- a/src/psmoveservice/PSMoveTracker/PS3EyeTracker.cpp +++ b/src/psmoveservice/PSMoveTracker/PS3EyeTracker.cpp @@ -37,6 +37,8 @@ PS3EyeTrackerConfig::PS3EyeTrackerConfig(const std::string &fnamebase) : PSMoveConfig(fnamebase) , is_valid(false) , max_poll_failure_count(100) + , frame_width(640) + , frame_height(480) , frame_rate(40) , exposure(32) , gain(32) @@ -73,6 +75,8 @@ PS3EyeTrackerConfig::config2ptree() pt.put("version", PS3EyeTrackerConfig::CONFIG_VERSION); pt.put("lens_calibration_version", PS3EyeTrackerConfig::LENS_CALIBRATION_VERSION); pt.put("max_poll_failure_count", max_poll_failure_count); + pt.put("frame_width", frame_width); + pt.put("frame_height", frame_height); pt.put("frame_rate", frame_rate); pt.put("exposure", exposure); pt.put("gain", gain); @@ -117,6 +121,8 @@ PS3EyeTrackerConfig::ptree2config(const boost::property_tree::ptree &pt) { is_valid = pt.get("is_valid", false); max_poll_failure_count = pt.get("max_poll_failure_count", 100); + frame_width = pt.get("frame_width", 640); + frame_height = pt.get("frame_height", 480); frame_rate = pt.get("frame_rate", 40); exposure = pt.get("exposure", 32); gain = pt.get("gain", 32); @@ -353,6 +359,7 @@ bool PS3EyeTracker::open(const DeviceEnumerator *enumerator) // Save the config back out again in case defaults changed cfg.save(); + VideoCapture->set(cv::CAP_PROP_FRAME_WIDTH, cfg.frame_width); VideoCapture->set(cv::CAP_PROP_EXPOSURE, cfg.exposure); VideoCapture->set(cv::CAP_PROP_GAIN, cfg.gain); VideoCapture->set(cv::CAP_PROP_FPS, cfg.frame_rate); @@ -529,12 +536,18 @@ const unsigned char *PS3EyeTracker::getVideoFrameBuffer() const void PS3EyeTracker::loadSettings() { - const double currentFramerate = VideoCapture->get(cv::CAP_PROP_FPS); + const double currentFrameWidth = VideoCapture->get(cv::CAP_PROP_FRAME_WIDTH); + const double currentFrameRate = VideoCapture->get(cv::CAP_PROP_FPS); const double currentExposure= VideoCapture->get(cv::CAP_PROP_EXPOSURE); const double currentGain= VideoCapture->get(cv::CAP_PROP_GAIN); cfg.load(); + if (currentFrameWidth != cfg.frame_width) + { + VideoCapture->set(cv::CAP_PROP_FRAME_WIDTH, cfg.frame_width); + } + if (currentExposure != cfg.exposure) { VideoCapture->set(cv::CAP_PROP_EXPOSURE, cfg.exposure); @@ -545,7 +558,7 @@ void PS3EyeTracker::loadSettings() VideoCapture->set(cv::CAP_PROP_GAIN, cfg.gain); } - if (currentFramerate != cfg.frame_rate) + if (currentFrameRate != cfg.frame_rate) { VideoCapture->set(cv::CAP_PROP_FPS, cfg.frame_rate); } @@ -556,7 +569,37 @@ void PS3EyeTracker::saveSettings() cfg.save(); } -void PS3EyeTracker::setFramerate(double value, bool bUpdateConfig) +void PS3EyeTracker::setFrameWidth(double value, bool bUpdateConfig) +{ + VideoCapture->set(cv::CAP_PROP_FRAME_WIDTH, value); + + if (bUpdateConfig) + { + cfg.frame_width = value; + } +} + +double PS3EyeTracker::getFrameWidth() const +{ + return VideoCapture->get(cv::CAP_PROP_FRAME_WIDTH); +} + +void PS3EyeTracker::setFrameHeight(double value, bool bUpdateConfig) +{ + VideoCapture->set(cv::CAP_PROP_FRAME_HEIGHT, value); + + if (bUpdateConfig) + { + cfg.frame_height = value; + } +} + +double PS3EyeTracker::getFrameHeight() const +{ + return VideoCapture->get(cv::CAP_PROP_FRAME_HEIGHT); +} + +void PS3EyeTracker::setFrameRate(double value, bool bUpdateConfig) { VideoCapture->set(cv::CAP_PROP_FPS, value); @@ -566,7 +609,7 @@ void PS3EyeTracker::setFramerate(double value, bool bUpdateConfig) } } -double PS3EyeTracker::getFramerate() const +double PS3EyeTracker::getFrameRate() const { return VideoCapture->get(cv::CAP_PROP_FPS); } diff --git a/src/psmoveservice/PSMoveTracker/PS3EyeTracker.h b/src/psmoveservice/PSMoveTracker/PS3EyeTracker.h index 5e6a2115..6e3896bc 100644 --- a/src/psmoveservice/PSMoveTracker/PS3EyeTracker.h +++ b/src/psmoveservice/PSMoveTracker/PS3EyeTracker.h @@ -37,6 +37,8 @@ class PS3EyeTrackerConfig : public PSMoveConfig bool is_valid; long max_poll_failure_count; + double frame_width; + double frame_height; double frame_rate; double exposure; double gain; @@ -105,8 +107,12 @@ class PS3EyeTracker : public ITrackerInterface { const unsigned char *getVideoFrameBuffer() const override; void loadSettings() override; void saveSettings() override; - void setFramerate(double value, bool bUpdateConfig) override; - double getFramerate() const override; + void setFrameWidth(double value, bool bUpdateConfig) override; + double getFrameWidth() const override; + void setFrameHeight(double value, bool bUpdateConfig) override; + double getFrameHeight() const override; + void setFrameRate(double value, bool bUpdateConfig) override; + double getFrameRate() const override; void setExposure(double value, bool bUpdateConfig) override; double getExposure() const override; void setGain(double value, bool bUpdateConfig) override; diff --git a/src/psmoveservice/PSMoveTracker/PSEye/PSEyeVideoCapture.cpp b/src/psmoveservice/PSMoveTracker/PSEye/PSEyeVideoCapture.cpp index d620bad4..a51ead29 100644 --- a/src/psmoveservice/PSMoveTracker/PSEye/PSEyeVideoCapture.cpp +++ b/src/psmoveservice/PSMoveTracker/PSEye/PSEyeVideoCapture.cpp @@ -332,9 +332,17 @@ class PSEYECaptureCAM_PS3EYE : public cv::IVideoCapture eye->start(); break; case CV_CAP_PROP_FRAME_HEIGHT: - return false; //TODO: Modifying frame size probably requires resetting the camera + eye->stop(); + if (!eye->setHeight((int)round(value))) return false; + eye->start(); + break; + //return false; //TODO: Modifying frame size probably requires resetting the camera case CV_CAP_PROP_FRAME_WIDTH: - return false; + eye->stop(); + if (!eye->setWidth((int)round(value))) return false; + eye->start(); + break; + //return false; case CV_CAP_PROP_GAIN: // [0, 255] -> [0, 63] [20] val = (int)(value * 64.0 / 256.0); diff --git a/src/psmoveservice/Server/ServerRequestHandler.cpp b/src/psmoveservice/Server/ServerRequestHandler.cpp index 432784d2..f934645f 100644 --- a/src/psmoveservice/Server/ServerRequestHandler.cpp +++ b/src/psmoveservice/Server/ServerRequestHandler.cpp @@ -261,7 +261,15 @@ class ServerRequestHandlerImpl response = new PSMoveProtocol::Response; handle_request__get_tracker_settings(context, response); break; - case PSMoveProtocol::Request_RequestType_SET_TRACKER_FRAMERATE: + case PSMoveProtocol::Request_RequestType_SET_TRACKER_FRAME_WIDTH: + response = new PSMoveProtocol::Response; + handle_request__set_tracker_frame_width(context, response); + break; + case PSMoveProtocol::Request_RequestType_SET_TRACKER_FRAME_HEIGHT: + response = new PSMoveProtocol::Response; + handle_request__set_tracker_frame_height(context, response); + break; + case PSMoveProtocol::Request_RequestType_SET_TRACKER_FRAME_RATE: response = new PSMoveProtocol::Response; handle_request__set_tracker_frame_rate(context, response); break; @@ -1724,7 +1732,9 @@ class ServerRequestHandlerImpl response->mutable_result_tracker_settings(); const int device_id = context.request->request_get_tracker_settings().device_id(); - settings->set_frame_rate(static_cast(tracker_view->getFramerate())); + settings->set_frame_width(static_cast(tracker_view->getFrameWidth())); + settings->set_frame_height(static_cast(tracker_view->getFrameHeight())); + settings->set_frame_rate(static_cast(tracker_view->getFrameRate())); settings->set_exposure(static_cast(tracker_view->getExposure())); settings->set_gain(static_cast(tracker_view->getGain())); tracker_view->gatherTrackerOptions(settings); @@ -1758,12 +1768,104 @@ class ServerRequestHandlerImpl } } + void handle_request__set_tracker_frame_width(const RequestContext &context, + PSMoveProtocol::Response *response) + { + const int tracker_id = context.request->request_set_tracker_frame_width().tracker_id(); + + response->set_type(PSMoveProtocol::Response_ResponseType_TRACKER_FRAME_WIDTH_UPDATED); + + if (ServerUtility::is_index_valid(tracker_id, m_device_manager.getTrackerViewMaxCount())) + { + ServerTrackerViewPtr tracker_view = m_device_manager.getTrackerViewPtr(tracker_id); + if (tracker_view->getIsOpen()) + { + const bool bSaveSetting = context.request->request_set_tracker_frame_width().save_setting(); + const float desired_frame_width = context.request->request_set_tracker_frame_width().value(); + PSMoveProtocol::Response_ResultSetTrackerFrameWidth* result_frame_width = + response->mutable_result_set_tracker_frame_width(); + + // Set the desired frame width on the tracker + tracker_view->setFrameWidth(desired_frame_width, bSaveSetting); + + // Only save the setting if requested + if (bSaveSetting) + { + tracker_view->saveSettings(); + } + else + { + context.connection_state->active_tracker_stream_info[tracker_id].has_temp_settings_override = true; + } + + // Return back the actual frame width that got set + result_frame_width->set_new_frame_width(static_cast(tracker_view->getFrameWidth())); + + response->set_result_code(PSMoveProtocol::Response_ResultCode_RESULT_OK); + } + else + { + response->set_result_code(PSMoveProtocol::Response_ResultCode_RESULT_ERROR); + } + } + else + { + response->set_result_code(PSMoveProtocol::Response_ResultCode_RESULT_ERROR); + } + } + + void handle_request__set_tracker_frame_height(const RequestContext &context, + PSMoveProtocol::Response *response) + { + const int tracker_id = context.request->request_set_tracker_frame_height().tracker_id(); + + response->set_type(PSMoveProtocol::Response_ResponseType_TRACKER_FRAME_HEIGHT_UPDATED); + + if (ServerUtility::is_index_valid(tracker_id, m_device_manager.getTrackerViewMaxCount())) + { + ServerTrackerViewPtr tracker_view = m_device_manager.getTrackerViewPtr(tracker_id); + if (tracker_view->getIsOpen()) + { + const bool bSaveSetting = context.request->request_set_tracker_frame_height().save_setting(); + const float desired_frame_height = context.request->request_set_tracker_frame_height().value(); + PSMoveProtocol::Response_ResultSetTrackerFrameHeight* result_frame_height = + response->mutable_result_set_tracker_frame_height(); + + // Set the desired frame height on the tracker + tracker_view->setFrameHeight(desired_frame_height, bSaveSetting); + + // Only save the setting if requested + if (bSaveSetting) + { + tracker_view->saveSettings(); + } + else + { + context.connection_state->active_tracker_stream_info[tracker_id].has_temp_settings_override = true; + } + + // Return back the actual frame height that got set + result_frame_height->set_new_frame_height(static_cast(tracker_view->getFrameHeight())); + + response->set_result_code(PSMoveProtocol::Response_ResultCode_RESULT_OK); + } + else + { + response->set_result_code(PSMoveProtocol::Response_ResultCode_RESULT_ERROR); + } + } + else + { + response->set_result_code(PSMoveProtocol::Response_ResultCode_RESULT_ERROR); + } + } + void handle_request__set_tracker_frame_rate(const RequestContext &context, PSMoveProtocol::Response *response) { const int tracker_id = context.request->request_set_tracker_frame_rate().tracker_id(); - response->set_type(PSMoveProtocol::Response_ResponseType_TRACKER_FRAMERATE_UPDATED); + response->set_type(PSMoveProtocol::Response_ResponseType_TRACKER_FRAME_RATE_UPDATED); if (ServerUtility::is_index_valid(tracker_id, m_device_manager.getTrackerViewMaxCount())) { @@ -1771,12 +1873,12 @@ class ServerRequestHandlerImpl if (tracker_view->getIsOpen()) { const bool bSaveSetting = context.request->request_set_tracker_frame_rate().save_setting(); - const float desired_framerate = context.request->request_set_tracker_frame_rate().value(); - PSMoveProtocol::Response_ResultSetTrackerFramerate* result_frame_rate = + const float desired_frame_rate = context.request->request_set_tracker_frame_rate().value(); + PSMoveProtocol::Response_ResultSetTrackerFrameRate* result_frame_rate = response->mutable_result_set_tracker_frame_rate(); - // Set the desired framerate on the tracker - tracker_view->setFramerate(desired_framerate, bSaveSetting); + // Set the desired frame rate on the tracker + tracker_view->setFrameRate(desired_frame_rate, bSaveSetting); // Only save the setting if requested if (bSaveSetting) @@ -1788,8 +1890,8 @@ class ServerRequestHandlerImpl context.connection_state->active_tracker_stream_info[tracker_id].has_temp_settings_override = true; } - // Return back the actual framerate that got set - result_frame_rate->set_new_frame_rate(static_cast(tracker_view->getFramerate())); + // Return back the actual frame rate that got set + result_frame_rate->set_new_frame_rate(static_cast(tracker_view->getFrameRate())); response->set_result_code(PSMoveProtocol::Response_ResultCode_RESULT_OK); } @@ -2123,7 +2225,9 @@ class ServerRequestHandlerImpl TrackerProfile trackerProfile; trackerProfile.clear(); - trackerProfile.frame_rate = static_cast(tracker_view->getFramerate()); + trackerProfile.frame_width = static_cast(tracker_view->getFrameWidth()); + //trackerProfile.frame_height = static_cast(tracker_view->getFrameHeight()); + trackerProfile.frame_rate = static_cast(tracker_view->getFrameRate()); trackerProfile.exposure= static_cast(tracker_view->getExposure()); trackerProfile.gain = static_cast(tracker_view->getGain()); @@ -2170,7 +2274,9 @@ class ServerRequestHandlerImpl m_device_manager.m_tracker_manager->getDefaultTrackerProfile(); // Apply the profile to the tracker - tracker_view->setFramerate(trackerProfile->frame_rate, true); + tracker_view->setFrameWidth(trackerProfile->frame_width, true); + //tracker_view->setFrameHeight(trackerProfile->frame_height, true); + tracker_view->setFrameRate(trackerProfile->frame_rate, true); tracker_view->setExposure(trackerProfile->exposure, true); tracker_view->setGain(trackerProfile->gain, true); for (int preset_index = 0; preset_index < eCommonTrackingColorID::MAX_TRACKING_COLOR_TYPES; ++preset_index) @@ -2186,7 +2292,9 @@ class ServerRequestHandlerImpl PSMoveProtocol::Response_ResultTrackerSettings* settings = response->mutable_result_tracker_settings(); - settings->set_frame_rate(static_cast(tracker_view->getFramerate())); + settings->set_frame_width(static_cast(tracker_view->getFrameWidth())); + settings->set_frame_height(static_cast(tracker_view->getFrameHeight())); + settings->set_frame_rate(static_cast(tracker_view->getFrameRate())); settings->set_exposure(static_cast(tracker_view->getExposure())); settings->set_gain(static_cast(tracker_view->getGain())); tracker_view->gatherTrackerOptions(settings); diff --git a/src/tests/test_camera.cpp b/src/tests/test_camera.cpp index 75dce73e..c4049ecc 100644 --- a/src/tests/test_camera.cpp +++ b/src/tests/test_camera.cpp @@ -5,11 +5,11 @@ #include #include -const std::vector known_keys = {113, 97, 119, 115, 101, 100, 114, 102, 116, 103, 121, 104}; -// q, a, w, s, e, d, r, f, t, g, y, h +const std::vector known_keys = {113, 97, 119, 115, 101, 100, 114, 102, 116, 103, 121, 104, 117, 106}; +// q, a, w, s, e, d, r, f, t, g, y, h, u, j -const std::vector known_keys_check = { 32, 122, 120, 99, 118, 98, 110 }; -// SPACEBAR, z, x, c, v, b, n +const std::vector known_keys_check = { 32, 122, 120, 99, 118, 98, 110, 109 }; +// SPACEBAR, z, x, c, v, b, n, m struct camera_state { @@ -23,6 +23,7 @@ int main(int, char**) { std::vector camera_states; int frame_rate_init = 40; + int frame_width_init = 640; std::cout << "=========CONTROLS=========\n" << " + | - | value | Variable\n" << "___|___|_______|__________\n" @@ -32,6 +33,7 @@ int main(int, char**) << " r | f | v | Hue \n" << " t | g | b | Sharpness \n" << " y | h | n | Fame Rate \n" + << " u | j | m | Fame Width \n" << "The space bar calculates the frame rate from the processed frames.\n" << "The escape key will close the cameras.\n" << "(focus must be on one of the camera windows to apply)\n" @@ -42,6 +44,9 @@ int main(int, char**) << "(higher frame rates will need more USB bandwidth): \n"; std::cin >> frame_rate_init; + std::cout << "Please enter the initial frame width for the cameras:\n"; + std::cin >> frame_width_init; + // Open all available cameras (up to 4 max) for (int camera_index = 0; camera_index < PSMOVESERVICE_MAX_TRACKER_COUNT; ++camera_index) { @@ -51,10 +56,11 @@ int main(int, char**) { std::string identifier = camera->getUniqueIndentifier(); - if (camera->get(CV_CAP_PROP_FPS) != frame_rate_init) - { + if (camera->get(CV_CAP_PROP_FRAME_WIDTH) != frame_width_init) + camera->set(CV_CAP_PROP_FRAME_WIDTH, frame_width_init); + + if (camera->get(CV_CAP_PROP_FPS) != frame_rate_init) camera->set(CV_CAP_PROP_FPS, frame_rate_init); - } auto last_ticks = std::chrono::high_resolution_clock::now(); int last_frames = 0; @@ -95,7 +101,7 @@ int main(int, char**) } ); - int wk = cv::waitKey(10); + int wk = cv::waitKey(1); if (wk == 27) // Escape { @@ -161,6 +167,15 @@ int main(int, char**) val_diff = (wk == 121) ? 10 : -10; } + // u/j for +/- frame width + // For CL_Eye, don't know + if ((wk == 117) || (wk == 106)) + { + cap_prop = CV_CAP_PROP_FRAME_WIDTH; + prop_str = "CV_CAP_PROP_FRAME_WIDTH"; + val_diff = (wk == 117) ? 1 : -1; + } + std::for_each( camera_states.begin(), camera_states.end(), @@ -171,19 +186,53 @@ int main(int, char**) switch (cap_prop) { + case CV_CAP_PROP_FRAME_WIDTH: + if (val == 320) { if (val_diff > 0) val_diff = 320; else val_diff = 0; } + else if (val == 640) { if (val_diff > 0) val_diff = 0; else val_diff = -320; } + break; case CV_CAP_PROP_FPS: - if (val == 2) { if (val_diff > 0) val_diff = 1; else val_diff = 0; } - else if (val == 3) { if (val_diff > 0) val_diff = 2; else val_diff = -1; } - else if (val == 5) { if (val_diff > 0) val_diff = 3; else val_diff = -2; } - else if (val == 8) { if (val_diff > 0) val_diff = 2; else val_diff = -3; } - else if (val == 10) { if (val_diff > 0) val_diff = 5; else val_diff = -2; } - else if (val == 15) { if (val_diff > 0) val_diff = 5; else val_diff = -5; } - else if (val == 20) { if (val_diff > 0) val_diff = 5; else val_diff = -5; } - else if (val == 25) { if (val_diff > 0) val_diff = 5; else val_diff = -5; } - else if (val == 30) { if (val_diff < 0) { val_diff = -5; } } - else if (val == 60) { if (val_diff > 0) { val_diff = 15; } } - else if (val == 75) { if (val_diff > 0) val_diff = 8; else val_diff = -15; } - else if (val == 83) { if (val_diff < 0) val_diff = -8; } + int frame_width = state.camera->get(CV_CAP_PROP_FRAME_WIDTH); + if (frame_width == 640) + { + if (val == 2) { if (val_diff > 0) val_diff = 1; else val_diff = 0; } + else if (val == 3) { if (val_diff > 0) val_diff = 2; else val_diff = -1; } + else if (val == 5) { if (val_diff > 0) val_diff = 3; else val_diff = -2; } + else if (val == 8) { if (val_diff > 0) val_diff = 2; else val_diff = -3; } + else if (val == 10) { if (val_diff > 0) val_diff = 5; else val_diff = -2; } + else if (val == 15) { if (val_diff > 0) val_diff = 5; else val_diff = -5; } + else if (val == 20) { if (val_diff > 0) val_diff = 5; else val_diff = -5; } + else if (val == 25) { if (val_diff > 0) val_diff = 5; else val_diff = -5; } + else if (val == 30) { if (val_diff < 0) { val_diff = -5; } } + else if (val == 60) { if (val_diff > 0) { val_diff = 15; } } + else if (val == 75) { if (val_diff > 0) val_diff = 8; else val_diff = -15; } + else if (val == 83) { if (val_diff < 0) val_diff = -8; } + } + else + { + if (val == 2) { if (val_diff > 0) val_diff = 1; else val_diff = 0; } + else if (val == 3) { if (val_diff > 0) val_diff = 2; else val_diff = -1; } + else if (val == 5) { if (val_diff > 0) val_diff = 2; else val_diff = -2; } + else if (val == 7) { if (val_diff > 0) val_diff = 3; else val_diff = -2; } + else if (val == 10) { if (val_diff > 0) val_diff = 2; else val_diff = -3; } + else if (val == 12) { if (val_diff > 0) val_diff = 3; else val_diff = -2; } + else if (val == 15) { if (val_diff > 0) val_diff = 2; else val_diff = -3; } + else if (val == 17) { if (val_diff > 0) val_diff = 13; else val_diff = -2; } + else if (val == 30) { if (val_diff > 0) val_diff = 7; else val_diff = -13; } + else if (val == 37) { if (val_diff > 0) val_diff = 3; else val_diff = -7; } + else if (val == 40) { if (val_diff > 0) val_diff = 10; else val_diff = -3; } + else if (val == 50) { if (val_diff > 0) val_diff = 10; else val_diff = -10; } + else if (val == 60) { if (val_diff > 0) val_diff = 15; else val_diff = -10; } + else if (val == 75) { if (val_diff > 0) val_diff = 15; else val_diff = -15; } + else if (val == 90) { if (val_diff > 0) val_diff = 10; else val_diff = -15; } + else if (val == 100) { if (val_diff > 0) val_diff = 25; else val_diff = -10; } + else if (val == 125) { if (val_diff > 0) val_diff = 12; else val_diff = -25; } + else if (val == 137) { if (val_diff > 0) val_diff = 13; else val_diff = -12; } + else if (val == 150) { if (val_diff > 0) val_diff = 37; else val_diff = -13; } + else if (val == 187) { if (val_diff > 0) val_diff = 18; else val_diff = -37; } + else if (val == 205) { if (val_diff > 0) val_diff = 85; else val_diff = -18; } + else if (val == 290) { if (val_diff > 0) val_diff = 0; else val_diff = -85; } + } + break; } val += val_diff; @@ -248,6 +297,13 @@ int main(int, char**) prop_str = "CV_CAP_PROP_FPS"; } + // M to check frame width + if (wk == 109) + { + cap_prop = CV_CAP_PROP_FRAME_WIDTH; + prop_str = "CV_CAP_PROP_FRAME_WIDTH"; + } + std::for_each( camera_states.begin(), camera_states.end(), diff --git a/src/tests/test_camera_parallel.cpp b/src/tests/test_camera_parallel.cpp index 2625486d..d1077708 100644 --- a/src/tests/test_camera_parallel.cpp +++ b/src/tests/test_camera_parallel.cpp @@ -28,11 +28,11 @@ inline void parallel_for_each(It a, It b, F&& f) } #endif -const std::vector known_keys = { 113, 97, 119, 115, 101, 100, 114, 102, 116, 103, 121, 104 }; -// q, a, w, s, e, d, r, f, t, g, y, h +const std::vector known_keys = { 113, 97, 119, 115, 101, 100, 114, 102, 116, 103, 121, 104, 117, 106 }; +// q, a, w, s, e, d, r, f, t, g, y, h, u, j -const std::vector known_keys_check = { 32, 122, 120, 99, 118, 98, 110 }; -// SPACEBAR, z, x, c, v, b, n +const std::vector known_keys_check = { 32, 122, 120, 99, 118, 98, 110, 109 }; +// SPACEBAR, z, x, c, v, b, n, m struct camera_state { @@ -47,6 +47,13 @@ int main(int, char**) { std::vector camera_states; int frame_rate_init = 40; + int frame_width_init = 640; + + bool ask_for_input = true; + char yesno = 'y'; + std::cout << "Enter individual settings? [y/n]: "; + std::cin >> yesno; + if (yesno == 'n') ask_for_input = false; // Open all available cameras (up to 30 max) for (int camera_index = 0; camera_index < 30; ++camera_index) @@ -57,14 +64,21 @@ int main(int, char**) { std::string identifier = camera->getUniqueIndentifier(); - std::cout << "Enter initial frame rate for camera " << identifier << ": " ; - std::cin >> frame_rate_init; - - if (camera->get(CV_CAP_PROP_FPS) != frame_rate_init) + if (ask_for_input) { - camera->set(CV_CAP_PROP_FPS, frame_rate_init); + std::cout << "Enter initial frame width for camera " << identifier << ": "; + std::cin >> frame_width_init; + + std::cout << "Enter initial frame rate for camera " << identifier << ": "; + std::cin >> frame_rate_init; } + if (camera->get(CV_CAP_PROP_FRAME_WIDTH) != frame_width_init) + camera->set(CV_CAP_PROP_FRAME_WIDTH, frame_width_init); + + if (camera->get(CV_CAP_PROP_FPS) != frame_rate_init) + camera->set(CV_CAP_PROP_FPS, frame_rate_init); + auto last_ticks = std::chrono::high_resolution_clock::now(); int last_frames = 0; @@ -82,13 +96,17 @@ int main(int, char**) << " r | f | v | Hue \n" << " t | g | b | Sharpness \n" << " y | h | n | Fame Rate \n" + << " u | j | m | Fame Width \n" << "Check the calculated frame rate with the space bar and close cameras with escape \n" ; + + bool closeAll = false; + // Create a window for each opened camera parallel_for_each( camera_states.begin(), camera_states.end(), - [&camera_states](camera_state &state) { + [&camera_states, &closeAll](camera_state &state) { cv::namedWindow(state.identifier.c_str(), 1); //bool bKeepRunning = camera_states.size() > 0; @@ -105,12 +123,16 @@ int main(int, char**) state.last_frames++; } - int wk = cv::waitKey(10); + int wk = cv::waitKey(1); - if (wk == 27) // Escape + if (wk == 27 || closeAll) // Escape { bKeepRunning = false; } + else if (wk == 7536640) // F4 + { + closeAll = true; + } else if (std::find(known_keys.begin(), known_keys.end(), wk) != known_keys.end()) { int cap_prop = CV_CAP_PROP_EXPOSURE; @@ -171,24 +193,67 @@ int main(int, char**) val_diff = (wk == 121) ? 10 : -10; } + // u/j for +/- frame width + // For CL_Eye, don't know + if ((wk == 117) || (wk == 106)) + { + cap_prop = CV_CAP_PROP_FRAME_WIDTH; + prop_str = "CV_CAP_PROP_FRAME_WIDTH"; + val_diff = (wk == 117) ? 1 : -1; + } + double val = state.camera->get(cap_prop); std::cout << state.identifier << ": Value of " << prop_str << " was " << val << std::endl; switch (cap_prop) { + case CV_CAP_PROP_FRAME_WIDTH: + if (val == 320) { if (val_diff > 0) val_diff = 320; else val_diff = 0; } + else if (val == 640) { if (val_diff > 0) val_diff = 0; else val_diff = -320; } + break; case CV_CAP_PROP_FPS: - if (val == 2) { if (val_diff > 0) val_diff = 1; else val_diff = 0; } - else if (val == 3) { if (val_diff > 0) val_diff = 2; else val_diff = -1; } - else if (val == 5) { if (val_diff > 0) val_diff = 3; else val_diff = -2; } - else if (val == 8) { if (val_diff > 0) val_diff = 2; else val_diff = -3; } - else if (val == 10) { if (val_diff > 0) val_diff = 5; else val_diff = -2; } - else if (val == 15) { if (val_diff > 0) val_diff = 5; else val_diff = -5; } - else if (val == 20) { if (val_diff > 0) val_diff = 5; else val_diff = -5; } - else if (val == 25) { if (val_diff > 0) val_diff = 5; else val_diff = -5; } - else if (val == 30) { if (val_diff < 0) { val_diff = -5; } } - else if (val == 60) { if (val_diff > 0) { val_diff = 15; } } - else if (val == 75) { if (val_diff > 0) val_diff = 8; else val_diff = -15; } - else if (val == 83) { if (val_diff < 0) val_diff = -8; } + int frame_width = state.camera->get(CV_CAP_PROP_FRAME_WIDTH); + if (frame_width == 640) + { + if (val == 2) { if (val_diff > 0) val_diff = 1; else val_diff = 0; } + else if (val == 3) { if (val_diff > 0) val_diff = 2; else val_diff = -1; } + else if (val == 5) { if (val_diff > 0) val_diff = 3; else val_diff = -2; } + else if (val == 8) { if (val_diff > 0) val_diff = 2; else val_diff = -3; } + else if (val == 10) { if (val_diff > 0) val_diff = 5; else val_diff = -2; } + else if (val == 15) { if (val_diff > 0) val_diff = 5; else val_diff = -5; } + else if (val == 20) { if (val_diff > 0) val_diff = 5; else val_diff = -5; } + else if (val == 25) { if (val_diff > 0) val_diff = 5; else val_diff = -5; } + else if (val == 30) { if (val_diff < 0) { val_diff = -5; } } + else if (val == 60) { if (val_diff > 0) { val_diff = 15; } } + else if (val == 75) { if (val_diff > 0) val_diff = 8; else val_diff = -15; } + else if (val == 83) { if (val_diff < 0) val_diff = -8; } + } + else + { + if (val == 2) { if (val_diff > 0) val_diff = 1; else val_diff = 0; } + else if (val == 3) { if (val_diff > 0) val_diff = 2; else val_diff = -1; } + else if (val == 5) { if (val_diff > 0) val_diff = 2; else val_diff = -2; } + else if (val == 7) { if (val_diff > 0) val_diff = 3; else val_diff = -2; } + else if (val == 10) { if (val_diff > 0) val_diff = 2; else val_diff = -3; } + else if (val == 12) { if (val_diff > 0) val_diff = 3; else val_diff = -2; } + else if (val == 15) { if (val_diff > 0) val_diff = 2; else val_diff = -3; } + else if (val == 17) { if (val_diff > 0) val_diff = 13; else val_diff = -2; } + else if (val == 30) { if (val_diff > 0) val_diff = 7; else val_diff = -13; } + else if (val == 37) { if (val_diff > 0) val_diff = 3; else val_diff = -7; } + else if (val == 40) { if (val_diff > 0) val_diff = 10; else val_diff = -3; } + else if (val == 50) { if (val_diff > 0) val_diff = 10; else val_diff = -10; } + else if (val == 60) { if (val_diff > 0) val_diff = 15; else val_diff = -10; } + else if (val == 75) { if (val_diff > 0) val_diff = 15; else val_diff = -15; } + else if (val == 90) { if (val_diff > 0) val_diff = 10; else val_diff = -15; } + else if (val == 100) { if (val_diff > 0) val_diff = 25; else val_diff = -10; } + else if (val == 125) { if (val_diff > 0) val_diff = 12; else val_diff = -25; } + else if (val == 137) { if (val_diff > 0) val_diff = 13; else val_diff = -12; } + else if (val == 150) { if (val_diff > 0) val_diff = 37; else val_diff = -13; } + else if (val == 187) { if (val_diff > 0) val_diff = 18; else val_diff = -37; } + else if (val == 205) { if (val_diff > 0) val_diff = 85; else val_diff = -18; } + else if (val == 290) { if (val_diff > 0) val_diff = 0; else val_diff = -85; } + } + break; } val += val_diff; @@ -245,6 +310,13 @@ int main(int, char**) prop_str = "CV_CAP_PROP_SHARPNESS"; } + // M to check frame width + if (wk == 109) + { + cap_prop = CV_CAP_PROP_FRAME_WIDTH; + prop_str = "CV_CAP_PROP_FRAME_WIDTH"; + } + double val = state.camera->get(cap_prop); auto now_ticks = std::chrono::high_resolution_clock::now(); switch (wk) diff --git a/thirdparty/PS3EYEDriver b/thirdparty/PS3EYEDriver index 64383a6e..c8d80a6f 160000 --- a/thirdparty/PS3EYEDriver +++ b/thirdparty/PS3EYEDriver @@ -1 +1 @@ -Subproject commit 64383a6e047572759e4ad4e6efc703f4248ced26 +Subproject commit c8d80a6f705c0a40887d60963991fc92c46530be