Skip to content

Commit 7946616

Browse files
committed
Simplify code logic
1 parent d647118 commit 7946616

1 file changed

Lines changed: 25 additions & 69 deletions

File tree

litecam/examples/mrz/main.cpp

Lines changed: 25 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -182,80 +182,37 @@ std::mutex textResultsMutex;
182182
class MyCapturedResultReceiver : public CCapturedResultReceiver
183183
{
184184
public:
185-
virtual void OnRecognizedTextLinesReceived(CRecognizedTextLinesResult *pResult) override
185+
virtual void OnCapturedResultReceived(CCapturedResult *capturedResult) override
186186
{
187187
std::lock_guard<std::mutex> lock(textResultsMutex);
188188
textResults.clear();
189189

190-
const CImageTag *tag = pResult->GetOriginalImageTag();
191-
192-
if (tag == nullptr)
190+
CRecognizedTextLinesResult *textLineResult = capturedResult->GetRecognizedTextLinesResult();
191+
if (textLineResult == nullptr)
193192
{
194193
return;
195194
}
196195

197-
if (pResult->GetErrorCode() != EC_OK)
198-
{
199-
cout << "Error: " << pResult->GetErrorString() << endl;
200-
}
201-
else
196+
int lCount = textLineResult->GetItemsCount();
197+
for (int li = 0; li < lCount; ++li)
202198
{
203-
int lCount = pResult->GetItemsCount();
204-
for (int li = 0; li < lCount; ++li)
205-
{
206-
TextResult result;
199+
TextResult textResult;
207200

208-
const CTextLineResultItem *textLine = pResult->GetItem(li);
209-
CPoint *points = textLine->GetLocation().points;
210-
result.textLinePoints.push_back(Point(points[0][0], points[0][1]));
211-
result.textLinePoints.push_back(Point(points[1][0], points[1][1]));
212-
result.textLinePoints.push_back(Point(points[2][0], points[2][1]));
213-
result.textLinePoints.push_back(Point(points[3][0], points[3][1]));
201+
const CTextLineResultItem *textLine = textLineResult->GetItem(li);
202+
CPoint *points = textLine->GetLocation().points;
203+
textResult.textLinePoints.push_back(Point(points[0][0], points[0][1]));
204+
textResult.textLinePoints.push_back(Point(points[1][0], points[1][1]));
205+
textResult.textLinePoints.push_back(Point(points[2][0], points[2][1]));
206+
textResult.textLinePoints.push_back(Point(points[3][0], points[3][1]));
214207

215-
result.id = tag->GetImageId();
216-
textResults.push_back(result);
217-
}
218-
}
219-
}
208+
const CParsedResultItem *item = capturedResult->GetParsedResult()->GetItem(li);
209+
MRZResult mrzResult;
210+
mrzResult.FromParsedResultItem(item);
220211

221-
virtual void OnParsedResultsReceived(CParsedResult *pResult)
222-
{
223-
if (pResult == nullptr)
224-
{
225-
return;
226-
}
212+
textResult.info = mrzResult;
227213

228-
const CImageTag *tag = pResult->GetOriginalImageTag();
229-
230-
if (tag == nullptr)
231-
{
232-
return;
214+
textResults.push_back(textResult);
233215
}
234-
235-
if (pResult->GetErrorCode() != EC_OK)
236-
{
237-
cout << "Error: " << pResult->GetErrorString() << endl;
238-
}
239-
else
240-
{
241-
int lCount = pResult->GetItemsCount();
242-
for (int i = 0; i < lCount; i++)
243-
{
244-
const CParsedResultItem *item = pResult->GetItem(i);
245-
246-
MRZResult result;
247-
result.FromParsedResultItem(item);
248-
cout << result.ToString() << endl;
249-
250-
if (textResults[0].id == tag->GetImageId())
251-
{
252-
std::lock_guard<std::mutex> lock(textResultsMutex);
253-
textResults[0].info = result;
254-
}
255-
}
256-
}
257-
258-
pResult->Release();
259216
}
260217
};
261218

@@ -280,9 +237,8 @@ int main()
280237
{
281238
int iRet = -1;
282239
char szErrorMsg[256];
283-
// Initialize license.
284240
// Request a trial from https://www.dynamsoft.com/customer/license/trialLicense/?product=dcv&package=cross-platform
285-
iRet = CLicenseManager::InitLicense("LICENSE-KEY", szErrorMsg, 256);
241+
iRet = CLicenseManager::InitLicense("DLS2eyJoYW5kc2hha2VDb2RlIjoiMjAwMDAxLTE2NDk4Mjk3OTI2MzUiLCJvcmdhbml6YXRpb25JRCI6IjIwMDAwMSIsInNlc3Npb25QYXNzd29yZCI6IndTcGR6Vm05WDJrcEQ5YUoifQ==", szErrorMsg, 256);
286242
if (iRet != EC_OK)
287243
{
288244
std::cout << szErrorMsg << std::endl;
@@ -313,6 +269,12 @@ int main()
313269

314270
if (camera.Open(0))
315271
{
272+
// bool success = camera.SetResolution(1280, 720);
273+
// if (!success)
274+
// {
275+
// std::cerr << "Failed to set resolution." << std::endl;
276+
// return -1;
277+
// }
316278
// Create a window
317279
CameraWindow window(camera.frameWidth, camera.frameHeight, "Camera Stream");
318280
if (!window.Create())
@@ -334,18 +296,13 @@ int main()
334296
// Display the frame
335297
window.ShowFrame(frame.rgbData, frame.width, frame.height);
336298

337-
CFileImageTag tag(nullptr, 0, 0);
338-
tag.SetImageId(i);
339-
i++;
340-
if (i == 10000)
341-
i = 0;
342299
CImageData data(frame.size,
343300
frame.rgbData,
344301
frame.width,
345302
frame.height,
346303
frame.width * 3,
347304
IPF_RGB_888,
348-
0, &tag);
305+
0, 0);
349306

350307
fetcher->MyAddImageToBuffer(&data);
351308

@@ -409,4 +366,3 @@ int main()
409366
std::cout << "Done.\n";
410367
return 0;
411368
}
412-
/////

0 commit comments

Comments
 (0)