Skip to content

Commit e3043fb

Browse files
committed
Improvements
- Better painting graphics - Better timing sampling - Disabling (for now) DirectML - Updated GIF
1 parent 3da0286 commit e3043fb

File tree

7 files changed

+49
-31
lines changed

7 files changed

+49
-31
lines changed

HandOCRVeryfier.aps

360 Bytes
Binary file not shown.

HandOCRVeryfier.rc

-4 Bytes
Binary file not shown.

example_ocr.gif

34.7 KB
Loading

src/CSetupDlg.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,10 +124,12 @@ void CSetupDlg::OnBnClickedOk()
124124
UpdateData(1);
125125
theApp.ocr.LoadModel(netPath, labelsPath);
126126

127+
ShowWindow(0);
128+
127129
CHandOCRVeryfierDlg dlg;
128130
dlg.DoModal();
129131

130-
CDialog::OnOK();
132+
ShowWindow(1);
131133
}
132134

133135

src/HandOCRVeryfierDlg.cpp

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,16 @@
88
#include "HandOCRVeryfierDlg.h"
99
#include "afxdialogex.h"
1010

11+
#include <chrono>
12+
1113
#ifdef _DEBUG
1214
#define new DEBUG_NEW
1315
#endif
1416

17+
typedef std::chrono::high_resolution_clock Time;
18+
typedef std::chrono::milliseconds ms;
19+
typedef std::chrono::duration<float> fsec;
20+
1521
extern CHandOCRVeryfierApp theApp;
1622

1723
// Finestra di dialogo CHandOCRVeryfierDlg
@@ -142,11 +148,12 @@ void CHandOCRVeryfierDlg::OnBnClickedDetect()
142148
int best = 0;
143149
bool success;
144150

145-
INT64 start, end;
146-
147-
start = GetTickCount64();
151+
auto start = Time::now();
148152
success = theApp.ocr.Predict(img, &scores, best);
149-
end = GetTickCount64();
153+
auto end = Time::now();
154+
155+
fsec fs = end - start;
156+
ms d = std::chrono::duration_cast<ms>(fs);
150157

151158
if (success)
152159
{
@@ -155,7 +162,7 @@ void CHandOCRVeryfierDlg::OnBnClickedDetect()
155162

156163
text.Format(_T("%s %.2f"), theApp.ocr.labels[best], score);
157164
text += _T("% (");
158-
text += std::to_wstring(end - start).c_str();
165+
text += std::to_wstring(d.count()).c_str();
159166
text += "ms)";
160167

161168
SetWindowText(text);

src/OCR.cpp

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -73,23 +73,28 @@ bool OCR::Predict(BYTE* buffer, float** scores, int& best)
7373
best = bestInd;
7474
*scores = probs;
7575

76+
delete inputNet;
77+
7678
return true;
7779
}
7880

7981
bool OCR::StartModel(CString netPath, CString labelPath)
8082
{
83+
if (session)
84+
StopModel();
85+
8186
Ort::SessionOptions sessionOptions;
8287

83-
OrtStatus* onnxStatus = OrtSessionOptionsAppendExecutionProvider_DML(sessionOptions, 0);
84-
85-
if (onnxStatus)
86-
{
87-
const OrtApi* g_ort = OrtGetApiBase()->GetApi(ORT_API_VERSION);
88+
//OrtStatus* onnxStatus = OrtSessionOptionsAppendExecutionProvider_DML(sessionOptions, 0);
89+
//
90+
//if (onnxStatus)
91+
//{
92+
// const OrtApi* g_ort = OrtGetApiBase()->GetApi(ORT_API_VERSION);
8893

89-
CString msg(g_ort->GetErrorMessage(onnxStatus));
94+
// CString msg(g_ort->GetErrorMessage(onnxStatus));
9095

91-
MessageBox(NULL, msg, _T("Error DirectML"), MB_OK);
92-
}
96+
// MessageBox(NULL, msg, _T("Error DirectML"), MB_OK);
97+
//}
9398

9499
sessionOptions.SetGraphOptimizationLevel(GraphOptimizationLevel::ORT_ENABLE_ALL);
95100

src/PaintCtrl.cpp

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44

55
PaintCtrl::PaintCtrl(HWND pParent, int width, int height, int wPaint, int hPaint)
66
{
7+
if (pParent)
8+
SubclassWindow(pParent);
9+
710
if (width < 0)
811
width = 1;
912

@@ -16,28 +19,29 @@ PaintCtrl::PaintCtrl(HWND pParent, int width, int height, int wPaint, int hPaint
1619
if (hPaint < 0)
1720
hPaint = 1;
1821

19-
this->width = width;
20-
this->height = height;
22+
GetClientRect(&rectClient);
23+
24+
this->width = rectClient.Width();
25+
this->height = rectClient.Height();
2126
this->wPaint = wPaint;
2227
this->hPaint = hPaint;
2328

24-
if (pParent)
25-
SubclassWindow(pParent);
2629

27-
GetClientRect(&rectClient);
2830

29-
drawLUT = new bool* [width];
3031

31-
for (int x = 0; x < width; x++)
32+
33+
drawLUT = new bool* [this->width];
34+
35+
for (int x = 0; x < this->width; x++)
3236
{
33-
drawLUT[x] = new bool[height];
37+
drawLUT[x] = new bool[this->height];
3438

35-
for (int y = 0; y < height; y++)
39+
for (int y = 0; y < this->height; y++)
3640
drawLUT[x][y] = 0;
3741
}
3842

39-
coeffX = (double)width / (double)rectClient.Width();
40-
coeffY = (double)height / (double)rectClient.Height();
43+
coeffX = (double)this->width / (double)rectClient.Width();
44+
coeffY = (double)this->height / (double)rectClient.Height();
4145

4246
CDC* pDC = this->GetDC();
4347

@@ -169,8 +173,8 @@ void PaintCtrl::OnMouseMove(UINT nFlags, CPoint point)
169173
if (!isPressing)
170174
return;
171175

172-
int x = coeffX * point.x;
173-
int y = coeffY * point.y;
176+
int x = (int)(coeffX * (double)point.x + 0.5);
177+
int y = (int)(coeffY * (double)point.y + 0.5);
174178

175179
for (int i = max(0, x - wPaint / 2); i <= min(width - 1, x + wPaint / 2); i++)
176180
for (int j = max(0, y - hPaint / 2); j <= min(height - 1, y + hPaint / 2); j++)
@@ -203,18 +207,18 @@ void PaintCtrl::UpdateDisplay()
203207
{
204208
if (drawLUT[x][y])
205209
{
206-
point.x = x / coeffX;
207-
point.y = y / coeffY;
210+
point.x = x;// (int)((double)x / coeffX + 0.5);
211+
point.y = y;// (int)((double)y / coeffY + 0.5);
208212

209-
//shadowMem.FillSolidRect(point.x - widthPaint / 2, point.y - heightPaint / 2, widthPaint, heightPaint, RGB(0, 0, 0));
213+
//shadowMem.FillSolidRect(point.x - wPaint / 2, point.y - hPaint / 2, wPaint, hPaint, RGB(0, 0, 0));
210214
//shadowMem.SetPixel(point, RGB(0, 0, 0));
211215

212216
ptr = &curBuffer[point.y * rectClient.Width() * 4 + point.x * 4];
213217

214218
*ptr++ = 0;
215219
*ptr++ = 0;
216220
*ptr++ = 0;
217-
*ptr++ = 0;
221+
*ptr++ = 255;
218222
}
219223
}
220224

0 commit comments

Comments
 (0)