@@ -77,50 +77,49 @@ static PyObject *DynamsoftDocumentScanner_new(PyTypeObject *type, PyObject *args
7777 return (PyObject *)self;
7878}
7979
80- // PyObject *createPyList(DLR_ResultArray *pResults)
81- // {
82- // int count = pResults->resultsCount;
83-
84- // // Create a Python object to store results
85- // PyObject *list = PyList_New(0);
86- // for (int i = 0; i < count; i++)
87- // {
88- // DLR_Result *mrzResult = pResults->results[i];
89- // int lCount = mrzResult->lineResultsCount;
90- // for (int j = 0; j < lCount; j++)
91- // {
92- // // printf("Line result %d: %s\n", j, mrzResult->lineResults[j]->text);
93-
94- // DM_Point *points = mrzResult->lineResults[j]->location.points;
95- // int x1 = points[0].x;
96- // int y1 = points[0].y;
97- // int x2 = points[1].x;
98- // int y2 = points[1].y;
99- // int x3 = points[2].x;
100- // int y3 = points[2].y;
101- // int x4 = points[3].x;
102- // int y4 = points[3].y;
103- // DocumentResult *result = PyObject_New(DocumentResult, &DocumentResultType);
104- // result->confidence = Py_BuildValue("i", mrzResult->lineResults[j]->confidence);
105- // result->text = PyUnicode_FromString(mrzResult->lineResults[j]->text);
106- // result->x1 = Py_BuildValue("i", x1);
107- // result->y1 = Py_BuildValue("i", y1);
108- // result->x2 = Py_BuildValue("i", x2);
109- // result->y2 = Py_BuildValue("i", y2);
110- // result->x3 = Py_BuildValue("i", x3);
111- // result->y3 = Py_BuildValue("i", y3);
112- // result->x4 = Py_BuildValue("i", x4);
113- // result->y4 = Py_BuildValue("i", y4);
114-
115- // PyList_Append(list, (PyObject *)result);
116- // }
117- // }
118-
119- // return list;
120- // }
80+ PyObject *createPyList (DetectedQuadResultArray *pResults)
81+ {
82+ // Create a Python object to store results
83+ PyObject *list = PyList_New (0 );
84+
85+ if (pResults)
86+ {
87+ int count = pResults->resultsCount ;
88+
89+ for (int i = 0 ; i < count; i++)
90+ {
91+ DetectedQuadResult *quadResult = pResults->detectedQuadResults [i];
92+ int confidence = quadResult->confidenceAsDocumentBoundary ;
93+ DM_Point *points = quadResult->location ->points ;
94+ int x1 = points[0 ].coordinate [0 ];
95+ int y1 = points[0 ].coordinate [1 ];
96+ int x2 = points[1 ].coordinate [0 ];
97+ int y2 = points[1 ].coordinate [1 ];
98+ int x3 = points[2 ].coordinate [0 ];
99+ int y3 = points[2 ].coordinate [1 ];
100+ int x4 = points[3 ].coordinate [0 ];
101+ int y4 = points[3 ].coordinate [1 ];
102+
103+ DocumentResult *result = PyObject_New (DocumentResult, &DocumentResultType);
104+ result->confidence = Py_BuildValue (" i" , confidence);
105+ result->x1 = Py_BuildValue (" i" , x1);
106+ result->y1 = Py_BuildValue (" i" , y1);
107+ result->x2 = Py_BuildValue (" i" , x2);
108+ result->y2 = Py_BuildValue (" i" , y2);
109+ result->x3 = Py_BuildValue (" i" , x3);
110+ result->y3 = Py_BuildValue (" i" , y3);
111+ result->x4 = Py_BuildValue (" i" , x4);
112+ result->y4 = Py_BuildValue (" i" , y4);
113+
114+ PyList_Append (list, (PyObject *)result);
115+ }
116+ }
117+
118+ return list;
119+ }
121120
122121/* *
123- * Recognize MRZ from image files.
122+ * Recognize document from image files.
124123 *
125124 * @param string filename
126125 *
@@ -136,24 +135,25 @@ static PyObject *decodeFile(PyObject *obj, PyObject *args)
136135 return NULL ;
137136 }
138137
139- NormalizedImageResult* normalizedResult = NULL ;
140- int ret = DDN_NormalizeFile (self->handler , pFileName, " " , NULL , &normalizedResult);
138+ DetectedQuadResultArray *pResults = NULL ;
139+
140+ int ret = DDN_DetectQuadFromFile (self->handler , pFileName, " " , &pResults);
141141 if (ret)
142142 {
143143 printf (" Detection error: %s\n " , DC_GetErrorString (ret));
144144 }
145145
146- PyObject *list = NULL ;
146+ PyObject *list = createPyList (pResults) ;
147147
148148 // Release memory
149- if (normalizedResult != NULL )
150- DDN_FreeNormalizedImageResult (&normalizedResult );
149+ if (pResults != NULL )
150+ DDN_FreeDetectedQuadResultArray (&pResults );
151151
152152 return list;
153153}
154154
155155/* *
156- * Recognize MRZ from OpenCV Mat.
156+ * Recognize document from OpenCV Mat.
157157 *
158158 * @param Mat image
159159 *
@@ -207,29 +207,30 @@ static PyObject *decodeMat(PyObject *obj, PyObject *args)
207207 data.format = format;
208208 data.bytesLength = len;
209209
210- NormalizedImageResult* normalizedResult = NULL ;
211- int ret = DDN_NormalizeBuffer (self->handler , &data, " " , NULL , &normalizedResult);
210+ DetectedQuadResultArray *pResults = NULL ;
211+
212+ int ret = DDN_DetectQuadFromBuffer (self->handler , &data, " " , &pResults);
212213 if (ret)
213214 {
214215 printf (" Detection error: %s\n " , DC_GetErrorString (ret));
215216 }
216217
217- PyObject *list = NULL ;
218+ PyObject *list = createPyList (pResults) ;
218219
219220 // Release memory
220- if (normalizedResult != NULL )
221- DDN_FreeNormalizedImageResult (&normalizedResult );
221+ if (pResults != NULL )
222+ DDN_FreeDetectedQuadResultArray (&pResults );
222223
223224 Py_DECREF (memoryview);
224225
225226 return list;
226227}
227228
228- void onResultReady (DynamsoftDocumentScanner *self)
229+ void onResultReady (DynamsoftDocumentScanner *self, DetectedQuadResultArray *pResults )
229230{
230231 PyGILState_STATE gstate;
231232 gstate = PyGILState_Ensure ();
232- PyObject *list = NULL ;
233+ PyObject *list = createPyList (pResults) ;
233234 PyObject *result = PyObject_CallFunction (self->callback , " O" , list);
234235 if (result != NULL )
235236 Py_DECREF (result);
@@ -247,23 +248,23 @@ void scan(DynamsoftDocumentScanner *self, unsigned char *buffer, int width, int
247248 data.format = format;
248249 data.bytesLength = len;
249250
250- NormalizedImageResult* normalizedResult = NULL ;
251- int ret = DDN_NormalizeBuffer (self->handler , &data, " " , NULL , &normalizedResult );
251+ DetectedQuadResultArray *pResults = NULL ;
252+ int ret = DDN_DetectQuadFromBuffer (self->handler , &data, " " , &pResults );
252253 if (ret)
253254 {
254255 printf (" Detection error: %s\n " , DC_GetErrorString (ret));
255256 }
256257
257- // Release memory
258- if (normalizedResult != NULL )
259- DDN_FreeNormalizedImageResult (&normalizedResult);
260-
261258 free (buffer);
262- onResultReady (self);
259+ onResultReady (self, pResults);
260+
261+ // Release memory
262+ if (pResults != NULL )
263+ DDN_FreeDetectedQuadResultArray (&pResults);
263264}
264265
265266/* *
266- * Recognize MRZ from OpenCV Mat asynchronously.
267+ * Recognize document from OpenCV Mat asynchronously.
267268 *
268269 * @param Mat image
269270 *
@@ -346,7 +347,7 @@ void run(DynamsoftDocumentScanner *self)
346347}
347348
348349/* *
349- * Register callback function to receive MRZ decoding result asynchronously.
350+ * Register callback function to receive document decoding result asynchronously.
350351 */
351352static PyObject *addAsyncListener (PyObject *obj, PyObject *args)
352353{
0 commit comments