Skip to content

Commit

Permalink
adds docstrings, refactors SignapseUtils, #22, #11
Browse files Browse the repository at this point in the history
  • Loading branch information
rossGardiner committed Apr 14, 2022
1 parent 5325703 commit 38e9f2c
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 47 deletions.
7 changes: 0 additions & 7 deletions src/CNNProcessor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,4 @@ Scene CNNProcessor::ProcessScene(Scene scene){
return scene;
}

//void CNNProcessor::NextScene(Scene next) {
// Scene updatedFrame = ProcessScene(next);
// if(!sceneCallback) return;
// sceneCallback->NextScene(updatedFrame);
//}



2 changes: 1 addition & 1 deletion src/Gui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ void Gui::SetTargetImage(std::string letter) {
* Method handler for when the next task button is pressed, sets new task and resets the progress bar.
*/
void Gui::ButtonPressed(){
std::string new_task = SignapseUtils::getLetterFromDigit(SignapseUtils::makeTask());
std::string new_task = SignapseUtils::makeTask();
SetTargetImage(new_task);
currentTask = new_task;
progress_bar.reset_progress();
Expand Down
92 changes: 55 additions & 37 deletions src/SignapseUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,42 +9,60 @@

#define MODEL_PATH "models/asl-mobilenetv2.pb"
#define NR_TASKS 26


class SignapseUtils {
public:
static std::string getLetterFromDigit(int digit){
std::string results[] = {"A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V",
"W", "X", "Y", "Z", "del", "space", "nothing"};
return results[digit];
}
static void welcomeMessage(){
printf(" _____ _ \n"
" / ____(_) \n"
" | (___ _ __ _ _ __ __ _ _ __ ___ ___ \n"
" \\___ \\| |/ _` | '_ \\ / _` | '_ \\/ __|/ _ \\\n"
" ____) | | (_| | | | | (_| | |_) \\__ \\ __/\n"
" |_____/|_|\\__, |_| |_|\\__,_| .__/|___/\\___|\n"
" __/ | | | \n"
" |___/ |_| \n \nWelcome to Signapse, the tool for helping everyday people learn sign language for free!\n");
}


static void printProgress(float percentage, int prediction) {
std::string letter = getLetterFromDigit(prediction);
std::cout << "\r Prediction: " << letter << ", Progress: " << percentage << "% - keep signing! ";
fflush(stdout);
}

static int makeTask(){
srand( (unsigned)time( NULL ) );
return rand() % NR_TASKS;
}

static std::string getModelPath(){
return MODEL_PATH;
}
};

namespace {
/*!
* Simple static class for some utilities needed by Signapse objects.
*/
class SignapseUtils {
public:
/*!
* Array of ordered results from expected at the output of the current CNN model in use.
*/
static std::vector <std::string> results;

/*!
* Prints welcome message and ASCII art logo
*/
static void welcomeMessage() {
printf(" _____ _ \n"
" / ____(_) \n"
" | (___ _ __ _ _ __ __ _ _ __ ___ ___ \n"
" \\___ \\| |/ _` | '_ \\ / _` | '_ \\/ __|/ _ \\\n"
" ____) | | (_| | | | | (_| | |_) \\__ \\ __/\n"
" |_____/|_|\\__, |_| |_|\\__,_| .__/|___/\\___|\n"
" __/ | | | \n"
" |___/ |_| \n \nWelcome to Signapse, the tool for helping everyday people learn sign language for free!\n");
}
/*!
* Used to convert an integer index result into a string sign
* @param digit integer index
* @return std::string representing sign at given index
*/
static std::string getLetterFromDigit(int digit) {
return results[digit % results.size()];
}
/*!
* Generates a random sign for use assigning tasks to users.
*
*/
static std::string makeTask() {
srand((unsigned) time(NULL));
int task_int = rand() % NR_TASKS;
return getLetterFromDigit(task_int);
}
/*!
* @return Path of the currently used CNN network. Path given as std::string
*/
static std::string getModelPath() {
return MODEL_PATH;
}
};
/*!
* Declares results array, this may be changed for different CNN output results.
*/
std::vector <std::string> SignapseUtils::results = {"A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M",
"N", "O", "P", "Q", "R", "S", "T", "U", "V",
"W", "X", "Y", "Z", "del", "space", "nothing"};
}

#endif
4 changes: 2 additions & 2 deletions test/gtest_signapseutils.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ TEST(signapseutils_test, checkModelPath_ret){
}

TEST(signapseutils_test, checkMakeTask_int){
int task = SignapseUtils::makeTask();
EXPECT_LE(task, NR_TASKS);
int size = SignapseUtils::results.size();
EXPECT_LE(NR_TASKS, size);
}

0 comments on commit 38e9f2c

Please sign in to comment.