std::unique_ptr<std::thread> _thread_handle;
bool _exit_thread { false };
std::unordered_set<unsigned int> _camera_ids;
+ std::vector<int> _validFps;
unsigned int _active_camera_id {};
static bool _registered;
void updateAvailableCameraDevices();
void setActiveCameraDevice(unsigned int id);
+ void updateAvailableFPS();
void threadLoop();
public:
}
}
+void OpencvBackend::updateAvailableFPS()
+{
+ // Opencv cannot list up valid FPS values itself
+ // so use well-known fps values to check if each fps is valid or not.
+ vector<int> testFPS = { 15, 30, 60, 120 };
+
+ for (auto &fps : testFPS) {
+ _video_capture->set(cv::CAP_PROP_FPS, fps);
+
+ auto actualFPS = _video_capture->get(cv::CAP_PROP_FPS);
+ if (static_cast<int>(actualFPS) == fps) {
+ SINGLEO_LOGD("%d FPS is supported.", fps);
+ _validFps.push_back(fps);
+ }
+ }
+}
+
void OpencvBackend::registerObserver(IInputObserver *observer)
{
_observer = observer;
SINGLEO_LOGE("Failed to open camera device(%d).", _active_camera_id);
throw InvalidOperation("Failed to open WebCap device.");
}
+
+ // Listup valid FPS values.
+ updateAvailableFPS();
+
+ auto fps_it = find(_validFps.begin(), _validFps.end(), config.fps);
+ if (fps_it == _validFps.end()) {
+ SINGLEO_LOGE("OpencvBackend: fps(%d) is not supported.", config.fps);
+ throw InvalidOperation("OpencvBackend: fps is not supported.");
+ }
+
+ _video_capture->set(cv::CAP_PROP_FPS, config.fps);
+ SINGLEO_LOGD("%d FPS has been set.", config.fps);
}
void OpencvBackend::capture(BaseDataType &out_data)