Blackjack Decision Maker
Camera.h
Go to the documentation of this file.
1 /*
2 Copyright 2023 Georgios Titas
3 Copyright 2023 Alexander Douglas
4 Copyright 2023 Jijo Varghese
5 Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
6 The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
7 THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
8 */
9 
10 #ifndef CAMERA_H
11 #define CAMERA_H
12 #include <opencv2/core.hpp>
13 #include <opencv2/videoio.hpp>
14 #include <opencv2/highgui.hpp>
15 
16 #include <iostream>
17 #include <thread>
18 #include "CallbackLinker.h"
19 
20 /* Choose the old or new Pi camera stack from CMakeLists.txt file*/
21 #if defined(CMAKE_NEW_CAM_STACK_ON)
22 #define NEW_CAM_STACK 1
23 #elif defined(CMAKE_NEW_CAM_STACK_OFF)
24 #define NEW_CAM_STACK 0
25 #else
26 #define NEW_CAM_STACK 0
27 #endif
28 
29 #if NEW_CAM_STACK
30 #include <lccv.hpp>
31 #endif
32 
33 
34 enum Err_type{
38 };
39 
44 class Camera
45 {
46 private:
47  struct{
48  int camIdx;
49  int camApi;
50  bool isOn = false;
51  } CamSettings;
52 
53  int errCode;
54  cv::Mat currentFrame;
55 
56 #if NEW_CAM_STACK
57  lccv::PiCamera activeCapture;
58 #else
59  cv::VideoCapture activeCapture;
60 #endif
61 
62  std::thread camThread;
63  void camThreadLoop();
64  CallbackLinker* cameraCallback = nullptr;
65 
66 public:
67  Camera(int camIdx = 0, double res_w = 640, double res_h = 480);
68  ~Camera();
70  void unregisterCallback();
71  void startRecording();
72  void stopRecording();
73  int getErr();
74 
75 };
76 
77 
78 #endif /* CAMERA_H */
Err_type
Definition: Camera.h:34
@ ERR_EMPTY_FRAME
Definition: Camera.h:37
@ NO_ERROR
Definition: Camera.h:35
@ ERR_INIT
Definition: Camera.h:36
Generic abstract Callback Interface class.
Definition: CallbackLinker.h:20
Class for initialising a Camera object and capturing frames.
Definition: Camera.h:45
int camIdx
Definition: Camera.h:48
void registerCallback(CallbackLinker *cb)
Register a Callback for the Camera Class.
Definition: Camera.cpp:96
int camApi
Definition: Camera.h:49
Camera(int camIdx=0, double res_w=640, double res_h=480)
Construct a new Camera:: Camera object.
Definition: Camera.cpp:21
void stopRecording()
Method call to stop the camera recording thread Call when exiting the programme.
Definition: Camera.cpp:133
int getErr()
Get latest Error Code.
Definition: Camera.cpp:145
bool isOn
Definition: Camera.h:50
void unregisterCallback()
Unregister existing callback.
Definition: Camera.cpp:104
~Camera()
Destroy the Camera:: Camera object.
Definition: Camera.cpp:153
void startRecording()
Method call to start the camera recording thread.
Definition: Camera.cpp:112
Definition: lccv.hpp:53