Blackjack Decision Maker
CardDiscriminator.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 CARDDISCRIMINATOR
11 #define CARDDISCRIMINATOR
12 
13 
14 #include "Card.h"
15 
22  /* Images of loaded template cards */
23  std::vector<cv::Mat> template_cards;
24  /* Names of loaded template cards */
25  std::vector<cv::String> names;
26 };
27 
34 {
35 private:
36  /* Load template ranks once */
37  const TemplateImages rank_images;
38  /* Not implemented yet */
39  const TemplateImages suit_images;
40 
41 public:
42  /* Keep track on number of template cards stored */
43  const int num_template_cards;
44 
55  CardTemplate(cv::String folder) : rank_images(init(folder, false)), suit_images(init(folder, true)), num_template_cards((int)rank_images.template_cards.size()) {};
56 
66  static TemplateImages init(cv::String folder, bool suit_flag)
67  {
68  TemplateImages temp;
69  cv::String filename;
70  std::vector<cv::Mat> result;
71  std::vector<cv::String> card_names;
72 
73  if(suit_flag){
74  card_names = {"Club","Heart","Diamond","Spade"};
75  }
76  else{
77  card_names = {"Ace","Two","Three","Four","Five","Six","Seven","Eight","Nine","Ten","Jack","Queen","King"};
78  }
79 
80  for (size_t i = 0; i < card_names.size(); i++){
81  filename = folder + card_names[i] + ".jpg";
82  result.push_back(cv::imread(filename, cv::IMREAD_GRAYSCALE));
83  }
84 
85  temp.template_cards = result;
86  temp.names = card_names;
87  return temp;
88  }
89 
96  cv::Mat getCard(int index){
97  if(index > rank_images.template_cards.size() || index < 0){
98  std::cout << "Error: Index Invalid" << std::endl;
99  return cv::Mat{};
100  }
101  return rank_images.template_cards.at(index);
102  }
103 
110  cv::String getCardRank(int index){
111  if(index > rank_images.names.size() || index < 0){
112  std::cout << "Error: Index Invalid" << std::endl;
113  return "None";
114  }
115  return rank_images.names.at(index);
116  }
117 };
118 
126  public:
127  CardDiscriminator(cv::String folder_path);
128  void template_matching(Card_params &Card_params, bool rank);
129 
130  private:
131  CardTemplate cardTemplates;
132 
133 };
134 
135 #endif //CARD_DISCRIMINATOR_H
Class to implement detection method from Card Rank ROIs. Can be adapted for other solutions such as m...
Definition: CardDiscriminator.h:125
CardDiscriminator(cv::String folder_path)
Construct a new Card Discriminator:: Card Discriminator object.
Definition: CardDiscriminator.cpp:19
void template_matching(Card_params &Card_params, bool rank)
Template matching method is responsible for determining the card Rank. In this release,...
Definition: CardDiscriminator.cpp:38
Class to load and store the template cards from a folder path.
Definition: CardDiscriminator.h:34
CardTemplate(cv::String folder)
Construct a new Card Template object. Template cards are defined as constant. The following procedure...
Definition: CardDiscriminator.h:55
cv::Mat getCard(int index)
Get the Card object.
Definition: CardDiscriminator.h:96
const int num_template_cards
Definition: CardDiscriminator.h:43
cv::String getCardRank(int index)
Get the Card name.
Definition: CardDiscriminator.h:110
static TemplateImages init(cv::String folder, bool suit_flag)
Init function to parse the folder path and read the template card images.
Definition: CardDiscriminator.h:66
Structure holding the parameters of all detected card shapes in a frame, such as their position in th...
Definition: Card.h:52
Simple structure to hold loaded images and their respective names.
Definition: CardDiscriminator.h:21
std::vector< cv::Mat > template_cards
Definition: CardDiscriminator.h:23
std::vector< cv::String > names
Definition: CardDiscriminator.h:25