@@ -30,7 +30,7 @@ constexpr int NOK_KEY = 110;
3030 */
3131bool Camera::isGrayscale ()
3232{
33- unique_ptr<cv::Mat> frame = read1 ();
33+ auto frame = read1 ();
3434
3535 if (frame->channels () != 3 )
3636 return false ;
@@ -163,8 +163,7 @@ void Camera::closeCap() noexcept
163163 cap->release ();
164164}
165165
166- Camera::Camera (const string &device)
167- : id(Camera::deviceId(device)), device(device)
166+ Camera::Camera (const string &device) : id(Camera::deviceId(device)), device(device)
168167{
169168 cv::utils::logging::setLogLevel (cv::utils::logging::LogLevel::LOG_LEVEL_ERROR);
170169}
@@ -225,47 +224,94 @@ bool Camera::apply(const CameraInstruction &instruction)
225224 *
226225 * @return the frame
227226 */
228- unique_ptr <cv::Mat> Camera::read1 ()
227+ shared_ptr <cv::Mat> Camera::read1 ()
229228{
230229 openCap ();
231- auto frame = make_unique <cv::Mat>();
230+ auto frame = make_shared <cv::Mat>();
232231 cap->read (*frame);
233232 closeCap ();
234233 return frame;
235234}
236235
237236/* *
238- * @brief Check if the emitter is working
239- * by showing a video feedback and
240- * asking confirmation to the user
237+ * @brief Show a video feedback to the user
238+ * and asks if the emitter is working
241239 *
242240 * @throw CameraException if unable to open the camera device
243241 *
244242 * @return true if yes, false if not
245243 */
246- bool Camera::isEmitterWorking ()
244+ bool Camera::isEmitterWorkingAsk ()
247245{
248- openCap ();
249246 cv::Mat frame;
250247 int key = -1 ;
251248
252249 cout << " Is the video flashing? Press Y or N in the window" << endl;
253-
254250 while (key != OK_KEY && key != NOK_KEY)
255251 {
256252 cap->read (frame);
257253 cv::imshow (" linux-enable-ir-emitter" , frame);
258254 key = cv::waitKey (5 );
259255 }
260-
261256 cout << (key == OK_KEY ? " Y pressed" : " N pressed" ) << endl;
262257
263- closeCap ();
264258 cv::destroyAllWindows ();
265-
266259 return key == OK_KEY;
267260}
268261
262+ /* *
263+ * @brief Trigger the camera
264+ * and asks if the emitter is working
265+ *
266+ * @throw CameraException if unable to open the camera device
267+ *
268+ * @return true if yes, false if not
269+ */
270+ bool Camera::isEmitterWorkingAskNoGui ()
271+ {
272+ cv::Mat frame;
273+ cap->read (frame);
274+
275+ string answer;
276+ cout << " Is the ir emitter flashing (not just turn on) ? Yes/No ? " ;
277+ cin >> answer;
278+ transform (answer.begin (), answer.end (), answer.begin (), [](char c)
279+ { return tolower (c); });
280+
281+ while (answer != " yes" && answer != " y" && answer != " no" && answer != " n" )
282+ {
283+ cout << " Yes/No ? " ;
284+ cin >> answer;
285+ transform (answer.begin (), answer.end (), answer.begin (), [](char c)
286+ { return tolower (c); });
287+ }
288+
289+ return answer == " yes" || answer == " y" ;
290+ }
291+
292+ /* *
293+ * @brief Check if the emitter is working
294+ * by asking confirmation to the user
295+ *
296+ * @throw CameraException if unable to open the camera device
297+ *
298+ * @return true if yes, false if not
299+ */
300+ bool Camera::isEmitterWorking ()
301+ {
302+ openCap ();
303+
304+ bool res;
305+ if (noGui)
306+ res = isEmitterWorkingAskNoGui ();
307+ else
308+ res = isEmitterWorkingAsk ();
309+
310+ closeCap ();
311+
312+ return res;
313+ }
314+
269315/* *
270316 * @brief Execute an uvc query on the device indicated by the file descriptor
271317 *
@@ -388,6 +434,11 @@ uint16_t Camera::lenUvcQuery(uint8_t unit, uint8_t selector)
388434 return len;
389435}
390436
437+ void Camera::disableGui ()
438+ {
439+ noGui = true ;
440+ }
441+
391442CameraException::CameraException (const string &device) : message(" Cannot access to " + device) {}
392443
393444const char *CameraException::what () const noexcept
0 commit comments