Add unitest
This commit is contained in:
@@ -12,7 +12,23 @@
|
||||
"Bash(cp \"C:/Projects/ANLS/ANSLIB/ANSCustomFireNSmokeDetection/pch.cpp\" \"C:/Projects/CLionProjects/ANSCustomModels/ANSCustomFireNSmokeDetection/pch.cpp\")",
|
||||
"Read(//c/ANSLibs/opencv/x64/vc17/**)",
|
||||
"Read(//c/ANSLibs/opencv/**)",
|
||||
"Bash(find C:/ANSLibs -name *.dll -type f)"
|
||||
"Bash(find C:/ANSLibs -name *.dll -type f)",
|
||||
"Bash(xargs grep:*)",
|
||||
"Bash(dumpbin /c/Projects/CLionProjects/ANSCORE/cmake-build-release/bin/ANSLIB.dll /imports)",
|
||||
"Bash(objdump -p /c/Projects/CLionProjects/ANSCORE/cmake-build-release/bin/ANSLIB.dll)",
|
||||
"Bash(nm -D /c/Projects/CLionProjects/ANSCORE/cmake-build-release/bin/ANSMOT.dll)",
|
||||
"Bash(find /c/Projects/ANLS/ANSLIB -type f -name *ANSMOT*)",
|
||||
"Bash(grep -r \"add_custom_command\\\\|install\\(\" /c/Projects/CLionProjects/ANSCORE --include=CMakeLists.txt --include=*.cmake)",
|
||||
"Bash(find C:/Projects/CLionProjects/ANSCORE/cmake-build-release/bin -name *.dll -type f)",
|
||||
"Read(//c/Projects/CLionProjects/ANSCustomModels/**)",
|
||||
"Bash(dumpbin /EXPORTS C:/ProgramData/ANSCENTER/Shared/ANSODEngine.dll)",
|
||||
"Bash(dumpbin /DEPENDENTS C:/ProgramData/ANSCENTER/Shared/ANSODEngine.dll)",
|
||||
"Bash(cmd.exe /c \"dumpbin /DEPENDENTS C:\\\\ProgramData\\\\ANSCENTER\\\\Shared\\\\ANSODEngine.dll\")",
|
||||
"Bash(\"C:/Program Files/Microsoft Visual Studio/2022/Community/VC/Tools/MSVC/14.44.35207/bin/Hostx64/x64/dumpbin.exe\" /DEPENDENTS \"C:/ProgramData/ANSCENTER/Shared/ANSODEngine.dll\")",
|
||||
"Bash(\"C:/Program Files/Microsoft Visual Studio/2022/Community/VC/Tools/MSVC/14.44.35207/bin/Hostx64/x64/dumpbin.exe\" //DEPENDENTS ANSODEngine.dll)",
|
||||
"Bash(\"C:/Program Files/Microsoft Visual Studio/2022/Community/VC/Tools/MSVC/14.44.35207/bin/Hostx64/x64/dumpbin.exe\" //EXPORTS ANSLicensingSystem.dll)",
|
||||
"Bash(\"C:/Program Files/Microsoft Visual Studio/2022/Community/VC/Tools/MSVC/14.44.35207/bin/Hostx64/x64/dumpbin.exe\" //IMPORTS ANSODEngine.dll)",
|
||||
"Bash(\"C:/Program Files/Microsoft Visual Studio/2022/Community/VC/Tools/MSVC/14.44.35207/bin/Hostx64/x64/dumpbin.exe\" //IMPORTS ANSMOT.dll)"
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
@@ -461,9 +461,9 @@ bool ANSCustomFS::Initialize(const std::string& modelDirectory, float detectionS
|
||||
_motiondetector = ANSLIBPtr(ANSCENTER::ANSLIB::Create(), &ANSCENTER::ANSLIB::Destroy);
|
||||
|
||||
|
||||
_detectorModelType = 4; // TENSORRT
|
||||
_detectorModelType = 31; // TENSORRT
|
||||
_detectorDetectionType = 1; // DETECTION
|
||||
_filterModelType = 4; // TENSORRT
|
||||
_filterModelType = 31; // TENSORRT
|
||||
_filterDetectionType = 1; // DETECTION
|
||||
_motionModelType = 19; // Motion detection (generic CPU)
|
||||
_motionDetectionType = 1; // DETECTION
|
||||
@@ -472,17 +472,17 @@ bool ANSCustomFS::Initialize(const std::string& modelDirectory, float detectionS
|
||||
engineType = _detector->GetEngineType();
|
||||
if (engineType == 1) {
|
||||
// NVIDIA GPU: Use TensorRT
|
||||
_detectorModelType = 4; // TENSORRT
|
||||
_detectorModelType = 31; // TENSORRT
|
||||
_detectorDetectionType = 1; // DETECTION
|
||||
_filterModelType = 4; // TENSORRT
|
||||
_filterModelType = 31; // TENSORRT
|
||||
_filterDetectionType = 1; // DETECTION
|
||||
std::cout << "NVIDIA GPU detected. Using TensorRT" << std::endl;
|
||||
}
|
||||
else {
|
||||
// CPU/Other: Use OpenVINO
|
||||
_detectorModelType = 17; // OPENVINO
|
||||
_detectorModelType = 30; // OPENVINO
|
||||
_detectorDetectionType = 1; // DETECTION
|
||||
_filterModelType = 17; //Yolo v12
|
||||
_filterModelType = 30; //Yolo v12
|
||||
_filterDetectionType = 1; // DETECTION
|
||||
std::cout << "CPU detected. Using OpenVINO and ONNX" << std::endl;
|
||||
|
||||
@@ -556,7 +556,7 @@ bool ANSCustomFS::Initialize(const std::string& modelDirectory, float detectionS
|
||||
return false;
|
||||
}
|
||||
|
||||
// Load motion detector model (background subtraction / frame differencing)
|
||||
// Load motion detector model (optional — not used in Stage A tracker-based pipeline)
|
||||
float motionScoreThreshold = MOTION_SENSITIVITY;
|
||||
float motionConfThreshold = 0.5f;
|
||||
float motionNMSThreshold = 0.5f;
|
||||
@@ -570,8 +570,8 @@ bool ANSCustomFS::Initialize(const std::string& modelDirectory, float detectionS
|
||||
"", // Empty model directory - motion detector is algorithmic
|
||||
motionDetectorLabels);
|
||||
if (motionResult != 1) {
|
||||
std::cerr << "ANSCustomFS::Initialize: Failed to load motion detector model." << std::endl;
|
||||
return false;
|
||||
std::cerr << "ANSCustomFS::Initialize: Warning - Motion detector not loaded (not required for Stage A)." << std::endl;
|
||||
// Non-fatal: motion detector is not used in the tracker-based Stage A pipeline
|
||||
}
|
||||
|
||||
return true;
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
|
||||
#define RETAINFRAMES 80
|
||||
#define FILTERFRAMES 10
|
||||
//#define FNS_DEBUG
|
||||
#define FNS_DEBUG
|
||||
class CUSTOM_API ANSCustomFS : public IANSCustomClass
|
||||
{
|
||||
typedef std::pair<cv::Scalar, cv::Scalar> Range;
|
||||
@@ -33,7 +33,7 @@ class CUSTOM_API ANSCustomFS : public IANSCustomClass
|
||||
private:
|
||||
using ANSLIBPtr = std::unique_ptr<ANSCENTER::ANSLIB, decltype(&ANSCENTER::ANSLIB::Destroy)>;
|
||||
|
||||
int engineType{ 0 };
|
||||
int engineType{ 0 };
|
||||
ANSLIBPtr _motiondetector{ nullptr, &ANSCENTER::ANSLIB::Destroy };
|
||||
ANSLIBPtr _detector{ nullptr, &ANSCENTER::ANSLIB::Destroy };
|
||||
ANSLIBPtr _filter{ nullptr, &ANSCENTER::ANSLIB::Destroy };
|
||||
|
||||
@@ -30,7 +30,7 @@ target_compile_definitions(${PROJECT_NAME} PRIVATE
|
||||
# ---------- include directories ----------
|
||||
target_include_directories(${PROJECT_NAME} PRIVATE
|
||||
${CMAKE_CURRENT_SOURCE_DIR}
|
||||
C:/Projects/ANLS/ANSLIB/ANSLIB
|
||||
C:/ProgramData/ANSCENTER/Shared # ANSLIB.h + ANSLIB.lib from same location
|
||||
C:/ANSLibs/opencv/include
|
||||
)
|
||||
|
||||
@@ -51,10 +51,12 @@ if(MSVC)
|
||||
/W3 # Warning level 3
|
||||
/sdl # SDL checks
|
||||
/permissive- # Conformance mode
|
||||
$<$<CONFIG:Release>:/O2 /Oi /GL> # Optimize + intrinsics + whole-program opt
|
||||
/Zi # Generate full debug info (PDB) in all configs
|
||||
$<$<CONFIG:Release>:/O2 /Oi> # Optimize + intrinsics (no /GL — incompatible with debugging)
|
||||
)
|
||||
|
||||
target_link_options(${PROJECT_NAME} PRIVATE
|
||||
$<$<CONFIG:Release>:/OPT:REF /OPT:ICF /LTCG> # Optimize refs, COMDAT folding, link-time codegen
|
||||
/DEBUG # Emit PDB for debugger in all configs
|
||||
$<$<CONFIG:Release>:/OPT:REF /OPT:ICF> # Optimize refs, COMDAT folding (no /LTCG — incompatible with debugging)
|
||||
)
|
||||
endif()
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
#include "ANSLIB.h"
|
||||
|
||||
//#define FNS_DEBUG
|
||||
#define FNS_DEBUG
|
||||
class CUSTOM_API ANSCustomHMD : public IANSCustomClass
|
||||
{
|
||||
private:
|
||||
|
||||
@@ -30,7 +30,7 @@ target_compile_definitions(${PROJECT_NAME} PRIVATE
|
||||
# ---------- include directories ----------
|
||||
target_include_directories(${PROJECT_NAME} PRIVATE
|
||||
${CMAKE_CURRENT_SOURCE_DIR}
|
||||
C:/Projects/ANLS/ANSLIB/ANSLIB
|
||||
C:/ProgramData/ANSCENTER/Shared # ANSLIB.h + ANSLIB.lib from same location
|
||||
C:/ANSLibs/opencv/include
|
||||
)
|
||||
|
||||
@@ -51,10 +51,12 @@ if(MSVC)
|
||||
/W3 # Warning level 3
|
||||
/sdl # SDL checks
|
||||
/permissive- # Conformance mode
|
||||
$<$<CONFIG:Release>:/O2 /Oi /GL> # Optimize + intrinsics + whole-program opt
|
||||
/Zi # Generate full debug info (PDB) in all configs
|
||||
$<$<CONFIG:Release>:/O2 /Oi> # Optimize + intrinsics (no /GL — incompatible with debugging)
|
||||
)
|
||||
|
||||
target_link_options(${PROJECT_NAME} PRIVATE
|
||||
$<$<CONFIG:Release>:/OPT:REF /OPT:ICF /LTCG> # Optimize refs, COMDAT folding, link-time codegen
|
||||
/DEBUG # Emit PDB for debugger in all configs
|
||||
$<$<CONFIG:Release>:/OPT:REF /OPT:ICF> # Optimize refs, COMDAT folding (no /LTCG — incompatible with debugging)
|
||||
)
|
||||
endif()
|
||||
|
||||
@@ -30,7 +30,7 @@ target_compile_definitions(${PROJECT_NAME} PRIVATE
|
||||
# ---------- include directories ----------
|
||||
target_include_directories(${PROJECT_NAME} PRIVATE
|
||||
${CMAKE_CURRENT_SOURCE_DIR}
|
||||
C:/Projects/ANLS/ANSLIB/ANSLIB
|
||||
C:/ProgramData/ANSCENTER/Shared # ANSLIB.h + ANSLIB.lib from same location
|
||||
C:/ANSLibs/opencv/include
|
||||
)
|
||||
|
||||
@@ -51,10 +51,12 @@ if(MSVC)
|
||||
/W3 # Warning level 3
|
||||
/sdl # SDL checks
|
||||
/permissive- # Conformance mode
|
||||
$<$<CONFIG:Release>:/O2 /Oi /GL> # Optimize + intrinsics + whole-program opt
|
||||
/Zi # Generate full debug info (PDB) in all configs
|
||||
$<$<CONFIG:Release>:/O2 /Oi> # Optimize + intrinsics (no /GL — incompatible with debugging)
|
||||
)
|
||||
|
||||
target_link_options(${PROJECT_NAME} PRIVATE
|
||||
$<$<CONFIG:Release>:/OPT:REF /OPT:ICF /LTCG> # Optimize refs, COMDAT folding, link-time codegen
|
||||
/DEBUG # Emit PDB for debugger in all configs
|
||||
$<$<CONFIG:Release>:/OPT:REF /OPT:ICF> # Optimize refs, COMDAT folding (no /LTCG — incompatible with debugging)
|
||||
)
|
||||
endif()
|
||||
|
||||
@@ -4,6 +4,11 @@ project(ANSCustomModels LANGUAGES CXX)
|
||||
set(CMAKE_CXX_STANDARD 17)
|
||||
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
||||
|
||||
# Place all build outputs (.exe and .dll) in the same directory so our own
|
||||
# custom model DLLs are found next to the test/demo executables at runtime.
|
||||
# External DLLs (ANSLIB, OpenCV, etc.) are loaded from C:\ProgramData\ANSCENTER\Shared.
|
||||
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin")
|
||||
|
||||
add_subdirectory(ANSCustomHelmetDetection)
|
||||
add_subdirectory(ANSCustomFireNSmokeDetection)
|
||||
add_subdirectory(ANSCustomWeaponDetection)
|
||||
|
||||
@@ -13,18 +13,13 @@ FetchContent_MakeAvailable(googletest)
|
||||
enable_testing()
|
||||
|
||||
# ---------- Common paths (propagated to sub-projects via variables) ----------
|
||||
set(ANSLIB_INCLUDE_DIR "C:/Projects/ANLS/ANSLIB/ANSLIB" CACHE PATH "")
|
||||
set(ANSLIB_INCLUDE_DIR "C:/ProgramData/ANSCENTER/Shared" CACHE PATH "")
|
||||
set(OPENCV_INCLUDE_DIR "C:/ANSLibs/opencv/include" CACHE PATH "")
|
||||
set(ANSLIB_LIB_DIR "C:/ProgramData/ANSCENTER/Shared" CACHE PATH "")
|
||||
set(OPENCV_LIB_DIR "C:/ANSLibs/opencv/x64/vc17/lib" CACHE PATH "")
|
||||
set(OPENCV_BIN_DIR "C:/ProgramData/ANSCENTER/Shared" CACHE PATH "")
|
||||
set(TEST_COMMON_DIR "${CMAKE_CURRENT_SOURCE_DIR}" CACHE PATH "")
|
||||
|
||||
# ---------- Place all test .exe files alongside the DLLs they need ----------
|
||||
# This ensures custom model DLLs (built by sibling projects) land in the same
|
||||
# directory as the test executables so Windows can find them at runtime.
|
||||
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin" CACHE PATH "" FORCE)
|
||||
|
||||
# ---------- Sub-project test executables ----------
|
||||
add_subdirectory(FireNSmokeDetection)
|
||||
add_subdirectory(HelmetDetection)
|
||||
|
||||
@@ -1,25 +1,37 @@
|
||||
project(FireNSmokeDetection_Tests LANGUAGES CXX)
|
||||
|
||||
add_executable(${PROJECT_NAME}
|
||||
FireNSmokeDetectionTest.cpp
|
||||
# ============================================================================
|
||||
# Common settings shared by both targets
|
||||
# ============================================================================
|
||||
set(COMMON_INCLUDES
|
||||
${TEST_COMMON_DIR}
|
||||
${ANSLIB_INCLUDE_DIR}
|
||||
${OPENCV_INCLUDE_DIR}
|
||||
${CMAKE_SOURCE_DIR}/ANSCustomFireNSmokeDetection
|
||||
)
|
||||
|
||||
target_compile_features(${PROJECT_NAME} PRIVATE cxx_std_17)
|
||||
|
||||
target_compile_definitions(${PROJECT_NAME} PRIVATE
|
||||
set(COMMON_DEFS
|
||||
WIN32_LEAN_AND_MEAN
|
||||
NOMINMAX
|
||||
$<$<CONFIG:Debug>:_DEBUG>
|
||||
$<$<CONFIG:Release>:NDEBUG>
|
||||
)
|
||||
|
||||
target_include_directories(${PROJECT_NAME} PRIVATE
|
||||
${TEST_COMMON_DIR}
|
||||
${ANSLIB_INCLUDE_DIR}
|
||||
${OPENCV_INCLUDE_DIR}
|
||||
${CMAKE_SOURCE_DIR}/ANSCustomFireNSmokeDetection
|
||||
# All runtime DLLs (ANSLIB, ANSODEngine, ANSLicensingSystem, ANSMOT, OpenCV, etc.)
|
||||
# live in C:\ProgramData\ANSCENTER\Shared — same directory as the .lib files.
|
||||
# Windows resolves them via the standard DLL search order.
|
||||
|
||||
# ============================================================================
|
||||
# 1. Google Test unit/integration test executable
|
||||
# ============================================================================
|
||||
add_executable(${PROJECT_NAME}
|
||||
FireNSmokeDetectionTest.cpp
|
||||
)
|
||||
|
||||
target_compile_features(${PROJECT_NAME} PRIVATE cxx_std_17)
|
||||
target_compile_definitions(${PROJECT_NAME} PRIVATE ${COMMON_DEFS})
|
||||
target_include_directories(${PROJECT_NAME} PRIVATE ${COMMON_INCLUDES})
|
||||
|
||||
target_link_directories(${PROJECT_NAME} PRIVATE
|
||||
${ANSLIB_LIB_DIR}
|
||||
${OPENCV_LIB_DIR}
|
||||
@@ -37,18 +49,31 @@ if(MSVC)
|
||||
target_compile_options(${PROJECT_NAME} PRIVATE /W3 /sdl /permissive-)
|
||||
endif()
|
||||
|
||||
# Copy required DLLs next to the test executable so Windows can find them
|
||||
add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD
|
||||
# ANSLIB.dll
|
||||
COMMAND ${CMAKE_COMMAND} -E copy_if_different
|
||||
"${ANSLIB_LIB_DIR}/ANSLIB.dll"
|
||||
"$<TARGET_FILE_DIR:${PROJECT_NAME}>"
|
||||
# OpenCV DLL
|
||||
COMMAND ${CMAKE_COMMAND} -E copy_if_different
|
||||
"${OPENCV_BIN_DIR}/opencv_world4130.dll"
|
||||
"$<TARGET_FILE_DIR:${PROJECT_NAME}>"
|
||||
COMMENT "Copying runtime DLLs for ${PROJECT_NAME}"
|
||||
)
|
||||
|
||||
include(GoogleTest)
|
||||
gtest_discover_tests(${PROJECT_NAME} DISCOVERY_MODE PRE_TEST)
|
||||
|
||||
# ============================================================================
|
||||
# 2. Interactive video demo executable (visual verification with OpenCV window)
|
||||
# ============================================================================
|
||||
add_executable(FireNSmokeDetection_Demo
|
||||
main.cpp
|
||||
)
|
||||
|
||||
target_compile_features(FireNSmokeDetection_Demo PRIVATE cxx_std_17)
|
||||
target_compile_definitions(FireNSmokeDetection_Demo PRIVATE ${COMMON_DEFS})
|
||||
target_include_directories(FireNSmokeDetection_Demo PRIVATE ${COMMON_INCLUDES})
|
||||
|
||||
target_link_directories(FireNSmokeDetection_Demo PRIVATE
|
||||
${ANSLIB_LIB_DIR}
|
||||
${OPENCV_LIB_DIR}
|
||||
)
|
||||
|
||||
target_link_libraries(FireNSmokeDetection_Demo PRIVATE
|
||||
ANSLIB
|
||||
opencv_world4130
|
||||
ANSCustomFireNSmokeDetection
|
||||
)
|
||||
|
||||
if(MSVC)
|
||||
target_compile_options(FireNSmokeDetection_Demo PRIVATE /W3 /sdl /permissive-)
|
||||
endif()
|
||||
|
||||
127
tests/FireNSmokeDetection/main.cpp
Normal file
127
tests/FireNSmokeDetection/main.cpp
Normal file
@@ -0,0 +1,127 @@
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
#include <vector>
|
||||
#include <string>
|
||||
#include <chrono>
|
||||
#include <opencv2/opencv.hpp>
|
||||
#include "ANSCustomFireNSmoke.h"
|
||||
|
||||
int FireNSmokeDetection() {
|
||||
std::string modelDirectory = "C:\\Projects\\ANSVIS\\Models\\ANS_FireSmoke_v3.0";
|
||||
std::string videoFilePath = "E:\\Programs\\DemoAssets\\Videos\\FireNSmoke\\ANSFireFull.mp4";// passed
|
||||
//std::string videoFilePath = "E:\\Programs\\DemoAssets\\Videos\\ANSVIS_Issues\\FGFire.mp4";// passed
|
||||
//std::string videoFilePath = "E:\\Programs\\DemoAssets\\Videos\\FireNSmoke\\HFire1.mp4"; // passed
|
||||
//std::string videoFilePath = "E:\\Programs\\DemoAssets\\Videos\\FireNSmoke\\HFire3.mp4"; // passed
|
||||
//std::string videoFilePath = "C:\\Programs\\FireTest\\road.mp4"; // passed
|
||||
//std::string videoFilePath = "C:\\Programs\\FireTest\\video_20.mp4"; // passed
|
||||
//std::string videoFilePath = "C:\\Programs\\FireTest\\BCA1.mp4"; // passed
|
||||
//std::string videoFilePath = "C:\\Programs\\DemoAssets\\Videos\\FireNSmoke\\E112 v4-1.mp4"; // passed
|
||||
//std::string videoFilePath = "C:\\Programs\\DemoAssets\\Videos\\FireNSmoke\\E112Full.mp4"; // passed
|
||||
//std::string videoFilePath = "C:\\Programs\\DemoAssets\\Videos\\FireNSmoke\\SimFire.mp4"; // passed
|
||||
//std::string videoFilePath = "C:\\Programs\\DemoAssets\\Videos\\FireNSmoke\\BCA3.mp4"; // pass (smoke issue)
|
||||
//std::string videoFilePath = "C:\\Programs\\DemoAssets\\Videos\\FireNSmoke\\E112 fire.mp4"; // pass
|
||||
//std::string videoFilePath = "C:\\Programs\\DemoAssets\\Videos\\FireNSmoke\\e112 v3-2.mp4"; // pass
|
||||
//std::string videoFilePath = "C:\\Programs\\DemoAssets\\Videos\\FireNSmoke\\e112 v3-3.mp4"; // pass
|
||||
//std::string videoFilePath = "C:\\Programs\\DemoAssets\\Videos\\FireNSmoke\\e112 v3-4.mp4"; // pass
|
||||
//std::string videoFilePath = "C:\\Programs\\DemoAssets\\Videos\\FireNSmoke\\E112 v4-1.mp4"; // pass
|
||||
//std::string videoFilePath = "C:\\Programs\\DemoAssets\\Videos\\FireNSmoke\\Fire25m.mp4"; // passed (fire is too small and low resolution cam)
|
||||
//std::string videoFilePath = "C:\\Programs\\DemoAssets\\Videos\\FireNSmoke\\Failed\\fire 25cm 480p.mp4"; // passed (fire is too small and low resolution cam)
|
||||
|
||||
//std::string videoFilePath = "C:\\Programs\\FireTest\\BCA2.mp4"; // failed (fire is too small and low resolution cam)
|
||||
//std::string videoFilePath = "C:\\Programs\\DemoAssets\\Videos\\FireNSmoke\\fire4.mp4"; // failed (smoke issue, too low resolution)
|
||||
//std::string videoFilePath = "C:\\Programs\\FireTest\\HFire2.mp4"; // failed as camera is moving
|
||||
//std::string videoFilePath = "C:\\Programs\\DemoAssets\\Videos\\FireNSmoke\\E112 v4-2.mp4"; // failed white smoke low resolution cam
|
||||
|
||||
std::vector<std::string> classes;
|
||||
ANSCustomFS detector;
|
||||
std::string labelMap;
|
||||
|
||||
// Optimize model
|
||||
bool optimize = detector.OptimizeModel(true);
|
||||
|
||||
// Initialize the detector and parse the label map
|
||||
detector.Initialize(modelDirectory, 0.5, labelMap);
|
||||
std::stringstream ss(labelMap);
|
||||
while (ss.good()) {
|
||||
std::string substr;
|
||||
getline(ss, substr, ',');
|
||||
classes.push_back(substr);
|
||||
}
|
||||
|
||||
// Open video capture
|
||||
cv::VideoCapture capture(videoFilePath);
|
||||
if (!capture.isOpened()) {
|
||||
std::cerr << "Error: Unable to open video file!" << std::endl;
|
||||
return -1;
|
||||
}
|
||||
|
||||
// Get the original video dimensions
|
||||
int originalWidth = static_cast<int>(capture.get(cv::CAP_PROP_FRAME_WIDTH));
|
||||
int originalHeight = static_cast<int>(capture.get(cv::CAP_PROP_FRAME_HEIGHT));
|
||||
double aspectRatio = static_cast<double>(originalWidth) / originalHeight;
|
||||
|
||||
// Create a resizable window
|
||||
const std::string windowName = "ANS Fire Detection";
|
||||
cv::namedWindow(windowName, cv::WINDOW_NORMAL);
|
||||
|
||||
while (true) {
|
||||
cv::Mat frame;
|
||||
if (!capture.read(frame)) {
|
||||
break;
|
||||
}
|
||||
|
||||
// Run inference on the frame
|
||||
std::vector<CustomObject> customObjects;
|
||||
auto start = std::chrono::system_clock::now();
|
||||
customObjects = detector.RunInference(frame);
|
||||
auto end = std::chrono::system_clock::now();
|
||||
auto elapsed = std::chrono::duration_cast<std::chrono::milliseconds>(end - start);
|
||||
printf("Time = %lld ms\n", static_cast<long long int>(elapsed.count()));
|
||||
|
||||
// Draw detection results on the frame
|
||||
if (!customObjects.empty()) {
|
||||
for (const auto& obj : customObjects) {
|
||||
cv::rectangle(frame, cv::Rect(obj.box.x, obj.box.y, obj.box.width, obj.box.height), cv::Scalar(123, 255, 123), 2);
|
||||
cv::putText(frame,
|
||||
cv::format("%s:%d:%.2f", classes[obj.classId].c_str(), obj.classId, obj.confidence),
|
||||
cv::Point(obj.box.x, obj.box.y - 5),
|
||||
cv::FONT_HERSHEY_SIMPLEX,
|
||||
0.6,
|
||||
cv::Scalar(0, 0, 255),
|
||||
1,
|
||||
cv::LINE_AA);
|
||||
}
|
||||
}
|
||||
|
||||
// Handle resizing and maintain aspect ratio
|
||||
int currentWidth = static_cast<int>(cv::getWindowProperty(windowName, cv::WND_PROP_AUTOSIZE));
|
||||
int currentHeight = static_cast<int>(cv::getWindowProperty(windowName, cv::WND_PROP_AUTOSIZE));
|
||||
|
||||
if (currentWidth > 0 && currentHeight > 0) {
|
||||
int newWidth = currentWidth;
|
||||
int newHeight = static_cast<int>(newWidth / aspectRatio);
|
||||
if (newHeight > currentHeight) {
|
||||
newHeight = currentHeight;
|
||||
newWidth = static_cast<int>(newHeight * aspectRatio);
|
||||
}
|
||||
cv::resize(frame, frame, cv::Size(newWidth, newHeight));
|
||||
}
|
||||
|
||||
// Display the frame
|
||||
cv::imshow(windowName, frame);
|
||||
|
||||
// Exit the loop if 'esc' key is pressed
|
||||
if (cv::waitKey(30) == 27) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Clean up
|
||||
capture.release();
|
||||
cv::destroyAllWindows();
|
||||
return 0;
|
||||
}
|
||||
|
||||
int main() {
|
||||
return FireNSmokeDetection();
|
||||
}
|
||||
@@ -37,18 +37,5 @@ if(MSVC)
|
||||
target_compile_options(${PROJECT_NAME} PRIVATE /W3 /sdl /permissive-)
|
||||
endif()
|
||||
|
||||
# Copy required DLLs next to the test executable so Windows can find them
|
||||
add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD
|
||||
# ANSLIB.dll
|
||||
COMMAND ${CMAKE_COMMAND} -E copy_if_different
|
||||
"${ANSLIB_LIB_DIR}/ANSLIB.dll"
|
||||
"$<TARGET_FILE_DIR:${PROJECT_NAME}>"
|
||||
# OpenCV DLL
|
||||
COMMAND ${CMAKE_COMMAND} -E copy_if_different
|
||||
"${OPENCV_BIN_DIR}/opencv_world4130.dll"
|
||||
"$<TARGET_FILE_DIR:${PROJECT_NAME}>"
|
||||
COMMENT "Copying runtime DLLs for ${PROJECT_NAME}"
|
||||
)
|
||||
|
||||
include(GoogleTest)
|
||||
gtest_discover_tests(${PROJECT_NAME} DISCOVERY_MODE PRE_TEST)
|
||||
|
||||
@@ -37,18 +37,5 @@ if(MSVC)
|
||||
target_compile_options(${PROJECT_NAME} PRIVATE /W3 /sdl /permissive-)
|
||||
endif()
|
||||
|
||||
# Copy required DLLs next to the test executable so Windows can find them
|
||||
add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD
|
||||
# ANSLIB.dll
|
||||
COMMAND ${CMAKE_COMMAND} -E copy_if_different
|
||||
"${ANSLIB_LIB_DIR}/ANSLIB.dll"
|
||||
"$<TARGET_FILE_DIR:${PROJECT_NAME}>"
|
||||
# OpenCV DLL
|
||||
COMMAND ${CMAKE_COMMAND} -E copy_if_different
|
||||
"${OPENCV_BIN_DIR}/opencv_world4130.dll"
|
||||
"$<TARGET_FILE_DIR:${PROJECT_NAME}>"
|
||||
COMMENT "Copying runtime DLLs for ${PROJECT_NAME}"
|
||||
)
|
||||
|
||||
include(GoogleTest)
|
||||
gtest_discover_tests(${PROJECT_NAME} DISCOVERY_MODE PRE_TEST)
|
||||
|
||||
Reference in New Issue
Block a user