Browse Source

la_mojo: make the Darknet (YOLO filter) build and link

- kernelEventFilterYOLO.h:
  * Darknet V3+ (hank-ai) declares load_network(), load_network_custom()
    and free_network_ptr() only when DARKNET_INCLUDE_ORIGINAL_API is
    defined before darknet.h ("was not declared in this scope"): define it.
  * Darknet installs the header as <prefix>/include/darknet.h, not
    darknet/darknet.h: include <darknet.h>, fall back to
    <darknet/darknet.h>, clear #error if neither exists.
  * m_pNET was DarknetNetworkPtr * (void **) although DarknetNetworkPtr is
    already void *: "invalid conversion from void* to void**".
- makefile / la_mojo.vpj: -ldarknet was only linked in Release86; the
  build script uses Debug86. Added to Debug86 and Debug (the .vpj too,
  so a SlickEdit regeneration keeps it).
- kernelEventFilterYOLO::initFilter(): load the settings first
  (validate()); m_sYOLOFilterData was still zero, so fileExist("") made
  initFilter() always fail. Logs why it fails, frees a previously loaded
  network, logs the network dimensions. Destructor stops the thread
  before freeing the network.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0139veDo3XyavMuVhdnHcN16
pull/17/head
Claude 20 hours ago
parent
commit
9ea7055649
Failed to extract signature
  1. 2
      Projects/la_mojo/la_mojo.vpj
  2. 5
      Projects/la_mojo/makefile
  3. 29
      lib/App/common/kernelEventFilterYOLO.cpp
  4. 15
      lib/App/common/kernelEventFilterYOLO.h

2
Projects/la_mojo/la_mojo.vpj

@ -140,6 +140,7 @@
<Lib File="-lgroupsock"/>
<Lib File="-lBasicUsageEnvironment"/>
<Lib File="-lUsageEnvironment"/>
<Lib File="-ldarknet"/>
</Libs>
</Config>
<Config
@ -372,6 +373,7 @@
<Lib File="-lBasicUsageEnvironment"/>
<Lib File="-lUsageEnvironment"/>
<Lib File="-lsensors"/>
<Lib File="-ldarknet"/>
</Libs>
</Config>
<Config

5
Projects/la_mojo/makefile

@ -26,7 +26,8 @@ CFG_LIB=-lsqlite3 -lpthread -lmysqlclient -lssl -lcurl -lm -lcrypto \
libavdevice libavfilter libavformat libavutil libpostproc \
libswresample libswscale --libs` -latomic `pkg-config --libs openssl \
opencv4 rdkafka++` -L/usr/lib -lrdkafka++ -lrdkafka -lwiringx \
-lliveMedia -lgroupsock -lBasicUsageEnvironment -lUsageEnvironment
-lliveMedia -lgroupsock -lBasicUsageEnvironment -lUsageEnvironment \
-ldarknet
CFG_OBJ=
COMMON_OBJ=$(OUTDIR)/base64.o $(OUTDIR)/basicCameraInfo.o \
$(OUTDIR)/basicDualThread.o $(OUTDIR)/basicEngine.o \
@ -442,7 +443,7 @@ CFG_LIB=-lsqlite3 -lpthread -lmysqlclient -lssl -lcurl -lm -lcrypto \
libavdevice libavfilter libavformat libavutil libpostproc \
libswresample libswscale --libs` -latomic `pkg-config --libs openssl \
opencv4 rdkafka++` -lliveMedia -lgroupsock -lBasicUsageEnvironment \
-lUsageEnvironment -lsensors
-lUsageEnvironment -lsensors -ldarknet
CFG_OBJ=
COMMON_OBJ=$(OUTDIR)/base64.o $(OUTDIR)/basicCameraInfo.o \
$(OUTDIR)/basicDualThread.o $(OUTDIR)/basicEngine.o \

29
lib/App/common/kernelEventFilterYOLO.cpp

@ -21,12 +21,15 @@ basicThread()
// validate() compares it with the database copy: must start defined
memset(&m_sYOLOFilterData, 0, sizeof(YOLO_FILTER_DATA));
m_pNET = NULL;
m_nW = m_nH = m_nC = 0;
}
kernelEventFilterYOLO::~kernelEventFilterYOLO()
{
waitThreadEnd(true);
if ( m_pNET ){
free_network_ptr( m_pNET );
m_pNET = NULL;
};
}
@ -54,8 +57,27 @@ bool kernelEventFilterYOLO::validateTarget(uint32_t DevID, TARGET_DATA * ptr){
}
bool kernelEventFilterYOLO::initFilter(){
if ( !fileExist( m_sYOLOFilterData.config_path ) ) return false;
if ( !fileExist( m_sYOLOFilterData.weights_path ) ) return false;
// The settings must be loaded first: m_sYOLOFilterData was still all zero here, so fileExist("")
// failed and initFilter() could never succeed
if ( !validate() ) {
LOG_ERROR("No YOLO filter settings (getYOLOFilterData returned nothing)");
return false;
};
char tB[160]; // LOG_ERROR formats into a 256-byte buffer (with file and function name): keep it short
if ( !fileExist( m_sYOLOFilterData.config_path ) ) {
snprintf( tB, sizeof(tB), "YOLO config not found: %.120s", m_sYOLOFilterData.config_path );
LOG_ERROR( tB );
return false;
};
if ( !fileExist( m_sYOLOFilterData.weights_path ) ) {
snprintf( tB, sizeof(tB), "YOLO weights not found: %.120s", m_sYOLOFilterData.weights_path );
LOG_ERROR( tB );
return false;
};
if ( m_pNET ) {
free_network_ptr( m_pNET ); // initFilter() called again
m_pNET = NULL;
};
if ( m_sYOLOFilterData.batch ) {
m_pNET = load_network_custom( m_sYOLOFilterData.config_path, m_sYOLOFilterData.weights_path, m_sYOLOFilterData.clear, m_sYOLOFilterData.batch );
} else {
@ -63,8 +85,11 @@ bool kernelEventFilterYOLO::initFilter(){
};
if ( m_pNET ){
darknet_network_dimensions( m_pNET, &m_nW, &m_nH, &m_nC );
snprintf( tB, sizeof(tB), "YOLO network loaded: %dx%dx%d", m_nW, m_nH, m_nC );
LOG( tB );
return true;
}
LOG_ERROR("Darknet could not load the YOLO network");
return false;
}

15
lib/App/common/kernelEventFilterYOLO.h

@ -8,7 +8,18 @@
//#include "../../data/darknet/darknetWraper.h"
//#include <darknet/darknet.hpp>
#include <darknet/darknet.h>
// Darknet (hank-ai, V3+) declares load_network(), load_network_custom() and free_network_ptr() only
// when DARKNET_INCLUDE_ORIGINAL_API is defined before darknet.h ("was not declared in this scope").
#define DARKNET_INCLUDE_ORIGINAL_API
// Darknet's CMake installs the header as <prefix>/include/darknet.h (no darknet/ subdirectory)
#if __has_include(<darknet.h>)
#include <darknet.h>
#elif __has_include(<darknet/darknet.h>)
#include <darknet/darknet.h>
#else
#error "darknet.h not found: install Darknet (libdarknet.so + darknet.h, e.g. the darknet .deb)"
#endif
class kernelEventFilterYOLO : public kernelEventFilter, public basicEventHandler, public basicThread {
private:
@ -17,7 +28,7 @@ class kernelEventFilterYOLO : public kernelEventFilter, public basicEventHandler
basicMutex m_mStateProtector;
basicMutex m_mDataProtector;
//darknetWraper * m_pDarkNet;
DarknetNetworkPtr * m_pNET;
DarknetNetworkPtr m_pNET; // DarknetNetworkPtr is already a pointer (void *)
int m_nW;
int m_nH;
int m_nC;

Loading…
Cancel
Save