diff options
-rw-r--r-- | ftnoir_tracker_aruco/ftnoir_tracker_aruco.cpp | 31 | ||||
-rw-r--r-- | ftnoir_tracker_aruco/ftnoir_tracker_aruco.h | 12 |
2 files changed, 34 insertions, 9 deletions
diff --git a/ftnoir_tracker_aruco/ftnoir_tracker_aruco.cpp b/ftnoir_tracker_aruco/ftnoir_tracker_aruco.cpp index 1a638198..d068564d 100644 --- a/ftnoir_tracker_aruco/ftnoir_tracker_aruco.cpp +++ b/ftnoir_tracker_aruco/ftnoir_tracker_aruco.cpp @@ -16,6 +16,7 @@ #include <opencv/highgui.h> #include <vector> #include <cstdio> +#include <memory> #if defined(_WIN32) #include <dshow.h> @@ -100,6 +101,7 @@ static resolution_tuple resolution_choices[] = { void Tracker::load_settings() { + QMutexLocker foo(&mtx); QSettings settings("opentrack"); QString currentFile = settings.value( "SettingsFile", QCoreApplication::applicationDirPath() + "/settings/default.ini" ).toString(); QSettings iniFile( currentFile, QSettings::IniFormat ); @@ -126,6 +128,8 @@ void Tracker::load_settings() headpos[i] = iniFile.value(QString("headpos-%1").arg(i), 0).toDouble(); } iniFile.endGroup(); + + reset = true; } Tracker::Tracker() @@ -149,6 +153,7 @@ Tracker::~Tracker() void Tracker::StartTracker(QFrame* videoframe) { + reset = false; videoframe->show(); videoWidget = new ArucoVideoWidget(videoframe); QHBoxLayout* layout = new QHBoxLayout(); @@ -169,26 +174,32 @@ void Tracker::StartTracker(QFrame* videoframe) void Tracker::run() { - cv::VideoCapture camera(camera_index); +start: + reset = false; + std::unique_ptr<cv::VideoCapture> camera(new cv::VideoCapture(camera_index)); if (force_width) - camera.set(CV_CAP_PROP_FRAME_WIDTH, force_width); + camera->set(CV_CAP_PROP_FRAME_WIDTH, force_width); if (force_height) - camera.set(CV_CAP_PROP_FRAME_HEIGHT, force_height); + camera->set(CV_CAP_PROP_FRAME_HEIGHT, force_height); if (force_fps) - camera.set(CV_CAP_PROP_FPS, force_fps); + camera->set(CV_CAP_PROP_FPS, force_fps); aruco::MarkerDetector detector; detector.setDesiredSpeed(3); detector.setThresholdParams(11, 5); cv::Mat color, color_, grayscale, grayscale2, rvec, tvec; - if (!camera.isOpened()) + if (!camera->isOpened()) { fprintf(stderr, "aruco tracker: can't open camera\n"); return; } + while (!stop) + if(camera->read(color_)) + break; + auto freq = cv::getTickFrequency(); auto last_time = cv::getTickCount(); auto prev_time = last_time; @@ -200,7 +211,12 @@ void Tracker::run() cv::Point2f last_centroid; while (!stop) { - if (!camera.read(color_)) + if (reset) + { + camera.reset(nullptr); + goto start; + } + if (!camera->read(color_)) continue; color_.copyTo(color); cv::cvtColor(color, grayscale2, cv::COLOR_BGR2GRAY); @@ -416,6 +432,7 @@ extern "C" FTNOIR_TRACKER_BASE_EXPORT ITrackerDialog* CALLING_CONVENTION GetDial TrackerControls::TrackerControls() { + tracker = nullptr; ui.setupUi(this); setAttribute(Qt::WA_NativeWindow, true); connect(ui.cameraName, SIGNAL(currentIndexChanged(int)), this, SLOT(settingChanged(int))); @@ -553,6 +570,8 @@ void TrackerControls::save() } iniFile.endGroup(); settingsDirty = false; + if (tracker) + tracker->load_settings(); } void TrackerControls::doOK() diff --git a/ftnoir_tracker_aruco/ftnoir_tracker_aruco.h b/ftnoir_tracker_aruco/ftnoir_tracker_aruco.h index 5d3d4ed6..61eec096 100644 --- a/ftnoir_tracker_aruco/ftnoir_tracker_aruco.h +++ b/ftnoir_tracker_aruco/ftnoir_tracker_aruco.h @@ -28,6 +28,7 @@ public: bool GiveHeadPoseData(double *data); bool enableTX, enableTY, enableTZ, enableRX, enableRY, enableRZ; void run(); + void load_settings(); private: QMutex mtx; ArucoVideoWidget* videoWidget; @@ -36,10 +37,10 @@ private: float fov; int camera_index; int force_fps, force_width, force_height; - void load_settings(); double pose[6]; cv::Mat frame; double headpos[3]; + volatile bool reset; }; // Widget that has controls for FTNoIR protocol client-settings. @@ -53,14 +54,19 @@ public: void showEvent (QShowEvent *); void Initialize(QWidget *); - void registerTracker(ITracker *) {} - void unRegisterTracker() {} + void registerTracker(ITracker * x) { + tracker = dynamic_cast<Tracker*>(x); + } + void unRegisterTracker() { + tracker = nullptr; + } private: Ui::Form ui; void loadSettings(); void save(); bool settingsDirty; + Tracker* tracker; private slots: void doOK(); |