Skip to content

Commit ca4e04a

Browse files
committed
Added header to the file storing the title decode confidence.
1 parent 2f435e9 commit ca4e04a

2 files changed

Lines changed: 21 additions & 1 deletion

File tree

ReadMagicCard/CardReader.cpp

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@
1313
using namespace cv;
1414
using namespace std;
1515

16+
bool CardReader::m_hasWrittenConfidenceFileHeader = false;
17+
mutex CardReader::m_fileHeaderLock;
18+
1619
CardReader::CardReader(wstring imageFileName, SystemMethods* systemMethods, bool doDebugging)
1720
: BasicReaderData(imageFileName, Mat(), systemMethods, doDebugging)
1821
{
@@ -207,9 +210,21 @@ void CardReader::storeConfidence(int numberOfTries, wstring ocrResult, int ocrCo
207210

208211
wstring textfileName = L"TitleDecodeConfidence.txt";
209212
wstring subfolderName = L"Image Data";
213+
214+
//Make sure the header can't be written by two different threads.
215+
m_fileHeaderLock.lock();
216+
bool writeHeader = !m_hasWrittenConfidenceFileHeader;
217+
m_hasWrittenConfidenceFileHeader = true;
218+
m_fileHeaderLock.unlock();
219+
220+
if (writeHeader) {
221+
222+
wstring rowToAdd = L"Number of tries\tImage file name\tOCR result\tOCR confidence";
223+
FileHandling::AddRowToFile(systemMethods, rowToAdd, textfileName, subfolderName);
224+
}
225+
210226
wstring numberOfTriesStr = systemMethods->ToWString(to_string(numberOfTries));
211227
wstring confidenceStr = systemMethods->ToWString(to_string(ocrConfidence));
212-
213228
wstring rowToAdd = numberOfTriesStr + L"\t" + imageFileName + L"\t" + ocrResult + L"\t" + confidenceStr;
214229
FileHandling::AddRowToFile(systemMethods, rowToAdd, textfileName, subfolderName);
215230
}

ReadMagicCard/CardReader.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
#include "BasicReaderData.h"
33
#include "CardTitleType.h"
44
#include "OcrDecodeResult.h"
5+
#include <mutex>
56
//Class for reading a card.
67
class CardReader :
78
BasicReaderData
@@ -44,4 +45,8 @@ class CardReader :
4445
bool m_success = false;
4546
//Tells how confident Tesseract was of decoding the title.
4647
int m_confidence = 0;
48+
//Lock preventing multiple threads from writing the header in the file storing the title decode confidence.
49+
static std::mutex m_fileHeaderLock;
50+
//Tells if the header in the file storing the title decode confidence has been written.
51+
static bool m_hasWrittenConfidenceFileHeader;
4752
};

0 commit comments

Comments
 (0)