Browse Source

itermediate

pull/18/head
Evgeny Gagua 16 hours ago
parent
commit
b550f2a9c9
  1. 25
      Projects/la_mojo/la_mojo.vpj
  2. 21
      Projects/la_mojo/makefile
  3. 6
      lib/App/common/dataBinder_structures.h
  4. 1
      lib/App/common/deviceNodeCamera.cpp
  5. 1
      lib/App/common/deviceNodeCamera.h
  6. 47
      lib/App/common/deviceNodePTZCamControl.cpp
  7. 113
      lib/App/common/kernelEventFilterYOLO.cpp
  8. 24
      lib/App/common/kernelEventFilterYOLO.h
  9. 5
      lib/App/common/kernelModuleEmbedVideo.cpp
  10. 5
      lib/App/common/kernelModuleEmbedVideo.h
  11. 6
      lib/components/base/basicEvent.h

25
Projects/la_mojo/la_mojo.vpj

@ -176,7 +176,7 @@
RunFromDir="%rw">
<Exec
CmdLine='g++ %xup -O3 -w %~other -o "%o" %objs'
OtherOptions="-lconfig -lpthread -lmysqlclient -lelf -lcurses -lcdk -lcurl `pkg-config --libs rdkafka++` -L/usr/lib -lrdkafka++ -lrdkafka -lwiringx -lsqlite3 -s"/>
OtherOptions="-s"/>
</Target>
<Target
Name="Build"
@ -241,7 +241,25 @@
Value="Executable"/>
</List>
<Includes></Includes>
<Libs PreObjects="0"/>
<Libs PreObjects="0">
<Lib File="-lconfig"/>
<Lib File="-lpthread"/>
<Lib File="-lmysqlclient"/>
<Lib File="-lelf"/>
<Lib File="-lcurses"/>
<Lib File="-lcdk"/>
<Lib File="-lcurl"/>
<Lib File="`pkg-config"/>
<Lib File="--libs"/>
<Lib File="rdkafka++`"/>
<Lib File="-L/usr/lib"/>
<Lib File="-lrdkafka++"/>
<Lib File="-lrdkafka"/>
<Lib File="-lwiringx"/>
<Lib File="-lsqlite3"/>
<Lib File="-ldarknet"/>
<Lib File="-lsensors"/>
</Libs>
</Config>
<Config
Name="Debug86"
@ -372,8 +390,8 @@
<Lib File="-lgroupsock"/>
<Lib File="-lBasicUsageEnvironment"/>
<Lib File="-lUsageEnvironment"/>
<Lib File="-lsensors"/>
<Lib File="-ldarknet"/>
<Lib File="-lsensors"/>
</Libs>
</Config>
<Config
@ -506,6 +524,7 @@
<Lib File="-lBasicUsageEnvironment"/>
<Lib File="-lUsageEnvironment"/>
<Lib File="-ldarknet"/>
<Lib File="-lsensors"/>
</Libs>
</Config>
<Config

21
Projects/la_mojo/makefile

@ -146,7 +146,8 @@ ALL_OBJ=$(OUTDIR)/base64.o $(OUTDIR)/basicCameraInfo.o \
libavcodec 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
COMPILE=g++ -c -x c++ "-DDEBUG" "-D__STDC_CONSTANT_MACROS__" "-D_CLIENT_APPLICATION_" "-D_OPENCV_" "-DRASPI_HARDWARE" -O0 -w -Wpointer-arith -std=c++17 -Wno-write-strings -I../../lib/include `pkg-config opencv4 libavcodec libavdevice libavfilter libavformat libavutil libpostproc libswresample libswscale live555 --cflags` -o "$(OUTDIR)/$(*F).o" $(CFG_INC) $<
LINK=g++ -O0 -w -o "$(OUTFILE)" $(ALL_OBJ)
@ -235,7 +236,9 @@ ifeq "$(CFG)" "Release"
OUTDIR=Release
OUTFILE=$(OUTDIR)/mojo
CFG_INC=
CFG_LIB=
CFG_LIB=-lconfig -lpthread -lmysqlclient -lelf -lcurses -lcdk -lcurl \
`pkg-config --libs rdkafka++` -L/usr/lib -lrdkafka++ -lrdkafka \
-lwiringx -lsqlite3 -ldarknet -lsensors
CFG_OBJ=
COMMON_OBJ=$(OUTDIR)/base64.o $(OUTDIR)/basicCameraInfo.o \
$(OUTDIR)/basicDualThread.o $(OUTDIR)/basicEngine.o \
@ -349,10 +352,12 @@ ALL_OBJ=$(OUTDIR)/base64.o $(OUTDIR)/basicCameraInfo.o \
$(OUTDIR)/streamHandler.o $(OUTDIR)/targetPipeLine.o \
$(OUTDIR)/Transform.o $(OUTDIR)/transportSocket.o $(OUTDIR)/utm.o \
$(OUTDIR)/videoAVLIBSource.o $(OUTDIR)/videoLive555AVLibSource.o \
$(OUTDIR)/xmlParser.o
$(OUTDIR)/xmlParser.o -lconfig -lpthread -lmysqlclient -lelf \
-lcurses -lcdk -lcurl `pkg-config --libs rdkafka++` -L/usr/lib \
-lrdkafka++ -lrdkafka -lwiringx -lsqlite3 -ldarknet -lsensors
COMPILE=g++ -c -x c++ "-DSLIM_KERNEL" "-D_THREAD_SAFE" "-D_BSD_SOURCE" "-D_REENTRANT" -O3 -w -Wpointer-arith -std=gnu++17 -I../../lib/include -o "$(OUTDIR)/$(*F).o" $(CFG_INC) $<
LINK=g++ -O3 -w -lconfig -lpthread -lmysqlclient -lelf -lcurses -lcdk -lcurl `pkg-config --libs rdkafka++` -L/usr/lib -lrdkafka++ -lrdkafka -lwiringx -lsqlite3 -s -o "$(OUTFILE)" $(ALL_OBJ)
LINK=g++ -O3 -w -s -o "$(OUTFILE)" $(ALL_OBJ)
# Pattern rules
$(OUTDIR)/%.o : ../../lib/components/object/%.cpp
@ -443,7 +448,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 -ldarknet
-lUsageEnvironment -ldarknet -lsensors
CFG_OBJ=
COMMON_OBJ=$(OUTDIR)/base64.o $(OUTDIR)/basicCameraInfo.o \
$(OUTDIR)/basicDualThread.o $(OUTDIR)/basicEngine.o \
@ -562,7 +567,7 @@ ALL_OBJ=$(OUTDIR)/base64.o $(OUTDIR)/basicCameraInfo.o \
libavcodec libavdevice libavfilter libavformat libavutil libpostproc \
libswresample libswscale --libs` -latomic `pkg-config --libs openssl \
opencv4 rdkafka++` -lliveMedia -lgroupsock -lBasicUsageEnvironment \
-lUsageEnvironment -lsensors
-lUsageEnvironment -ldarknet -lsensors
COMPILE=g++ -c -x c++ "-DDEBUG" "-DMEKOROT_PROJECT_" "-D__STDC_CONSTANT_MACROS" "-D_CLIENT_APPLICATION_" "-D_OPENCV_" -O0 -Wall -pedantic -W -std=c++17 -Wno-write-strings -I../../lib/include `pkg-config opencv4 libavcodec libavdevice libavfilter libavformat libavutil libpostproc libswresample libswscale live555 --cflags` -o "$(OUTDIR)/$(*F).o" $(CFG_INC) $<
LINK=g++ -O0 -Wall -pedantic -o "$(OUTFILE)" $(ALL_OBJ)
@ -656,7 +661,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 -ldarknet
-lUsageEnvironment -ldarknet -lsensors
CFG_OBJ=
COMMON_OBJ=$(OUTDIR)/base64.o $(OUTDIR)/basicCameraInfo.o \
$(OUTDIR)/basicDualThread.o $(OUTDIR)/basicEngine.o \
@ -775,7 +780,7 @@ ALL_OBJ=$(OUTDIR)/base64.o $(OUTDIR)/basicCameraInfo.o \
libavcodec libavdevice libavfilter libavformat libavutil libpostproc \
libswresample libswscale --libs` -latomic `pkg-config --libs openssl \
opencv4 rdkafka++` -lliveMedia -lgroupsock -lBasicUsageEnvironment \
-lUsageEnvironment -ldarknet
-lUsageEnvironment -ldarknet -lsensors
COMPILE=g++ -c -x c++ "-D__STDC_CONSTANT_MACROS" "-D_CLIENT_APPLICATION_" "-D_OPENCV_" -O3 -w -Wpointer-arith -std=c++17 -Wno-write-strings -I../../lib/include `pkg-config opencv4 libavcodec libavdevice libavfilter libavformat libavutil libpostproc libswresample libswscale live555 --cflags` -o "$(OUTDIR)/$(*F).o" $(CFG_INC) $<
LINK=g++ -O3 -w -o "$(OUTFILE)" $(ALL_OBJ)

6
lib/App/common/dataBinder_structures.h

@ -706,6 +706,12 @@ typedef struct S_DBC_MODEM_DATA
typedef struct S_YOLO_FILTER_DATA{
char config_path[MAX_PATH];
char weights_path[MAX_PATH];
char classes_path[MAX_PATH];
float threshold;
float overlap_boxes;
bool debug_mode;
bool use_face_id;
int8_t gpu_index;
uint8_t batch;
uint8_t clear;
} YOLO_FILTER_DATA;

1
lib/App/common/deviceNodeCamera.cpp

@ -52,6 +52,7 @@ deviceNodeCamera::deviceNodeCamera(uint32_t NodeID) :
m_tPtzLastProbe = 0;
m_bNoAbsPositionning = false;
m_bCameraOnHomePosition = false;
m_bCameraAIControled = false;
m_tTimeTSeconds = 0;
m_pProtocol = NULL;
// m_pTransport = NULL;

1
lib/App/common/deviceNodeCamera.h

@ -252,6 +252,7 @@ class deviceNodeCamera : public deviceNode, public basicThread
DBC_CAM_DATA m_sCamData;
MEDIA_SOURCE_DESC m_sMediaSource;
basicEventHeap * m_pBEH;
bool m_bCameraAIControled;
// bool m_bSourceConnected;
// uint32_t m_nActiveStreamID;
// bool inTheFOV( float lat, float lon, float alt );

47
lib/App/common/deviceNodePTZCamControl.cpp

@ -52,13 +52,26 @@ bool deviceNodePTZCamControl::dispatchEvent(EVENT_CONTAINER * E)
switch (E->m_eType){
case EVT_ROI_ACTIVE:{
TARGET_DATA * tDATA = (TARGET_DATA *) E->m_pEvtData;
if( tDATA ) lookAt(E->m_db_id, tDATA->system_target);
if ( !m_bCameraAIControled ) {
TARGET_DATA *tDATA = (TARGET_DATA *)E->m_pEvtData;
if( tDATA ) lookAt(E->m_db_id, tDATA->system_target);
}
break;
};
case EVT_CAMERA_AI_MODE_ON:{
if( E->m_nDestinationNodeID == m_sNodeData.node_id ) m_bCameraAIControled = true;
break;
};
case EVT_CAMERA_AI_MODE_OFF:{
if( E->m_nDestinationNodeID == m_sNodeData.node_id ) m_bCameraAIControled = false;
break;
};
case EVT_CAMERA_MOVE_TO:{
TARGET_DATA * tDATA = (TARGET_DATA *) E->m_pEvtData;
if (tDATA) lookAt( E->m_db_id, tDATA->system_target );
//Event used by AI Analytics to move camera
TARGET_DATA *tDATA = (TARGET_DATA *)E->m_pEvtData;
if (tDATA) {
lookAt( E->m_db_id, tDATA->system_target );
};
break;
};
case EVT_TARGET_1D:
@ -66,18 +79,20 @@ bool deviceNodePTZCamControl::dispatchEvent(EVENT_CONTAINER * E)
case EVT_TARGET_2D_WHITE:
case EVT_TARGET_3D_BLACK:
case EVT_TARGET_3D_WHITE:{
TARGET_DATA * tDATA = (TARGET_DATA *) E->m_pEvtData;
if (tDATA){
#ifdef DEBUG_EXTRA
LOG("CHECK CAMERA FOV");
#endif
if (testFOV(tDATA->system_target)){
#ifdef DEBUG_EXTRA
LOG("TARGET IN CAMERA FOV");
#endif
lookAt(E->m_db_id, tDATA->system_target);
};
};
if ( !m_bCameraAIControled ) {
TARGET_DATA *tDATA = (TARGET_DATA *)E->m_pEvtData;
if (tDATA){
#ifdef DEBUG_EXTRA
LOG("CHECK CAMERA FOV");
#endif
if (testFOV(tDATA->system_target)){
#ifdef DEBUG_EXTRA
LOG("TARGET IN CAMERA FOV");
#endif
lookAt(E->m_db_id, tDATA->system_target);
};
};
}
break;
};
default: break;

113
lib/App/common/kernelEventFilterYOLO.cpp

@ -43,6 +43,9 @@ bool kernelEventFilterYOLO::validate()
m_mDataProtector.lock();
memcpy(&m_sYOLOFilterData, tData, sizeof(YOLO_FILTER_DATA));
m_mDataProtector.unlock();
//ToDO: Make Re Init filter (stop the thread and start it again)
};
free(tData);
return true;
@ -63,6 +66,11 @@ bool kernelEventFilterYOLO::initFilter(){
LOG_ERROR("No YOLO filter settings (getYOLOFilterData returned nothing)");
return false;
};
if ( m_sYOLOFilterData.gpu_index > -1 ) {
Darknet::set_gpu_index( m_sYOLOFilterData.gpu_index );
} else {
LOG("Run On CPU Backend");
};
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 );
@ -74,28 +82,45 @@ bool kernelEventFilterYOLO::initFilter(){
LOG_ERROR( tB );
return false;
};
if ( m_pNET ) {
free_network_ptr( m_pNET ); // initFilter() called again
m_pNET = NULL;
if ( !fileExist( m_sYOLOFilterData.classes_path ) ) {
snprintf( tB, sizeof(tB), "YOLO classes not found: %.120s", m_sYOLOFilterData.classes_path );
LOG_ERROR( tB );
return false;
};
if ( m_sYOLOFilterData.batch ) {
m_pNET = load_network_custom( m_sYOLOFilterData.config_path, m_sYOLOFilterData.weights_path, m_sYOLOFilterData.clear, m_sYOLOFilterData.batch );
} else {
m_pNET = load_network( m_sYOLOFilterData.config_path, m_sYOLOFilterData.weights_path, m_sYOLOFilterData.clear );
try {
if (m_pNET) {
//free_network_ptr( m_pNET ); // initFilter() called again
Darknet::free_neural_network( m_pNET );
m_pNET = NULL;
};
m_pNET = Darknet::load_neural_network( m_sYOLOFilterData.config_path, m_sYOLOFilterData.classes_path, m_sYOLOFilterData.weights_path );
//if ( m_sYOLOFilterData.batch ) {
// m_pNET = load_network_custom( m_sYOLOFilterData.config_path, m_sYOLOFilterData.weights_path, m_sYOLOFilterData.clear, m_sYOLOFilterData.batch );
//} else {
// m_pNET = load_network( m_sYOLOFilterData.config_path, m_sYOLOFilterData.weights_path, m_sYOLOFilterData.clear );
//};
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 );
Darknet::set_detection_threshold( m_pNET, m_sYOLOFilterData.threshold ); // minimum confidence (default 0.25)
Darknet::set_non_maximal_suppression_threshold( m_pNET, m_sYOLOFilterData.overlap_boxes ); // overlap for merging boxes (default 0.45)
return init();
};
} catch ( const std::exception & e ) {
LOG_ERROR( e.what() );
if( m_pNET ) Darknet::free_neural_network( m_pNET );
};
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;
}
bool kernelEventFilterYOLO::stopFilter(){
return false;
return uninit();
}
bool kernelEventFilterYOLO::dispatchEvent(EVENT_CONTAINER * Evt){
(void) Evt; // ToDo: YOLO event handling
return false;
@ -112,3 +137,63 @@ void kernelEventFilterYOLO::m_fThreadProc(void)
SLEEP(DEFAULT_THREAD_SLEEP_TIME);
};
}
bool kernelEventFilterYOLO::detectYOLO( cv::Mat &Picture ){
//DarknetNetworkPtr tNET = ( DarknetNetworkPtr ) m_pNET;
if( m_pNET == NULL ) return false;
//int nW, nH, nC;
//darknet_network_dimensions( m_pNET, &nW, &nH, &nC );
//Darknet::Image im = mat_to_image( Picture );
// Resize image to network dimensions
//Darknet::Image sized = letterbox_image( im, m_nW, m_nH );
// 4. Run the prediction
// The results are stored internally in the network structure
//network_predict_ptr( m_pNET, sized.data );
// 5. Get and process results (example for a single image)
//int nms_t = 0.45; // NMS threshold
//float thresh = 0.5; // Confidence threshold
//detection *dets = get_network_boxes( tNET, Picture.cols, Picture.rows, thresh, thresh, 0, 1, &nms_t, 0);
// You would then iterate through 'dets' to draw boxes using OpenCV calls
// The bounding boxes (x, y, w, h) in `dets` are relative to the original image dimensions
//LOG("Detections found. Processing results...");
// Example loop to print detections
//for (int i = 0; i < tNET->layers[ tNET->n-1 ].outputs; ++i) {
// if( dets[i].prob[0] > thresh ){ // Check if confidence > threshold
// // Process the detection
// };
//};
// 6. Free allocated memory
//free_detections( dets, m_pNET->layers[ m_pNET->n-1 ].outputs );
//free_image( im );
//free_image( sized );
/*const*/ Darknet::Predictions predictions;
if ( m_sYOLOFilterData.debug_mode ) {
const auto t0 = std::chrono::steady_clock::now();
predictions = Darknet::predict( m_pNET, Picture );
const auto ms = std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::steady_clock::now() - t0).count();
const Darknet::VStr &names = Darknet::get_class_names(m_pNET);
for ( const auto & p : predictions ){
if( p.best_class < 0 ){
continue; // nothing above the threshold
};
const float confidence = p.prob.count(p.best_class) ? p.prob.at(p.best_class) : 0.0f;
//std::cout << " " << names.at( p.best_class )
// << " " << static_cast<int>(confidence * 100.0f + 0.5f) << "%"
// << " x=" << p.rect.x << " y=" << p.rect.y
// << " w=" << p.rect.width << " h=" << p.rect.height << std::endl;
};
} else {
predictions = Darknet::predict( m_pNET, Picture );
}
}

24
lib/App/common/kernelEventFilterYOLO.h

@ -6,6 +6,8 @@
#include "kernelEventFilter.h"
#include "kernelPrototype.h"
#include "../../components/base/basicLIBAV.h"
//#include "../../data/darknet/darknetWraper.h"
//#include <darknet/darknet.hpp>
@ -13,14 +15,23 @@
// 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>
#if __has_include(<darknet.hpp>)
//#include <darknet.h>
#include <darknet.hpp>
#elif __has_include(<darknet/darknet.hpp>)
//#include <darknet/darknet.h>
#include <darknet/darknet.hpp>
#else
#error "darknet.h not found: install Darknet (libdarknet.so + darknet.h, e.g. the darknet .deb)"
#error "darknet.hpp not found: install Darknet (libdarknet.so + darknet.hpp, e.g. the darknet .deb)"
#endif
#include <chrono>
#include <cstdlib>
#include <filesystem>
#include <iostream>
#include <string>
class kernelEventFilterYOLO : public kernelEventFilter, public basicEventHandler, public basicThread {
private:
basicLogCollection * m_pLog;
@ -28,10 +39,11 @@ class kernelEventFilterYOLO : public kernelEventFilter, public basicEventHandler
basicMutex m_mStateProtector;
basicMutex m_mDataProtector;
//darknetWraper * m_pDarkNet;
DarknetNetworkPtr m_pNET; // DarknetNetworkPtr is already a pointer (void *)
Darknet::NetworkPtr m_pNET; // DarknetNetworkPtr is already a pointer (void *)
int m_nW;
int m_nH;
int m_nC;
bool detectYOLO( cv::Mat &Picture );
protected:
virtual void m_fThreadProc(void);

5
lib/App/common/kernelModuleEmbedVideo.cpp

@ -2418,6 +2418,11 @@ bool kernelModuleEmbedVideo::unregisterStream(uint32_t streamID)
return false;
}
cv::Mat *kernelModuleEmbedVideo::getCurrentFrame( uint32_t streamID ){
cv::Mat *retVal = NULL;
return retVal;
}
#undef TLOG
#undef TLOG_ERROR

5
lib/App/common/kernelModuleEmbedVideo.h

@ -139,10 +139,11 @@ class kernelModuleEmbedVideo : public kernelModule
*/
int getWidh(void);
int getHeight(void);
bool registerStream(uint32_t streamID, uint8_t flip_mode = 0);
bool unregisterStream(uint32_t streamID);
bool registerStream( uint32_t streamID, uint8_t flip_mode = 0 );
bool unregisterStream( uint32_t streamID );
uint8_t getMediaMode(void);
bool isProcessingVideoStream();
cv::Mat * getCurrentFrame( uint32_t streamID );
friend class streamHandler;
};
#else //LRF_PROXY_ONLY

6
lib/components/base/basicEvent.h

@ -132,8 +132,10 @@ typedef enum E_basicEventTypeID :
EVT_SRV_MODBUS_CLEAR_P = 97, // Triggering SCADA Input Clear ALL Platform Signals and Modbus Blockers
EVT_SRV_MODBUS_S_POSTBOX = 98, // Snooze one Modbus Blocker
EVT_SRV_MODBUS_D_POSTBOX = 99, // Dissmis one Modbus Blocker
EVT_SRV_MODBUS_CLEAR_S = 100, // Dissmiss all Platform alarm signals only
EVT_COUNT = 101
EVT_SRV_MODBUS_CLEAR_S = 100,// Dissmiss all Platform alarm signals only
EVT_CAMERA_AI_MODE_ON = 101,// Set Camera Movement by AI Only -> Only Targeted Event
EVT_CAMERA_AI_MODE_OFF = 102,// Enables all Camera Movements (Auto && Manual) -> Only Targeted Event
EVT_COUNT = 103
} basicEventTypeID;
typedef enum E_basicEventClassID :

Loading…
Cancel
Save