Blackjack Decision Maker
DetectCard.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 DETECT_CARD_H
11 #define DETECT_CARD_H
12 
13 #include <thread>
14 
15 #include "Card.h"
16 #include "CallbackLinker.h"
17 #include "CardDiscriminator.h"
18 
23 class DetectCard : public CallbackLinker
24 {
25 private:
26  bool isProcessing = false;
27  bool busy = false;
28  bool newFrame = false;
29  bool err_frame = false;
30  int frame_counter = 0;
31  cv::Mat currentFrame;
32 
33  std::thread procThread;
34  void processingThreadLoop();
35  CallbackLinker* processingCallback = nullptr;
36 
37  cv::Mat preprocess_image(cv::Mat &image);
38  Card_params find_cards(cv::Mat &image);
39  cv::Mat flatten_card(qCard &qCard, cv::Mat &image);
40  void preprocess_cards(Card_params &Card_params, cv::Mat &image);
41 
42  /* Output, match template and store cards detected */
43  void template_matching(Card_params &Card_params, bool rank=true);
44  CardDiscriminator carddiscriminator;
45 
46 public:
47  DetectCard(cv::String folder_path);
48  ~DetectCard();
50  void unregisterCallback();
51  void nextCallback(AcePlaysUtils &callbackData);
52 
53  /* Spawn thread */
54  void startProcessing();
55  void stopProcessing();
56 };
57 
58 
59 
60 
61 #endif /* DETECT_CARD_H */
Generic abstract Callback Interface class.
Definition: CallbackLinker.h:20
Class to implement detection method from Card Rank ROIs. Can be adapted for other solutions such as m...
Definition: CardDiscriminator.h:125
Class for the detection of cards. Runs the processing pipeline.
Definition: DetectCard.h:24
void registerCallback(CallbackLinker *cb)
Register a Callback for the DetectCard Class.
Definition: DetectCard.cpp:435
DetectCard(cv::String folder_path)
Construct a new Detect Card:: Detect Card object.
Definition: DetectCard.cpp:474
void unregisterCallback()
Unregister existing callback.
Definition: DetectCard.cpp:443
void startProcessing()
Method call to start the Processing Thread.
Definition: DetectCard.cpp:451
void nextCallback(AcePlaysUtils &callbackData)
Implement the nextCallback virtual method to pass information down the pipeline.
Definition: DetectCard.cpp:423
~DetectCard()
Destroy the Detect Card:: Detect Card object.
Definition: DetectCard.cpp:482
void stopProcessing()
Method call to stop the Processing Thread.
Definition: DetectCard.cpp:461
Utility structure used by the AcePlays repo for passing necessary information down the processing pip...
Definition: Card.h:80
Structure holding the parameters of all detected card shapes in a frame, such as their position in th...
Definition: Card.h:52
Structure to store information about single card in the camera image.
Definition: Card.h:93