@@ -87,11 +87,17 @@ void Usage() {
8787 Quadra quadra;
8888#endif
8989
90+ #undef HAVE_MEMX_H
9091#if HAVE_MEMX_H
9192 #include " zm_memx.h"
9293 MemX *memx;
9394#endif
9495
96+ #if HAVE_MX_ACCL_H
97+ #include " zm_mx_accl.h"
98+ MxAccl *mx_accl;
99+ #endif
100+
95101int main (int argc, char *argv[]) {
96102 self = argv[0 ];
97103
@@ -172,17 +178,30 @@ int main(int argc, char *argv[]) {
172178 return 0 ;
173179 }
174180#endif
181+
175182#if HAVE_MEMX_H
176183 Debug (1 , " Including MemX" );
177184 memx = new MemX ();
178- if (!memx->setup (" yolov5" , " /var/cache/zoneminder/models/YOLO_v5_nano_leaky_416_416_3_tensorflow.dfp" )) {
185+ if (!memx->setup (" yolov8" , " /var/cache/zoneminder/models/YOLO_v8_nano_640_640_3_onnx.dfp" )) {
186+ // if (!memx->setup("yolov5", "/var/cache/zoneminder/models/YOLO_v5_nano_leaky_416_416_3_tensorflow.dfp")) {
179187 delete memx;
180188 memx = nullptr ;
181189 return 0 ;
182190 }
183191#else
184192 Debug (1 , " Not Including MemX" );
185193#endif
194+ #if HAVE_MX_ACCL_H
195+ Debug (1 , " Including MemX_Accl" );
196+ mx_accl = new MxAccl ();
197+ if (!mx_accl->setup (" yolov8" , " /var/cache/zoneminder/models/YOLO_v8_nano_640_640_3_onnx.dfp" )) {
198+ delete mx_accl;
199+ mx_accl = nullptr ;
200+ return 0 ;
201+ }
202+ #else
203+ Debug (1 , " Not Including MXACCL" );
204+ #endif
186205
187206 std::unordered_map<unsigned int , std::shared_ptr<Monitor>> monitors;
188207 std::unordered_map<unsigned int , AIThread *> threads;
@@ -206,6 +225,9 @@ int main(int argc, char *argv[]) {
206225#endif
207226#if HAVE_MEMX_H
208227 , memx
228+ #endif
229+ #if HAVE_MX_ACCL_H
230+ , mx_accl
209231#endif
210232 );
211233 }
@@ -278,6 +300,13 @@ void AIThread::Inference() {
278300 sleep (1 );
279301 }
280302#endif
303+ #ifdef HAVE_MX_ACCL_H
304+ Debug (1 , " Starting for mx_accl" );
305+ while (!terminate_ and !( mx_accl_job = mx_accl->get_job () )) {
306+ Warning (" Waiting for job" );
307+ sleep (1 );
308+ }
309+ #endif
281310
282311#if HAVE_QUADRA
283312#if !SOFT_DRAWBOX
@@ -300,40 +329,35 @@ void AIThread::Inference() {
300329
301330 while (!(terminate_ or zm_terminate)) {
302331 std::shared_ptr<ZMPacket> packet = nullptr ;
303- Debug (1 , " Getting lock" );
332+ Debug (4 , " Getting shm lock" );
304333 // Need to hold the lock because it guards shared_mem as well.
305334 std::unique_lock<std::mutex> lck (mutex_);
306- Debug (1 , " Having lock" );
335+ Debug (4 , " Having lock" );
307336 while (!(send_queue.size () or terminate_)) {
308- Debug (1 , " Waiting" );
309337 condition_.wait (lck);
310- Debug (1 , " Send queue size for monitor %d is %zu" , monitor_->Id (), send_queue.size ());
338+ Debug (4 , " Send queue size for monitor %d is %zu" , monitor_->Id (), send_queue.size ());
311339 }
312340 if (terminate_) break ;
313341 packet = send_queue.front ();
314342
315343 if (packet) {
316344 Monitor::SharedData *shared_data = monitor_->getSharedData ();
317345 Debug (4 , " Sending image %d for monitor %d" , packet->image_index , monitor_->Id ());
318- #ifdef HAVE_UNTETHER_H
319- speedai->send_image (job, packet->image );
320346
321347 Image *ai_image = monitor_->GetAnalysisImage (packet->image_index );
322- nlohmann::json detections = speedai->receive_detections (job, monitor_->ObjectDetection_Object_Threshold ());
323- Debug (1 , " detections %s" , detections.dump ().c_str ());
324348
325- if (detections.size ()) {
326- draw_boxes (packet->image , ai_image, detections, monitor_->LabelSize (), monitor_->LabelSize ());
327- // draw_boxes(drawbox_filter, drawbox_filter_ctx, packet->image, ai_image, detections, monitor_->LabelSize(), monitor_->LabelSize());
328- } else {
329- ai_image->Assign (*packet->image );
330- }
349+ #ifdef HAVE_UNTETHER_H
350+ speedai->send_image (job, packet->image );
351+ nlohmann::json detections = speedai->receive_detections (job, monitor_->ObjectDetection_Object_Threshold ());
331352#endif
332353#ifdef HAVE_MEMX_H
333354 memx->send_image (memx_job, packet->image );
334-
335- Image *ai_image = monitor_->GetAnalysisImage (packet->image_index );
336355 nlohmann::json detections = memx->receive_detections (memx_job, monitor_->ObjectDetection_Object_Threshold ());
356+ #endif
357+ #ifdef HAVE_MX_ACCL_H
358+ mx_accl->send_image (mx_accl_job, packet->image );
359+ nlohmann::json detections = mx_accl->receive_detections (mx_accl_job, monitor_->ObjectDetection_Object_Threshold ());
360+ #endif
337361 Debug (1 , " detections %s" , detections.dump ().c_str ());
338362
339363 if (detections.size ()) {
@@ -342,7 +366,6 @@ void AIThread::Inference() {
342366 } else {
343367 ai_image->Assign (*packet->image );
344368 }
345- #endif
346369
347370 shared_data->last_analysis_index = packet->image_index ;
348371
@@ -436,7 +459,7 @@ void AIThread::Run() {
436459 (send_queue.size () <= static_cast <unsigned int >(image_buffer_count))
437460 ) {
438461 image_index = shared_data->last_decoder_index % image_buffer_count;
439- Debug (3 , " Doing SpeedAI on monitor %d. Decoder index is %d=%d Our index is %d=%d, queue %zu" ,
462+ Debug (3 , " Doing ai on monitor %d. Decoder index is %d=%d Our index is %d=%d, queue %zu" ,
440463 monitor_->Id (),
441464 decoder_image_count, shared_data->last_decoder_index ,
442465 analysis_image_count, image_index, send_queue.size ());
@@ -469,7 +492,7 @@ void AIThread::Run() {
469492 }
470493
471494 } else {
472- Debug (4 , " Not Doing SpeedAI on monitor %d. Decoder count is %d index %d Our count is %d, last_index is %d, index %d" ,
495+ Debug (4 , " Not Doing ai on monitor %d. Decoder count is %d index %d Our count is %d, last_index is %d, index %d" ,
473496 monitor_->Id (), decoder_image_count, shared_data->last_decoder_index ,
474497 shared_data->analysis_image_count , shared_data->last_analysis_index , image_index);
475498
@@ -651,6 +674,9 @@ AIThread::AIThread(const std::shared_ptr<Monitor> monitor
651674#endif
652675#if HAVE_MEMX_H
653676 , MemX *p_memx
677+ #endif
678+ #if HAVE_MX_ACCL_H
679+ , MxAccl *p_mx_accl
654680#endif
655681 ) :
656682 monitor_(monitor), terminate_(false )
@@ -660,6 +686,9 @@ AIThread::AIThread(const std::shared_ptr<Monitor> monitor
660686#if HAVE_MEMX_H
661687 , memx(p_memx)
662688#endif
689+ #if HAVE_MX_ACCL_H
690+ , mx_accl(p_mx_accl)
691+ #endif
663692#if HAVE_QUADRA
664693 ,drawbox_filter(nullptr )
665694#endif
0 commit comments