@@ -26,7 +26,7 @@ typedef struct {
26
26
void * handle ;
27
27
int (* sod_cnn_create )(void * * ppOut , const char * zArch , const char * zModelPath , const char * * pzErr );
28
28
int (* sod_cnn_config )(void * pNet , int conf , ...);
29
- int (* sod_cnn_predict )(void * pNet , float * pInput , void * * * paBox , int * pnBox );
29
+ int (* sod_cnn_predict )(void * pNet , float * pInput , sod_box * * paBox , int * pnBox );
30
30
void (* sod_cnn_destroy )(void * pNet );
31
31
float * (* sod_cnn_prepare_image )(void * pNet , void * in );
32
32
int (* sod_cnn_get_network_size )(void * pNet , int * pWidth , int * pHeight , int * pChannels );
@@ -226,7 +226,7 @@ detection_model_t load_sod_model(const char *model_path, float threshold) {
226
226
}
227
227
228
228
// Use dynamic loading
229
- sod_funcs .sod_cnn_config (sod_model , SOD_CNN_DETECTION_THRESHOLD , threshold );
229
+ sod_funcs .sod_cnn_config (( sod_cnn * ) sod_model , SOD_CNN_DETECTION_THRESHOLD , threshold );
230
230
#else
231
231
// Use static linking
232
232
sod_cnn * cnn_model = NULL ;
@@ -304,33 +304,29 @@ int detect_with_sod_model(detection_model_t model, const unsigned char *frame_da
304
304
log_info ("Step 1: Creating SOD image from frame data (dimensions: %dx%d, channels: %d)" ,
305
305
width , height , channels );
306
306
307
- void * img_ptr = sod_funcs .sod_make_image (width , height , channels );
308
- if (!img_ptr ) {
307
+ // In dynamic linking, sod_make_image returns a sod_img, not a pointer to sod_img
308
+ sod_img img ;
309
+ memset (& img , 0 , sizeof (sod_img ));
310
+
311
+ // Call sod_make_image and store the result directly
312
+ img = * (sod_img * )sod_funcs .sod_make_image (width , height , channels );
313
+
314
+ if (!img .data ) {
309
315
log_error ("Failed to create SOD image" );
310
316
return -1 ;
311
317
}
312
318
313
319
// Step 2: Copy the frame data to the SOD image
314
320
log_info ("Step 2: Copying frame data to SOD image" );
315
321
316
- // Cast the void* to sod_img*
317
- sod_img * sod_img_ptr = (sod_img * )img_ptr ;
318
-
319
- // Check if the data field is valid
320
- if (!sod_img_ptr -> data ) {
321
- log_error ("SOD image data field is NULL" );
322
- sod_funcs .sod_free_image (img_ptr );
323
- return -1 ;
324
- }
325
-
326
322
// Calculate the total size of the image data
327
323
size_t total_size = width * height * channels ;
328
324
329
325
// Allocate a temporary buffer to store the converted data
330
326
float * temp_buffer = (float * )malloc (total_size * sizeof (float ));
331
327
if (!temp_buffer ) {
332
328
log_error ("Failed to allocate temporary buffer for image data conversion" );
333
- sod_funcs .sod_free_image (img_ptr );
329
+ sod_funcs .sod_free_image (& img );
334
330
return -1 ;
335
331
}
336
332
@@ -354,7 +350,7 @@ int detect_with_sod_model(detection_model_t model, const unsigned char *frame_da
354
350
}
355
351
356
352
// Copy the converted data to the SOD image
357
- memcpy (sod_img_ptr -> data , temp_buffer , total_size * sizeof (float ));
353
+ memcpy (img . data , temp_buffer , total_size * sizeof (float ));
358
354
359
355
// Free the temporary buffer
360
356
free (temp_buffer );
@@ -363,10 +359,10 @@ int detect_with_sod_model(detection_model_t model, const unsigned char *frame_da
363
359
364
360
// Step 3: Prepare the image for CNN detection
365
361
log_info ("Step 4: Preparing image for CNN detection with model=%p" , (void * )m -> sod .model );
366
- float * prepared_data = sod_funcs .sod_cnn_prepare_image (m -> sod .model , img_ptr );
362
+ float * prepared_data = sod_funcs .sod_cnn_prepare_image (( sod_cnn * ) m -> sod .model , & img );
367
363
if (!prepared_data ) {
368
364
log_error ("Failed to prepare image for CNN detection" );
369
- sod_funcs .sod_free_image (img_ptr );
365
+ sod_funcs .sod_free_image (& img );
370
366
return -1 ;
371
367
}
372
368
@@ -375,22 +371,22 @@ int detect_with_sod_model(detection_model_t model, const unsigned char *frame_da
375
371
// Step 4: Run detection
376
372
log_info ("Step 6: Running CNN detection" );
377
373
int count = 0 ;
378
- void * * boxes_ptr = NULL ;
379
374
380
375
// Add extra safety check
381
376
if (!m -> sod .model ) {
382
377
log_error ("Model pointer is NULL before prediction" );
383
- sod_funcs .sod_free_image (img_ptr );
378
+ sod_funcs .sod_free_image (& img );
384
379
return -1 ;
385
380
}
386
381
387
382
// Step 5: Call predict
388
- int rc = sod_funcs .sod_cnn_predict (m -> sod .model , prepared_data , & boxes_ptr , & count );
383
+ sod_box * boxes = NULL ;
384
+ int rc = sod_funcs .sod_cnn_predict ((sod_cnn * )m -> sod .model , prepared_data , & boxes , & count );
389
385
log_info ("Step 7: sod_cnn_predict returned with rc=%d, count=%d" , rc , count );
390
386
391
387
if (rc != 0 ) { // SOD_OK is 0
392
388
log_error ("CNN detection failed with error code: %d" , rc );
393
- sod_funcs .sod_free_image (img_ptr );
389
+ sod_funcs .sod_free_image (& img );
394
390
return -1 ;
395
391
}
396
392
@@ -403,21 +399,19 @@ int detect_with_sod_model(detection_model_t model, const unsigned char *frame_da
403
399
// Process detection results
404
400
int valid_count = 0 ;
405
401
406
- // Skip processing boxes if count is 0 or boxes_ptr is NULL
407
- if (count <= 0 || !boxes_ptr ) {
408
- log_warn ("No detection boxes returned (count=%d, boxes_ptr =%p)" , count , (void * )boxes_ptr );
409
- sod_funcs .sod_free_image (img_ptr );
402
+ // Skip processing boxes if count is 0 or boxes is NULL
403
+ if (count <= 0 || !boxes ) {
404
+ log_warn ("No detection boxes returned (count=%d, boxes =%p)" , count , (void * )boxes );
405
+ sod_funcs .sod_free_image (& img );
410
406
return 0 ;
411
407
}
412
408
413
409
log_info ("Processing %d detection boxes" , count );
414
410
415
- // In SOD, boxes_ptr is an array of pointers to sod_box structures
416
- sod_box_dynamic * * boxes_array = (sod_box_dynamic * * )boxes_ptr ;
417
-
411
+ // For dynamic linking, boxes is already an array of sod_box structures
418
412
for (int i = 0 ; i < count && valid_count < MAX_DETECTIONS ; i ++ ) {
419
413
// Get the current box
420
- sod_box_dynamic * box = boxes_array [i ];
414
+ sod_box * box = & boxes [i ];
421
415
422
416
if (!box ) {
423
417
log_warn ("Box %d is NULL, skipping" , i );
@@ -475,7 +469,7 @@ int detect_with_sod_model(detection_model_t model, const unsigned char *frame_da
475
469
476
470
// Step 7: Free the image data
477
471
log_info ("Step 9: Freeing SOD image" );
478
- sod_funcs .sod_free_image (img_ptr );
472
+ sod_funcs .sod_free_image (& img );
479
473
#else
480
474
// When SOD is statically linked, use direct function calls
481
475
log_info ("Using statically linked SOD functions" );
0 commit comments