Compare commits
6
Commits
91bdb3f96b
...
8a95ed6b8c
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
8a95ed6b8c | ||
|
|
3a527d2dad | ||
|
|
7a11c9617b | ||
|
|
fd2394a85a | ||
|
|
e2bf17289d | ||
|
|
baa88bcc48 |
@@ -95,7 +95,18 @@
|
||||
"Bash(git add *)",
|
||||
"Read(//c/ProgramData/Jh7O7nUe7vS/Models/EngineModels/B-IN_ANS_VehicleDetection_v2.0_67345015/**)",
|
||||
"Bash(xxd)",
|
||||
"Bash(icacls \"C:\\\\ProgramData\\\\Jh7O7nUe7vS\\\\Models\\\\EngineModels\\\\B-IN_ANS_VehicleDetection_v2.0_67345015\\\\train_last.onnx\")"
|
||||
"Bash(icacls \"C:\\\\ProgramData\\\\Jh7O7nUe7vS\\\\Models\\\\EngineModels\\\\B-IN_ANS_VehicleDetection_v2.0_67345015\\\\train_last.onnx\")",
|
||||
"Bash(grep -oE '<Data[^>]*>[^<]{0,400}</Data>' \"C:/Users/nghia/Downloads/error.xml\")",
|
||||
"Bash(grep -oE '<Data[^>]*>[^<]{0,500}</Data>' \"/c/Users/nghia/Downloads/error.xml\")",
|
||||
"Read(//tmp/**)",
|
||||
"Bash(grep -oE '<Data[^>]*>[^<]{0,400}</Data>' \"/c/Users/nghia/Downloads/error.xml\")",
|
||||
"Bash(echo \"Exit: $?\")",
|
||||
"Bash(python -)",
|
||||
"Bash(git show *)",
|
||||
"Bash(dumpbin //dependents \"C:\\\\\\\\ProgramData\\\\\\\\ANSCENTER\\\\\\\\Shared\\\\\\\\ANSLicensingSystem.dll\")",
|
||||
"Bash(grep -v \"//\")",
|
||||
"Bash(grep -v \"^ *//\")",
|
||||
"Bash(python strip_folder_lock.py)"
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,19 +1,32 @@
|
||||
#include "Utility.h"
|
||||
#include <ctime>
|
||||
#include <chrono>
|
||||
#include <mutex>
|
||||
#include <map>
|
||||
#include <memory>
|
||||
|
||||
// Bounded wait when acquiring GetZipPathLock inside extractor/writer entry
|
||||
// points. A genuine extract is seconds, but adversarial I/O (slow NAS,
|
||||
// antivirus holding files, libzip hang on malformed archive, a crashed
|
||||
// thread that never unwound the lock) can make it block indefinitely.
|
||||
// 15 minutes is generous enough for large models on slow storage yet short
|
||||
// enough that a service-wide hang turns into a localized load-failure
|
||||
// visible in DebugView.
|
||||
static constexpr auto kZipPathLockTimeout = std::chrono::minutes(15);
|
||||
|
||||
// Per-path mutex to serialize concurrent zip operations on the same target.
|
||||
// Without this, two LabVIEW threads can race: one extracting a zip while
|
||||
// another truncates/writes the same file, corrupting data and crashing LabVIEW.
|
||||
// Scope is limited to the extractor / zip writer — once ExtractProtectedZipFile
|
||||
// returns, the sidecar check makes subsequent calls fast no-ops, and readers
|
||||
// (ORT / TRT session create) access stable files concurrently with no lock.
|
||||
static std::mutex g_zipPathMapMutex;
|
||||
static std::map<std::string, std::shared_ptr<std::mutex>> g_zipPathLocks;
|
||||
static std::map<std::string, std::shared_ptr<std::recursive_timed_mutex>> g_zipPathLocks;
|
||||
|
||||
static std::shared_ptr<std::mutex> GetZipPathLock(const std::string& path) {
|
||||
static std::shared_ptr<std::recursive_timed_mutex> GetZipPathLock(const std::string& path) {
|
||||
std::lock_guard<std::mutex> guard(g_zipPathMapMutex);
|
||||
auto& ptr = g_zipPathLocks[path];
|
||||
if (!ptr) ptr = std::make_shared<std::mutex>();
|
||||
if (!ptr) ptr = std::make_shared<std::recursive_timed_mutex>();
|
||||
return ptr;
|
||||
}
|
||||
|
||||
@@ -453,7 +466,17 @@ bool AddFolderContentsToZip(zip* archive, const char* folderPath, const char* zi
|
||||
|
||||
bool ZipFolderWithPassword(const char* folderPath, const char* zipFilePath, const char* password) {
|
||||
auto pathLock = GetZipPathLock(std::string(zipFilePath));
|
||||
std::lock_guard<std::mutex> zipGuard(*pathLock);
|
||||
ANS_DBG("Extract", "ZipFolderWithPassword: waiting on zip lock (%llds): %s",
|
||||
(long long)std::chrono::duration_cast<std::chrono::seconds>(kZipPathLockTimeout).count(),
|
||||
zipFilePath ? zipFilePath : "(null)");
|
||||
std::unique_lock<std::recursive_timed_mutex> zipGuard(*pathLock, std::defer_lock);
|
||||
if (!zipGuard.try_lock_for(kZipPathLockTimeout)) {
|
||||
ANS_DBG("Extract", "ZipFolderWithPassword: TIMEOUT acquiring zip lock for %s",
|
||||
zipFilePath ? zipFilePath : "(null)");
|
||||
return false;
|
||||
}
|
||||
ANS_DBG("Extract", "ZipFolderWithPassword: zip lock acquired: %s",
|
||||
zipFilePath ? zipFilePath : "(null)");
|
||||
|
||||
zip* zipArchive;
|
||||
zip_flags_t flags = ZIP_CREATE | ZIP_TRUNCATE;
|
||||
@@ -839,10 +862,121 @@ std::string GetDateTimeString(const std::string& format) {
|
||||
bool ExtractProtectedZipFile(const std::string& zipFileName, const std::string& password, const std::string& modelName, const std::string outputFolder)
|
||||
{
|
||||
auto pathLock = GetZipPathLock(outputFolder);
|
||||
std::lock_guard<std::mutex> zipGuard(*pathLock);
|
||||
ANS_DBG("Extract", "ExtractProtectedZipFile: waiting on zip lock (%llds): %s",
|
||||
(long long)std::chrono::duration_cast<std::chrono::seconds>(kZipPathLockTimeout).count(),
|
||||
outputFolder.c_str());
|
||||
std::unique_lock<std::recursive_timed_mutex> zipGuard(*pathLock, std::defer_lock);
|
||||
if (!zipGuard.try_lock_for(kZipPathLockTimeout)) {
|
||||
ANS_DBG("Extract", "ExtractProtectedZipFile: TIMEOUT acquiring zip lock for %s (zip=%s)",
|
||||
outputFolder.c_str(), zipFileName.c_str());
|
||||
return false;
|
||||
}
|
||||
ANS_DBG("Extract", "ExtractProtectedZipFile: zip lock acquired: %s", outputFolder.c_str());
|
||||
|
||||
int error;
|
||||
if (!FileExist(zipFileName))return false;
|
||||
|
||||
// Idempotent fast-path: skip re-extraction when the target folder already
|
||||
// holds exactly the content of the current zip. Identity is tracked by a
|
||||
// small sidecar file (.ans_extract_info) written inside outputFolder after
|
||||
// every successful extract. The sidecar records three fields — zip path,
|
||||
// zip size, zip mtime — and we SKIP only if ALL match the current zip AND
|
||||
// the folder still has at least one non-empty file.
|
||||
//
|
||||
// Why sidecar and not just mtime? mtime alone breaks on:
|
||||
// • downgrades — a reverted older zip has an older mtime, so "file mtime
|
||||
// >= zip mtime" falsely reports fresh and we never re-extract.
|
||||
// • preserved-timestamp copies (cp --preserve=timestamps, some installers,
|
||||
// Git-LFS checkouts) — new-but-older-mtime zips look "not newer".
|
||||
// Size differs whenever content differs (libzip's CRC/compression shifts
|
||||
// bytes even for tiny payload changes), so size+mtime+path uniquely pins
|
||||
// the zip identity in practice.
|
||||
//
|
||||
// Any mismatch / missing sidecar / FS error → fall through to full extract,
|
||||
// which unconditionally rewrites the sidecar at the end. This means the
|
||||
// first run after deploying this patched binary will do one re-extract per
|
||||
// model to establish the sidecar; subsequent runs hit the fast path.
|
||||
const std::filesystem::path sidecarPath =
|
||||
std::filesystem::path(outputFolder) / ".ans_extract_info";
|
||||
|
||||
ANS_DBG("Extract", "ExtractProtectedZipFile: zip=%s -> folder=%s",
|
||||
zipFileName.c_str(), outputFolder.c_str());
|
||||
|
||||
// Capture the current zip's identity up-front so both the fast-path check
|
||||
// and the post-extract sidecar write see consistent values.
|
||||
std::uintmax_t curZipSize = 0;
|
||||
long long curZipMtime = 0;
|
||||
bool zipStatOk = false;
|
||||
try {
|
||||
curZipSize = std::filesystem::file_size(zipFileName);
|
||||
curZipMtime = std::filesystem::last_write_time(zipFileName)
|
||||
.time_since_epoch().count();
|
||||
zipStatOk = true;
|
||||
}
|
||||
catch (const std::exception& ex) {
|
||||
ANS_DBG("Extract",
|
||||
"ExtractProtectedZipFile: failed to stat zip (%s); extracting anyway",
|
||||
ex.what());
|
||||
}
|
||||
|
||||
try {
|
||||
if (zipStatOk &&
|
||||
std::filesystem::exists(outputFolder) &&
|
||||
std::filesystem::is_directory(outputFolder) &&
|
||||
std::filesystem::exists(sidecarPath))
|
||||
{
|
||||
// Read sidecar: 3 lines — zipPath, zipSize, zipMtime.
|
||||
std::ifstream sf(sidecarPath);
|
||||
std::string storedPath;
|
||||
std::uintmax_t storedSize = 0;
|
||||
long long storedMtime = 0;
|
||||
std::getline(sf, storedPath);
|
||||
sf >> storedSize >> storedMtime;
|
||||
if (sf.good() || sf.eof()) {
|
||||
// Sanity: folder must still contain at least one non-empty file
|
||||
// (defends against a sidecar that outlived its content, e.g. a
|
||||
// user manually wiping model files but leaving the sidecar).
|
||||
bool hasNonEmpty = false;
|
||||
size_t numFiles = 0;
|
||||
for (const auto& e : std::filesystem::directory_iterator(outputFolder)) {
|
||||
if (!e.is_regular_file()) continue;
|
||||
if (e.path().filename() == ".ans_extract_info") continue;
|
||||
++numFiles;
|
||||
std::error_code ec;
|
||||
if (e.file_size(ec) > 0 && !ec) { hasNonEmpty = true; break; }
|
||||
}
|
||||
const bool pathOk = (storedPath == zipFileName);
|
||||
const bool sizeOk = (storedSize == curZipSize);
|
||||
const bool mtimeOk = (storedMtime == curZipMtime);
|
||||
if (pathOk && sizeOk && mtimeOk && hasNonEmpty) {
|
||||
ANS_DBG("Extract",
|
||||
"ExtractProtectedZipFile: SKIP re-extract — sidecar match (size=%llu mtime=%lld, %zu payload file(s))",
|
||||
(unsigned long long)curZipSize,
|
||||
(long long)curZipMtime, numFiles);
|
||||
return true;
|
||||
}
|
||||
ANS_DBG("Extract",
|
||||
"ExtractProtectedZipFile: full extract needed — sidecar mismatch (path:%d size:%d mtime:%d nonEmpty:%d)",
|
||||
pathOk ? 0 : 1, sizeOk ? 0 : 1, mtimeOk ? 0 : 1,
|
||||
hasNonEmpty ? 1 : 0);
|
||||
} else {
|
||||
ANS_DBG("Extract",
|
||||
"ExtractProtectedZipFile: sidecar unreadable, re-extracting");
|
||||
}
|
||||
} else if (zipStatOk) {
|
||||
ANS_DBG("Extract",
|
||||
"ExtractProtectedZipFile: %s, full extract",
|
||||
std::filesystem::exists(outputFolder) ? "no sidecar yet"
|
||||
: "folder absent");
|
||||
}
|
||||
}
|
||||
catch (const std::exception& ex) {
|
||||
// Any filesystem hiccup: fall through to full extraction (safe).
|
||||
ANS_DBG("Extract",
|
||||
"ExtractProtectedZipFile: freshness check threw, extracting: %s",
|
||||
ex.what());
|
||||
}
|
||||
|
||||
zip_t* archive = zip_open(zipFileName.c_str(), ZIP_RDONLY, &error);
|
||||
if (!archive) {
|
||||
std::cerr << "Error opening ZIP archive: " << zip_strerror(archive) << std::endl;
|
||||
@@ -912,6 +1046,35 @@ bool ExtractProtectedZipFile(const std::string& zipFileName, const std::string&
|
||||
return false;
|
||||
}
|
||||
zip_close(archive);
|
||||
|
||||
// Extract succeeded — write the identity sidecar so the next call on this
|
||||
// folder can take the fast-path. We re-read zip stats here (rather than
|
||||
// trust the pre-extract snapshot) in case the zip was touched in between.
|
||||
try {
|
||||
std::uintmax_t finalSize = std::filesystem::file_size(zipFileName);
|
||||
long long finalMtime = std::filesystem::last_write_time(zipFileName)
|
||||
.time_since_epoch().count();
|
||||
std::ofstream sf(sidecarPath, std::ios::binary | std::ios::trunc);
|
||||
if (sf.is_open()) {
|
||||
sf << zipFileName << '\n' << finalSize << '\n' << finalMtime << '\n';
|
||||
ANS_DBG("Extract",
|
||||
"ExtractProtectedZipFile: sidecar written (size=%llu mtime=%lld) at %s",
|
||||
(unsigned long long)finalSize, (long long)finalMtime,
|
||||
sidecarPath.string().c_str());
|
||||
} else {
|
||||
ANS_DBG("Extract",
|
||||
"ExtractProtectedZipFile: could not open sidecar for write: %s",
|
||||
sidecarPath.string().c_str());
|
||||
}
|
||||
}
|
||||
catch (const std::exception& ex) {
|
||||
// Non-fatal — extract already succeeded. Next call will just re-extract
|
||||
// once more until the sidecar can be written.
|
||||
ANS_DBG("Extract",
|
||||
"ExtractProtectedZipFile: sidecar write threw (non-fatal): %s",
|
||||
ex.what());
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -16,6 +16,8 @@
|
||||
#include <vector>
|
||||
#include <regex>
|
||||
#include <stdio.h>
|
||||
#include <memory>
|
||||
#include <mutex>
|
||||
|
||||
//namespace logging = boost::log;
|
||||
//namespace attrs = boost::log::attributes;
|
||||
@@ -89,4 +91,6 @@ namespace fs = std::filesystem;
|
||||
// For training engine
|
||||
//bool ExtractPasswordProtectedZipForTrainingEgnine(const std::string& zipFileName, const std::string& password, const std::string& modelName, std::string& outputFolder, bool edgeDeviceModel = true);
|
||||
ANSLICENSE_API bool ExtractProtectedZipFile(const std::string& zipFileName,const std::string& password,const std::string& modelName,const std::string outputFolder);
|
||||
|
||||
|
||||
#endif
|
||||
+184
-5
@@ -22,6 +22,7 @@
|
||||
#include <nvjpeg.h>
|
||||
#include <cuda_runtime.h>
|
||||
#include "ANSCVVendorGate.h"
|
||||
#include "ANSLicense.h" // ANS_DBG macro
|
||||
#include <thread>
|
||||
#include <future>
|
||||
#include <opencv2/imgproc.hpp>
|
||||
@@ -4252,15 +4253,23 @@ extern "C" __declspec(dllexport) int ANSCV_ResizeImage_Static(unsigned char* in
|
||||
// Image Reference Management
|
||||
|
||||
extern "C" __declspec(dllexport) int ANSCV_CloneImage_S(cv::Mat** imageIn, cv::Mat** imageOut) {
|
||||
ANS_DBG("ANSCV_CloneImage", "ENTRY imageIn=%p imageOut=%p src=%p",
|
||||
(void*)imageIn, (void*)imageOut, (imageIn ? (void*)*imageIn : nullptr));
|
||||
try {
|
||||
//std::lock_guard<std::mutex> lock(imageMutex);
|
||||
std::unique_lock<std::timed_mutex> lock(timeImageMutex, std::defer_lock);
|
||||
if (!lock.try_lock_for(std::chrono::milliseconds(MUTEX_TIMEOUT_MS))) {
|
||||
ANS_DBG("ANSCV_CloneImage", "ERROR mutex timeout (%dms)", (int)MUTEX_TIMEOUT_MS);
|
||||
std::cerr << "Error: Mutex timeout in ANSCV_CloneImage_S!" << std::endl;
|
||||
return -6;
|
||||
}
|
||||
try {
|
||||
if (!imageIn || !(*imageIn) || (*imageIn)->empty() || !(*imageIn)->data) {
|
||||
ANS_DBG("ANSCV_CloneImage", "ERROR invalid input imageIn=%p src=%p empty=%d data=%p",
|
||||
(void*)imageIn,
|
||||
(imageIn ? (void*)*imageIn : nullptr),
|
||||
(imageIn && *imageIn) ? (int)(*imageIn)->empty() : -1,
|
||||
(imageIn && *imageIn) ? (void*)(*imageIn)->data : nullptr);
|
||||
std::cerr << "Error: Invalid or empty input image in ANSCV_CloneImage_S!" << std::endl;
|
||||
return -2;
|
||||
}
|
||||
@@ -4268,47 +4277,62 @@ extern "C" __declspec(dllexport) int ANSCV_CloneImage_S(cv::Mat** imageIn, cv::M
|
||||
*imageOut = anscv_mat_new(**imageIn);
|
||||
// Link clone to same NV12 frame data (refcount++)
|
||||
gpu_frame_addref(*imageIn, *imageOut);
|
||||
ANS_DBG("ANSCV_CloneImage", "SUCCESS dst=%p size=%dx%d type=%d",
|
||||
(void*)*imageOut, (*imageOut)->cols, (*imageOut)->rows, (*imageOut)->type());
|
||||
return 1; // Success
|
||||
}
|
||||
}
|
||||
catch (const std::bad_alloc& e) {
|
||||
ANS_DBG("ANSCV_CloneImage", "ERROR bad_alloc inner: %s", e.what());
|
||||
std::cerr << "Memory allocation failed in ANSCV_CloneImage_S: " << e.what() << std::endl;
|
||||
return -1;
|
||||
}
|
||||
catch (const std::exception& e) {
|
||||
ANS_DBG("ANSCV_CloneImage", "ERROR exception inner: %s", e.what());
|
||||
std::cerr << "Error: Exception occurred in ANSCV_CloneImage_S: " << e.what() << std::endl;
|
||||
return -3;
|
||||
}
|
||||
}
|
||||
catch (const std::bad_alloc& e) {
|
||||
ANS_DBG("ANSCV_CloneImage", "ERROR bad_alloc outer: %s", e.what());
|
||||
std::cerr << "Memory allocation failed in ANSCV_CloneImage_S: " << e.what() << std::endl;
|
||||
return -1;
|
||||
}
|
||||
catch (const std::exception& e) {
|
||||
ANS_DBG("ANSCV_CloneImage", "ERROR exception outer: %s", e.what());
|
||||
std::cerr << "Error: Exception occurred in ANSCV_CloneImage_S: " << e.what() << std::endl;
|
||||
return -3;
|
||||
}
|
||||
}
|
||||
extern "C" __declspec(dllexport) int ANSCV_ReleaseImage_S(cv::Mat** imageIn) {
|
||||
void* matPtr = (imageIn ? (void*)*imageIn : nullptr);
|
||||
ANS_DBG("ANSCV_ReleaseImage", "ENTRY imageIn=%p mat=%p", (void*)imageIn, matPtr);
|
||||
try {
|
||||
if (!imageIn || !(*imageIn)) {
|
||||
ANS_DBG("ANSCV_ReleaseImage", "SKIP null imageIn=%p mat=%p", (void*)imageIn, matPtr);
|
||||
return -2;
|
||||
}
|
||||
// anscv_mat_delete is thread-safe: checks the registry, only deletes if
|
||||
// the pointer is still registered (not already freed by a stream source).
|
||||
bool deleted = anscv_mat_delete(imageIn);
|
||||
ANS_DBG("ANSCV_ReleaseImage", "%s mat=%p", deleted ? "DELETED" : "NOT_REGISTERED", matPtr);
|
||||
return deleted ? 1 : -4;
|
||||
}
|
||||
catch (const std::exception& e) {
|
||||
ANS_DBG("ANSCV_ReleaseImage", "ERROR exception mat=%p: %s", matPtr, e.what());
|
||||
std::cerr << "Error: Exception occurred in ANSCV_ReleaseImage_S: " << e.what() << std::endl;
|
||||
return -3;
|
||||
}
|
||||
catch (...) {
|
||||
ANS_DBG("ANSCV_ReleaseImage", "ERROR unknown exception mat=%p", matPtr);
|
||||
std::cerr << "Error: Unknown exception in ANSCV_ReleaseImage_S." << std::endl;
|
||||
return -3;
|
||||
}
|
||||
}
|
||||
extern "C" __declspec(dllexport) int ANSCV_CropImage_S(cv::Mat** imageIn, int x, int y, int width, int height, int originalImageSize) {
|
||||
void* matPtr = (imageIn ? (void*)*imageIn : nullptr);
|
||||
ANS_DBG("ANSCV_CropImage", "ENTRY mat=%p roi=(%d,%d,%dx%d) origSize=%d",
|
||||
matPtr, x, y, width, height, originalImageSize);
|
||||
gpu_frame_invalidate(imageIn ? *imageIn : nullptr);
|
||||
try {
|
||||
// Step 1: Validate and copy input image safely
|
||||
@@ -4317,11 +4341,13 @@ extern "C" __declspec(dllexport) int ANSCV_CropImage_S(cv::Mat** imageIn, int x,
|
||||
//std::lock_guard<std::mutex> lock(imageMutex);
|
||||
std::unique_lock<std::timed_mutex> lock(timeImageMutex, std::defer_lock);
|
||||
if (!lock.try_lock_for(std::chrono::milliseconds(MUTEX_TIMEOUT_MS))) {
|
||||
ANS_DBG("ANSCV_CropImage", "ERROR mutex timeout (copy phase) mat=%p", matPtr);
|
||||
std::cerr << "Error: Mutex timeout in ANSCV_CropImage_S!" << std::endl;
|
||||
return -6;
|
||||
}
|
||||
try {
|
||||
if (!imageIn || !(*imageIn) || (*imageIn)->empty() || !(*imageIn)->data) {
|
||||
ANS_DBG("ANSCV_CropImage", "ERROR invalid input mat=%p", matPtr);
|
||||
std::cerr << "Error: Invalid or empty input image in ANSCV_CloneImage_S!" << std::endl;
|
||||
return -2;
|
||||
}
|
||||
@@ -4330,10 +4356,12 @@ extern "C" __declspec(dllexport) int ANSCV_CropImage_S(cv::Mat** imageIn, int x,
|
||||
}
|
||||
}
|
||||
catch (const std::bad_alloc& e) {
|
||||
ANS_DBG("ANSCV_CropImage", "ERROR bad_alloc on copy mat=%p: %s", matPtr, e.what());
|
||||
std::cerr << "Memory allocation failed in ANSCV_CloneImage_S: " << e.what() << std::endl;
|
||||
return -1;
|
||||
}
|
||||
catch (const std::exception& e) {
|
||||
ANS_DBG("ANSCV_CropImage", "ERROR exception on copy mat=%p: %s", matPtr, e.what());
|
||||
std::cerr << "Error: Exception occurred in ANSCV_CloneImage_S: " << e.what() << std::endl;
|
||||
return -3;
|
||||
}
|
||||
@@ -4341,6 +4369,7 @@ extern "C" __declspec(dllexport) int ANSCV_CropImage_S(cv::Mat** imageIn, int x,
|
||||
|
||||
// Step 2: Validate cropping parameters
|
||||
if (width <= 0 || height <= 0) {
|
||||
ANS_DBG("ANSCV_CropImage", "ERROR invalid width/height w=%d h=%d", width, height);
|
||||
std::cerr << "Error: Invalid width or height for cropping image in ANSCV_CropImage_S!" << std::endl;
|
||||
return -2;
|
||||
}
|
||||
@@ -4354,10 +4383,13 @@ extern "C" __declspec(dllexport) int ANSCV_CropImage_S(cv::Mat** imageIn, int x,
|
||||
height = min(height, originalHeight - y);
|
||||
|
||||
cv::Rect roi(x, y, width, height);
|
||||
ANS_DBG("ANSCV_CropImage", "CLAMPED roi=(%d,%d,%dx%d) src=%dx%d",
|
||||
x, y, width, height, originalWidth, originalHeight);
|
||||
|
||||
// Step 3: Process crop outside lock
|
||||
ANSCENTER::ANSOPENCV ansCVInstance;
|
||||
if (!ansCVInstance.Init("")) {
|
||||
ANS_DBG("ANSCV_CropImage", "ERROR ansCVInstance.Init failed");
|
||||
std::cerr << "Error: Failed to initialize ANSCV instance!" << std::endl;
|
||||
return -5;
|
||||
}
|
||||
@@ -4367,16 +4399,20 @@ extern "C" __declspec(dllexport) int ANSCV_CropImage_S(cv::Mat** imageIn, int x,
|
||||
{
|
||||
std::unique_lock<std::timed_mutex> lock(timeImageMutex, std::defer_lock);
|
||||
if (!lock.try_lock_for(std::chrono::milliseconds(MUTEX_TIMEOUT_MS))) {
|
||||
ANS_DBG("ANSCV_CropImage", "ERROR mutex timeout (writeback) mat=%p", matPtr);
|
||||
std::cerr << "Error: Mutex timeout in ANSCV_CropImage_S!" << std::endl;
|
||||
return -6;
|
||||
}
|
||||
//std::lock_guard<std::mutex> lock(imageMutex);
|
||||
if (croppedImage.empty()) {
|
||||
ANS_DBG("ANSCV_CropImage", "ERROR cropped image empty mat=%p", matPtr);
|
||||
std::cerr << "Error: Failed to crop image in ANSCV_CropImage_S!" << std::endl;
|
||||
return 0;
|
||||
}
|
||||
else {
|
||||
if (!imageIn || !(*imageIn) || (*imageIn)->empty() || !(*imageIn)->data) {
|
||||
ANS_DBG("ANSCV_CropImage", "ERROR input invalid at writeback mat=%p",
|
||||
(imageIn ? (void*)*imageIn : nullptr));
|
||||
std::cerr << "Error: Invalid or empty input image in ANSCV_CloneImage_S!" << std::endl;
|
||||
return -2;
|
||||
}
|
||||
@@ -4385,9 +4421,14 @@ extern "C" __declspec(dllexport) int ANSCV_CropImage_S(cv::Mat** imageIn, int x,
|
||||
|
||||
}
|
||||
|
||||
ANS_DBG("ANSCV_CropImage", "SUCCESS mat=%p new=%dx%d",
|
||||
(imageIn && *imageIn) ? (void*)*imageIn : nullptr,
|
||||
(imageIn && *imageIn) ? (*imageIn)->cols : -1,
|
||||
(imageIn && *imageIn) ? (*imageIn)->rows : -1);
|
||||
return 1; // Success
|
||||
}
|
||||
catch (const std::exception& e) {
|
||||
ANS_DBG("ANSCV_CropImage", "ERROR exception outer mat=%p: %s", matPtr, e.what());
|
||||
std::cerr << "Exception in ANSCV_CropImage_S: " << e.what() << std::endl;
|
||||
return -3;
|
||||
}
|
||||
@@ -4395,8 +4436,11 @@ extern "C" __declspec(dllexport) int ANSCV_CropImage_S(cv::Mat** imageIn, int x,
|
||||
|
||||
extern "C" __declspec(dllexport) int ANSCV_GetImage_CPP(cv::Mat** imageIn, int width, int quality,
|
||||
int& newWidth, int& newHeight, std::string& outputImage) {
|
||||
void* matPtr = (imageIn ? (void*)*imageIn : nullptr);
|
||||
ANS_DBG("ANSCV_GetImage_CPP", "ENTRY mat=%p targetW=%d quality=%d", matPtr, width, quality);
|
||||
try {
|
||||
if (!imageIn || !(*imageIn) || (*imageIn)->empty() || !(*imageIn)->data) {
|
||||
ANS_DBG("ANSCV_GetImage_CPP", "ERROR invalid input mat=%p", matPtr);
|
||||
std::cerr << "Error: Invalid or empty input image!" << std::endl;
|
||||
return -2;
|
||||
}
|
||||
@@ -4408,11 +4452,13 @@ extern "C" __declspec(dllexport) int ANSCV_GetImage_CPP(cv::Mat** imageIn, int w
|
||||
{
|
||||
std::unique_lock<std::timed_mutex> lock(timeImageMutex, std::chrono::milliseconds(1000));
|
||||
if (!lock.owns_lock()) {
|
||||
ANS_DBG("ANSCV_GetImage_CPP", "ERROR mutex timeout (dims) mat=%p", matPtr);
|
||||
std::cerr << "Error: Mutex timeout!" << std::endl;
|
||||
return -6;
|
||||
}
|
||||
|
||||
if (img->empty() || !img->data) {
|
||||
ANS_DBG("ANSCV_GetImage_CPP", "ERROR invalid after lock mat=%p", matPtr);
|
||||
std::cerr << "Error: Invalid image!" << std::endl;
|
||||
return -2;
|
||||
}
|
||||
@@ -4425,33 +4471,57 @@ extern "C" __declspec(dllexport) int ANSCV_GetImage_CPP(cv::Mat** imageIn, int w
|
||||
cv::Mat processedImage;
|
||||
|
||||
if (width > 0 && width < imageMaxSize) {
|
||||
ANS_DBG("ANSCV_GetImage_CPP", "RESIZE mat=%p src=%dx%d targetW=%d",
|
||||
matPtr, originalWidth, originalHeight, width);
|
||||
// Only lock when we need to resize
|
||||
std::unique_lock<std::timed_mutex> lock(timeImageMutex, std::chrono::milliseconds(1000));
|
||||
if (!lock.owns_lock()) return -6;
|
||||
if (!lock.owns_lock()) {
|
||||
ANS_DBG("ANSCV_GetImage_CPP", "ERROR mutex timeout (resize) mat=%p", matPtr);
|
||||
return -6;
|
||||
}
|
||||
|
||||
ANSCENTER::ANSOPENCV ansCVInstance;
|
||||
if (!ansCVInstance.Init("")) return -5;
|
||||
if (!ansCVInstance.Init("")) {
|
||||
ANS_DBG("ANSCV_GetImage_CPP", "ERROR ansCVInstance.Init failed");
|
||||
return -5;
|
||||
}
|
||||
|
||||
processedImage = ansCVInstance.ImageResizeV2(*img, width);
|
||||
}
|
||||
else {
|
||||
ANS_DBG("ANSCV_GetImage_CPP", "CLONE_ONLY mat=%p src=%dx%d targetW=%d",
|
||||
matPtr, originalWidth, originalHeight, width);
|
||||
// No resize needed - just copy quickly
|
||||
std::unique_lock<std::timed_mutex> lock(timeImageMutex, std::chrono::milliseconds(1000));
|
||||
if (!lock.owns_lock()) return -6;
|
||||
if (!lock.owns_lock()) {
|
||||
ANS_DBG("ANSCV_GetImage_CPP", "ERROR mutex timeout (clone) mat=%p", matPtr);
|
||||
return -6;
|
||||
}
|
||||
|
||||
processedImage = img->clone(); // Slightly faster than copyTo
|
||||
}
|
||||
|
||||
if (processedImage.empty()) return -8;
|
||||
if (processedImage.empty()) {
|
||||
ANS_DBG("ANSCV_GetImage_CPP", "ERROR processedImage empty mat=%p", matPtr);
|
||||
return -8;
|
||||
}
|
||||
|
||||
newWidth = processedImage.cols;
|
||||
newHeight = processedImage.rows;
|
||||
|
||||
outputImage = ANSCENTER::CompressJpegToString(processedImage, quality);
|
||||
return outputImage.empty() ? -9 : 1;
|
||||
if (outputImage.empty()) {
|
||||
ANS_DBG("ANSCV_GetImage_CPP", "ERROR JPEG compression empty mat=%p %dx%d q=%d",
|
||||
matPtr, newWidth, newHeight, quality);
|
||||
return -9;
|
||||
}
|
||||
ANS_DBG("ANSCV_GetImage_CPP", "SUCCESS mat=%p out=%dx%d jpegBytes=%zu",
|
||||
matPtr, newWidth, newHeight, outputImage.size());
|
||||
return 1;
|
||||
|
||||
}
|
||||
catch (...) {
|
||||
ANS_DBG("ANSCV_GetImage_CPP", "ERROR unknown exception mat=%p", matPtr);
|
||||
return -4;
|
||||
}
|
||||
}
|
||||
@@ -4600,13 +4670,18 @@ extern "C" __declspec(dllexport) int ANSCV_GetImage_CPP(cv::Mat** imageIn, int w
|
||||
//}
|
||||
|
||||
extern "C" __declspec(dllexport) int ANSCV_GetImage_S(cv::Mat** imageIn, int width, int quality, int& newWidth, int& newHeight, LStrHandle outputImage) {
|
||||
void* matPtr = (imageIn ? (void*)*imageIn : nullptr);
|
||||
ANS_DBG("ANSCV_GetImage", "ENTRY mat=%p targetW=%d quality=%d outHandle=%p",
|
||||
matPtr, width, quality, (void*)outputImage);
|
||||
try {
|
||||
if (!imageIn || !(*imageIn) || (*imageIn)->empty() || !(*imageIn)->data) {
|
||||
ANS_DBG("ANSCV_GetImage", "ERROR invalid input mat=%p", matPtr);
|
||||
std::cerr << "Error: Invalid or empty input image in ANSCV_GetImage_S!" << std::endl;
|
||||
return -2;
|
||||
}
|
||||
|
||||
if (!outputImage) {
|
||||
ANS_DBG("ANSCV_GetImage", "ERROR null LStrHandle");
|
||||
std::cerr << "Error: Output image handle is null!" << std::endl;
|
||||
return -2;
|
||||
}
|
||||
@@ -4615,11 +4690,14 @@ extern "C" __declspec(dllexport) int ANSCV_GetImage_S(cv::Mat** imageIn, int wid
|
||||
{
|
||||
std::unique_lock<std::timed_mutex> lock(timeImageMutex, std::defer_lock);
|
||||
if (!lock.try_lock_for(std::chrono::milliseconds(MUTEX_TIMEOUT_MS))) {
|
||||
ANS_DBG("ANSCV_GetImage", "ERROR mutex timeout mat=%p", matPtr);
|
||||
std::cerr << "Error: Mutex timeout in ANSCV_GetImage_S!" << std::endl;
|
||||
return -6;
|
||||
}
|
||||
|
||||
if (!imageIn || !(*imageIn) || (*imageIn)->empty() || !(*imageIn)->data) {
|
||||
ANS_DBG("ANSCV_GetImage", "ERROR invalid after lock mat=%p",
|
||||
(imageIn ? (void*)*imageIn : nullptr));
|
||||
std::cerr << "Error: Image became invalid after mutex acquisition!" << std::endl;
|
||||
return -2;
|
||||
}
|
||||
@@ -4628,12 +4706,14 @@ extern "C" __declspec(dllexport) int ANSCV_GetImage_S(cv::Mat** imageIn, int wid
|
||||
(*imageIn)->copyTo(imgCopy);
|
||||
}
|
||||
catch (const cv::Exception& e) {
|
||||
ANS_DBG("ANSCV_GetImage", "ERROR cv::Exception on copyTo mat=%p: %s", matPtr, e.what());
|
||||
std::cerr << "Error: OpenCV exception during image copy: " << e.what() << std::endl;
|
||||
return -7;
|
||||
}
|
||||
}
|
||||
|
||||
if (imgCopy.empty() || !imgCopy.data) {
|
||||
ANS_DBG("ANSCV_GetImage", "ERROR imgCopy empty after copy mat=%p", matPtr);
|
||||
std::cerr << "Error: Copied image is invalid in ANSCV_GetImage_S!" << std::endl;
|
||||
return -2;
|
||||
}
|
||||
@@ -4643,14 +4723,18 @@ extern "C" __declspec(dllexport) int ANSCV_GetImage_S(cv::Mat** imageIn, int wid
|
||||
int imageMaxSize = max(originalWidth, originalHeight);
|
||||
|
||||
if (width > 0 && width < imageMaxSize) {
|
||||
ANS_DBG("ANSCV_GetImage", "RESIZE mat=%p src=%dx%d targetW=%d",
|
||||
matPtr, originalWidth, originalHeight, width);
|
||||
ANSCENTER::ANSOPENCV ansCVInstance;
|
||||
if (!ansCVInstance.Init("")) {
|
||||
ANS_DBG("ANSCV_GetImage", "ERROR ansCVInstance.Init failed");
|
||||
std::cerr << "Error: Failed to initialize ANSOPENCV instance!" << std::endl;
|
||||
return -5;
|
||||
}
|
||||
|
||||
cv::Mat resized = ansCVInstance.ImageResizeV2(imgCopy, width);
|
||||
if (resized.empty()) {
|
||||
ANS_DBG("ANSCV_GetImage", "ERROR resize result empty mat=%p", matPtr);
|
||||
std::cerr << "Error: Resizing failed!" << std::endl;
|
||||
return -8;
|
||||
}
|
||||
@@ -4661,6 +4745,8 @@ extern "C" __declspec(dllexport) int ANSCV_GetImage_S(cv::Mat** imageIn, int wid
|
||||
newHeight = imgCopy.rows;
|
||||
std::string jpegString = ANSCENTER::CompressJpegToString(imgCopy, quality);
|
||||
if (jpegString.empty()) {
|
||||
ANS_DBG("ANSCV_GetImage", "ERROR JPEG compress empty mat=%p %dx%d q=%d",
|
||||
matPtr, newWidth, newHeight, quality);
|
||||
std::cerr << "Error: JPEG compression failed!" << std::endl;
|
||||
return -9;
|
||||
}
|
||||
@@ -4668,12 +4754,15 @@ extern "C" __declspec(dllexport) int ANSCV_GetImage_S(cv::Mat** imageIn, int wid
|
||||
int32_t size = static_cast<int32_t>(jpegString.size());
|
||||
|
||||
if (size > 50 * 1024 * 1024) {
|
||||
ANS_DBG("ANSCV_GetImage", "ERROR jpeg too large mat=%p bytes=%d", matPtr, (int)size);
|
||||
std::cerr << "Error: Compressed image size too large: " << size << " bytes" << std::endl;
|
||||
return -10;
|
||||
}
|
||||
|
||||
MgErr error = DSSetHandleSize(outputImage, sizeof(int32) + size);
|
||||
if (error != noErr) {
|
||||
ANS_DBG("ANSCV_GetImage", "ERROR DSSetHandleSize failed code=%d bytes=%d",
|
||||
(int)error, (int)size);
|
||||
std::cerr << "Error: Failed to allocate memory for output image! Error code: " << error << std::endl;
|
||||
return -10;
|
||||
}
|
||||
@@ -4681,32 +4770,41 @@ extern "C" __declspec(dllexport) int ANSCV_GetImage_S(cv::Mat** imageIn, int wid
|
||||
(*outputImage)->cnt = size;
|
||||
memcpy((*outputImage)->str, jpegString.data(), size);
|
||||
|
||||
ANS_DBG("ANSCV_GetImage", "SUCCESS mat=%p out=%dx%d jpegBytes=%d",
|
||||
matPtr, newWidth, newHeight, (int)size);
|
||||
return 1;
|
||||
|
||||
}
|
||||
catch (const std::exception& e) {
|
||||
ANS_DBG("ANSCV_GetImage", "ERROR exception mat=%p: %s", matPtr, e.what());
|
||||
std::cerr << "Exception in ANSCV_GetImage_S: " << e.what() << std::endl;
|
||||
return -3;
|
||||
}
|
||||
catch (...) {
|
||||
ANS_DBG("ANSCV_GetImage", "ERROR unknown exception mat=%p", matPtr);
|
||||
std::cerr << "Unknown exception in ANSCV_GetImage_S!" << std::endl;
|
||||
return -4;
|
||||
}
|
||||
}
|
||||
|
||||
extern "C" __declspec(dllexport) int ANSCV_ReSizeImage_S(cv::Mat** imageIn, int width, int originalImageSize) {
|
||||
void* matPtr = (imageIn ? (void*)*imageIn : nullptr);
|
||||
ANS_DBG("ANSCV_ReSizeImage", "ENTRY mat=%p width=%d origSize=%d",
|
||||
matPtr, width, originalImageSize);
|
||||
gpu_frame_invalidate(imageIn ? *imageIn : nullptr);
|
||||
try {
|
||||
cv::Mat localImage;
|
||||
{
|
||||
std::unique_lock<std::timed_mutex> lock(timeImageMutex, std::defer_lock);
|
||||
if (!lock.try_lock_for(std::chrono::milliseconds(MUTEX_TIMEOUT_MS))) {
|
||||
ANS_DBG("ANSCV_ReSizeImage", "ERROR mutex timeout (copy phase) mat=%p", matPtr);
|
||||
std::cerr << "Error: Mutex timeout in ANSCV_ReSizeImage_S!" << std::endl;
|
||||
return -6;
|
||||
}
|
||||
//std::lock_guard<std::mutex> lock(imageMutex);
|
||||
try {
|
||||
if (!imageIn || !(*imageIn) || (*imageIn)->empty() || !(*imageIn)->data) {
|
||||
ANS_DBG("ANSCV_ReSizeImage", "ERROR invalid input mat=%p", matPtr);
|
||||
std::cerr << "Error: Invalid or empty input image in ANSCV_CloneImage_S!" << std::endl;
|
||||
return -2;
|
||||
}
|
||||
@@ -4715,16 +4813,19 @@ extern "C" __declspec(dllexport) int ANSCV_ReSizeImage_S(cv::Mat** imageIn, int
|
||||
}
|
||||
}
|
||||
catch (const std::bad_alloc& e) {
|
||||
ANS_DBG("ANSCV_ReSizeImage", "ERROR bad_alloc mat=%p: %s", matPtr, e.what());
|
||||
std::cerr << "Memory allocation failed in ANSCV_CloneImage_S: " << e.what() << std::endl;
|
||||
return -1;
|
||||
}
|
||||
catch (const std::exception& e) {
|
||||
ANS_DBG("ANSCV_ReSizeImage", "ERROR exception copy mat=%p: %s", matPtr, e.what());
|
||||
std::cerr << "Error: Exception occurred in ANSCV_CloneImage_S: " << e.what() << std::endl;
|
||||
return -3;
|
||||
}
|
||||
}
|
||||
|
||||
if (width <= 0) {
|
||||
ANS_DBG("ANSCV_ReSizeImage", "ERROR invalid target width=%d", width);
|
||||
std::cerr << "Error: Invalid target width in ANSCV_ReSizeImage_S!" << std::endl;
|
||||
return -2;
|
||||
}
|
||||
@@ -4744,27 +4845,37 @@ extern "C" __declspec(dllexport) int ANSCV_ReSizeImage_S(cv::Mat** imageIn, int
|
||||
int targetHeight = static_cast<int>(std::round(targetWidth * static_cast<double>(originalHeight) / originalWidth));
|
||||
|
||||
if (targetHeight <= 0) {
|
||||
ANS_DBG("ANSCV_ReSizeImage", "ERROR computed height invalid targetW=%d origW=%d origH=%d",
|
||||
targetWidth, originalWidth, originalHeight);
|
||||
std::cerr << "Error: Computed height is invalid!" << std::endl;
|
||||
return -2;
|
||||
}
|
||||
ANS_DBG("ANSCV_ReSizeImage", "RESIZE mat=%p src=%dx%d -> %dx%d",
|
||||
matPtr, originalWidth, originalHeight, targetWidth, targetHeight);
|
||||
cv::resize(localImage, resizedImage, cv::Size(targetWidth, targetHeight), 0, 0, cv::INTER_LANCZOS4);
|
||||
}
|
||||
else {
|
||||
ANS_DBG("ANSCV_ReSizeImage", "SKIP_RESIZE mat=%p targetW=%d >= origW=%d",
|
||||
matPtr, targetWidth, originalWidth);
|
||||
resizedImage = localImage.clone(); // No resizing needed
|
||||
}
|
||||
{
|
||||
std::unique_lock<std::timed_mutex> lock(timeImageMutex, std::defer_lock);
|
||||
if (!lock.try_lock_for(std::chrono::milliseconds(MUTEX_TIMEOUT_MS))) {
|
||||
ANS_DBG("ANSCV_ReSizeImage", "ERROR mutex timeout (writeback) mat=%p", matPtr);
|
||||
std::cerr << "Error: Mutex timeout in ANSCV_ReSizeImage_S!" << std::endl;
|
||||
return -6;
|
||||
}
|
||||
//std::lock_guard<std::mutex> lock(imageMutex);
|
||||
if (resizedImage.empty()) {
|
||||
ANS_DBG("ANSCV_ReSizeImage", "ERROR resized empty mat=%p", matPtr);
|
||||
std::cerr << "Error: Resizing failed!" << std::endl;
|
||||
return 0;
|
||||
}
|
||||
else {
|
||||
if (!imageIn || !(*imageIn) || (*imageIn)->empty() || !(*imageIn)->data) {
|
||||
ANS_DBG("ANSCV_ReSizeImage", "ERROR input invalid at writeback mat=%p",
|
||||
(imageIn ? (void*)*imageIn : nullptr));
|
||||
std::cerr << "Error: Invalid or empty input image in ANSCV_CloneImage_S!" << std::endl;
|
||||
return -2;
|
||||
}
|
||||
@@ -4773,15 +4884,23 @@ extern "C" __declspec(dllexport) int ANSCV_ReSizeImage_S(cv::Mat** imageIn, int
|
||||
|
||||
}
|
||||
|
||||
ANS_DBG("ANSCV_ReSizeImage", "SUCCESS mat=%p new=%dx%d",
|
||||
(imageIn && *imageIn) ? (void*)*imageIn : nullptr,
|
||||
(imageIn && *imageIn) ? (*imageIn)->cols : -1,
|
||||
(imageIn && *imageIn) ? (*imageIn)->rows : -1);
|
||||
return 1;
|
||||
}
|
||||
catch (const std::exception& e) {
|
||||
ANS_DBG("ANSCV_ReSizeImage", "ERROR exception outer mat=%p: %s", matPtr, e.what());
|
||||
std::cerr << "Exception in ANSCV_ReSizeImage_S: " << e.what() << std::endl;
|
||||
return -3;
|
||||
}
|
||||
}
|
||||
|
||||
extern "C" __declspec(dllexport) int ANSCV_GetImageAndRemoveImgRef_S(cv::Mat** imageIn, int width, int quality, int& newWidth, int& newHeight, LStrHandle outputImage) {
|
||||
void* matPtr = (imageIn ? (void*)*imageIn : nullptr);
|
||||
ANS_DBG("ANSCV_GetImageAndRemove", "ENTRY mat=%p targetW=%d quality=%d outHandle=%p",
|
||||
matPtr, width, quality, (void*)outputImage);
|
||||
bool cleanupRequired = true;
|
||||
try {
|
||||
cv::Mat imgCopy;
|
||||
@@ -4789,19 +4908,24 @@ extern "C" __declspec(dllexport) int ANSCV_GetImageAndRemoveImgRef_S(cv::Mat** i
|
||||
//std::lock_guard<std::mutex> lock(imageMutex);
|
||||
std::unique_lock<std::timed_mutex> lock(timeImageMutex, std::defer_lock);
|
||||
if (!lock.try_lock_for(std::chrono::milliseconds(MUTEX_TIMEOUT_MS))) {
|
||||
ANS_DBG("ANSCV_GetImageAndRemove", "ERROR mutex timeout mat=%p", matPtr);
|
||||
std::cerr << "Error: Mutex timeout in ANSCV_ReSizeImage_S!" << std::endl;
|
||||
return -6;
|
||||
}
|
||||
if (!imageIn || !(*imageIn) || (*imageIn)->empty() || !(*imageIn)->data) {
|
||||
ANS_DBG("ANSCV_GetImageAndRemove", "ERROR invalid input mat=%p",
|
||||
(imageIn ? (void*)*imageIn : nullptr));
|
||||
std::cerr << "Error: Invalid or empty input image in ANSCV_GetImageAndRemoveImgRef_S!" << std::endl;
|
||||
return -2;
|
||||
}
|
||||
(*imageIn)->copyTo(imgCopy);
|
||||
ANS_DBG("ANSCV_GetImageAndRemove", "DELETING mat=%p (after copy)", matPtr);
|
||||
anscv_mat_delete(imageIn); // Safe delete + null
|
||||
cleanupRequired = false; // We already deleted inside lock
|
||||
}
|
||||
|
||||
if (imgCopy.empty() || !imgCopy.data) {
|
||||
ANS_DBG("ANSCV_GetImageAndRemove", "ERROR imgCopy invalid (orig mat=%p)", matPtr);
|
||||
std::cerr << "Error: Copied image is invalid in ANSCV_GetImageAndRemoveImgRef_S!" << std::endl;
|
||||
return 0;
|
||||
}
|
||||
@@ -4811,13 +4935,17 @@ extern "C" __declspec(dllexport) int ANSCV_GetImageAndRemoveImgRef_S(cv::Mat** i
|
||||
int imageMaxSize = max(originalWidth, originalHeight);
|
||||
|
||||
if (width > 0 && width < imageMaxSize) {
|
||||
ANS_DBG("ANSCV_GetImageAndRemove", "RESIZE src=%dx%d targetW=%d",
|
||||
originalWidth, originalHeight, width);
|
||||
ANSCENTER::ANSOPENCV ansCVInstance;
|
||||
if (!ansCVInstance.Init("")) {
|
||||
ANS_DBG("ANSCV_GetImageAndRemove", "ERROR ansCVInstance.Init failed");
|
||||
std::cerr << "Error: Failed to initialize ANSOPENCV instance!" << std::endl;
|
||||
return -5;
|
||||
}
|
||||
cv::Mat resized = ansCVInstance.ImageResizeV2(imgCopy, width);
|
||||
if (resized.empty()) {
|
||||
ANS_DBG("ANSCV_GetImageAndRemove", "ERROR resize empty");
|
||||
std::cerr << "Error: Resizing failed!" << std::endl;
|
||||
return 0;
|
||||
}
|
||||
@@ -4829,6 +4957,8 @@ extern "C" __declspec(dllexport) int ANSCV_GetImageAndRemoveImgRef_S(cv::Mat** i
|
||||
|
||||
std::string jpegString = ANSCENTER::CompressJpegToString(imgCopy, quality);
|
||||
if (jpegString.empty()) {
|
||||
ANS_DBG("ANSCV_GetImageAndRemove", "ERROR JPEG compress empty %dx%d q=%d",
|
||||
newWidth, newHeight, quality);
|
||||
std::cerr << "Error: JPEG compression failed in ANSCV_GetImageAndRemoveImgRef_S!" << std::endl;
|
||||
return 0;
|
||||
}
|
||||
@@ -4836,6 +4966,8 @@ extern "C" __declspec(dllexport) int ANSCV_GetImageAndRemoveImgRef_S(cv::Mat** i
|
||||
int32_t size = static_cast<int32_t>(jpegString.size());
|
||||
MgErr error = DSSetHandleSize(outputImage, sizeof(int32) + size);
|
||||
if (error != noErr) {
|
||||
ANS_DBG("ANSCV_GetImageAndRemove", "ERROR DSSetHandleSize failed code=%d bytes=%d",
|
||||
(int)error, (int)size);
|
||||
std::cerr << "Error: Failed to allocate memory for output image!" << std::endl;
|
||||
return 0;
|
||||
}
|
||||
@@ -4843,19 +4975,27 @@ extern "C" __declspec(dllexport) int ANSCV_GetImageAndRemoveImgRef_S(cv::Mat** i
|
||||
(*outputImage)->cnt = size;
|
||||
memcpy((*outputImage)->str, jpegString.data(), size);
|
||||
|
||||
ANS_DBG("ANSCV_GetImageAndRemove", "SUCCESS out=%dx%d jpegBytes=%d (deleted mat=%p)",
|
||||
newWidth, newHeight, (int)size, matPtr);
|
||||
return 1; // Success
|
||||
}
|
||||
catch (const std::exception& e) {
|
||||
ANS_DBG("ANSCV_GetImageAndRemove", "ERROR exception mat=%p: %s", matPtr, e.what());
|
||||
std::cerr << "Exception in ANSCV_GetImageAndRemoveImgRef_S: " << e.what() << std::endl;
|
||||
}
|
||||
catch (...) {
|
||||
ANS_DBG("ANSCV_GetImageAndRemove", "ERROR unknown exception mat=%p", matPtr);
|
||||
std::cerr << "Unknown exception in ANSCV_GetImageAndRemoveImgRef_S!" << std::endl;
|
||||
}
|
||||
|
||||
// Cleanup in case of exception and still pending
|
||||
if (cleanupRequired) {
|
||||
ANS_DBG("ANSCV_GetImageAndRemove", "CLEANUP delete pending mat=%p",
|
||||
(imageIn ? (void*)*imageIn : nullptr));
|
||||
std::unique_lock<std::timed_mutex> lock(timeImageMutex, std::defer_lock);
|
||||
if (!lock.try_lock_for(std::chrono::milliseconds(MUTEX_TIMEOUT_MS))) {
|
||||
ANS_DBG("ANSCV_GetImageAndRemove", "ERROR cleanup mutex timeout mat=%p",
|
||||
(imageIn ? (void*)*imageIn : nullptr));
|
||||
std::cerr << "Error: Mutex timeout in ANSCV_ReSizeImage_S!" << std::endl;
|
||||
return -6;
|
||||
}
|
||||
@@ -4866,17 +5006,21 @@ extern "C" __declspec(dllexport) int ANSCV_GetImageAndRemoveImgRef_S(cv::Mat** i
|
||||
}
|
||||
|
||||
extern "C" __declspec(dllexport) int ANSCV_GetImageInfo_S(cv::Mat** imageIn, int& width, int& height) {
|
||||
void* matPtr = (imageIn ? (void*)*imageIn : nullptr);
|
||||
ANS_DBG("ANSCV_GetImageInfo", "ENTRY mat=%p", matPtr);
|
||||
try {
|
||||
cv::Mat imgCopy;
|
||||
{
|
||||
std::unique_lock<std::timed_mutex> lock(timeImageMutex, std::defer_lock);
|
||||
if (!lock.try_lock_for(std::chrono::milliseconds(MUTEX_TIMEOUT_MS))) {
|
||||
ANS_DBG("ANSCV_GetImageInfo", "ERROR mutex timeout mat=%p", matPtr);
|
||||
std::cerr << "Error: Mutex timeout in ANSCV_ReSizeImage_S!" << std::endl;
|
||||
return -6;
|
||||
}
|
||||
//std::lock_guard<std::mutex> lock(imageMutex);
|
||||
try {
|
||||
if (!imageIn || !(*imageIn) || (*imageIn)->empty() || !(*imageIn)->data) {
|
||||
ANS_DBG("ANSCV_GetImageInfo", "ERROR invalid input mat=%p", matPtr);
|
||||
std::cerr << "Error: Invalid or empty input image in ANSCV_CloneImage_S!" << std::endl;
|
||||
return -2;
|
||||
}
|
||||
@@ -4885,15 +5029,18 @@ extern "C" __declspec(dllexport) int ANSCV_GetImageInfo_S(cv::Mat** imageIn, int
|
||||
}
|
||||
}
|
||||
catch (const std::bad_alloc& e) {
|
||||
ANS_DBG("ANSCV_GetImageInfo", "ERROR bad_alloc mat=%p: %s", matPtr, e.what());
|
||||
std::cerr << "Memory allocation failed in ANSCV_CloneImage_S: " << e.what() << std::endl;
|
||||
return -1;
|
||||
}
|
||||
catch (const std::exception& e) {
|
||||
ANS_DBG("ANSCV_GetImageInfo", "ERROR exception inner mat=%p: %s", matPtr, e.what());
|
||||
std::cerr << "Error: Exception occurred in ANSCV_CloneImage_S: " << e.what() << std::endl;
|
||||
return -3;
|
||||
}
|
||||
}
|
||||
if (imgCopy.empty() || !imgCopy.data) {
|
||||
ANS_DBG("ANSCV_GetImageInfo", "ERROR imgCopy invalid mat=%p", matPtr);
|
||||
std::cerr << "Error: Dereferenced image is invalid in ANSCV_GetImageInfo_S!" << std::endl;
|
||||
return 0;
|
||||
}
|
||||
@@ -4901,13 +5048,16 @@ extern "C" __declspec(dllexport) int ANSCV_GetImageInfo_S(cv::Mat** imageIn, int
|
||||
// Assign the width and height once the image is validated
|
||||
width = imgCopy.cols;
|
||||
height = imgCopy.rows;
|
||||
ANS_DBG("ANSCV_GetImageInfo", "SUCCESS mat=%p %dx%d", matPtr, width, height);
|
||||
return 1; // Success
|
||||
}
|
||||
catch (const std::exception& e) {
|
||||
ANS_DBG("ANSCV_GetImageInfo", "ERROR exception outer mat=%p: %s", matPtr, e.what());
|
||||
std::cerr << "Exception in ANSCV_GetImageInfo_S: " << e.what() << std::endl;
|
||||
return -3;
|
||||
}
|
||||
catch (...) {
|
||||
ANS_DBG("ANSCV_GetImageInfo", "ERROR unknown exception mat=%p", matPtr);
|
||||
std::cerr << "Unknown exception in ANSCV_GetImageInfo_S!" << std::endl;
|
||||
return -4;
|
||||
}
|
||||
@@ -4917,8 +5067,12 @@ extern "C" __declspec(dllexport) int ANSCV_CreateImageFromJpegString_S(
|
||||
unsigned int bufferLength,
|
||||
cv::Mat** image)
|
||||
{
|
||||
ANS_DBG("ANSCV_CreateFromJpeg", "ENTRY buf=%p bytes=%u outPtr=%p",
|
||||
(void*)inputImage, bufferLength, (void*)image);
|
||||
// Validate input parameters
|
||||
if (!inputImage || bufferLength == 0 || image == nullptr) {
|
||||
ANS_DBG("ANSCV_CreateFromJpeg", "ERROR invalid params buf=%p bytes=%u outPtr=%p",
|
||||
(void*)inputImage, bufferLength, (void*)image);
|
||||
std::cerr << "Error: Invalid input parameters in ANSCV_CreateImageFromJpegString_S!" << std::endl;
|
||||
return -2;
|
||||
}
|
||||
@@ -4931,39 +5085,49 @@ extern "C" __declspec(dllexport) int ANSCV_CreateImageFromJpegString_S(
|
||||
{
|
||||
std::unique_lock<std::timed_mutex> lock(timeImageMutex, std::defer_lock);
|
||||
if (!lock.try_lock_for(std::chrono::milliseconds(MUTEX_TIMEOUT_MS))) {
|
||||
ANS_DBG("ANSCV_CreateFromJpeg", "ERROR mutex timeout bytes=%u", bufferLength);
|
||||
std::cerr << "Error: Mutex timeout in ANSCV_ReSizeImage_S!" << std::endl;
|
||||
return -6;
|
||||
}
|
||||
//std::lock_guard<std::mutex> lock(imageMutex);
|
||||
// Check if decoding was successful
|
||||
if (decodedImage.empty()) {
|
||||
ANS_DBG("ANSCV_CreateFromJpeg", "ERROR imdecode empty bytes=%u", bufferLength);
|
||||
std::cerr << "Error: Failed to decode JPEG image in ANSCV_CreateImageFromJpegString_S!" << std::endl;
|
||||
return 0;
|
||||
}
|
||||
else {
|
||||
*image = anscv_mat_new(decodedImage);
|
||||
ANS_DBG("ANSCV_CreateFromJpeg", "SUCCESS mat=%p %dx%d type=%d (jpeg=%u bytes)",
|
||||
(void*)*image, (*image)->cols, (*image)->rows, (*image)->type(), bufferLength);
|
||||
return 1; // Success
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
catch (const std::bad_alloc& e) {
|
||||
ANS_DBG("ANSCV_CreateFromJpeg", "ERROR bad_alloc bytes=%u: %s", bufferLength, e.what());
|
||||
std::cerr << "Memory allocation failed in ANSCV_CreateImageFromJpegString_S: " << e.what() << std::endl;
|
||||
return -1;
|
||||
}
|
||||
catch (const std::exception& e) {
|
||||
ANS_DBG("ANSCV_CreateFromJpeg", "ERROR exception bytes=%u: %s", bufferLength, e.what());
|
||||
std::cerr << "Exception in ANSCV_CreateImageFromJpegString_S: " << e.what() << std::endl;
|
||||
return -3;
|
||||
}
|
||||
catch (...) {
|
||||
ANS_DBG("ANSCV_CreateFromJpeg", "ERROR unknown exception bytes=%u", bufferLength);
|
||||
std::cerr << "Unknown exception in ANSCV_CreateImageFromJpegString_S!" << std::endl;
|
||||
return -4;
|
||||
}
|
||||
}
|
||||
extern "C" __declspec(dllexport) int ANSCV_CreateImageFromFile_S(const char* imageFilePath, cv::Mat** image)
|
||||
{
|
||||
ANS_DBG("ANSCV_CreateFromFile", "ENTRY path=%s outPtr=%p",
|
||||
imageFilePath ? imageFilePath : "(null)", (void*)image);
|
||||
try {
|
||||
if (!imageFilePath) {
|
||||
ANS_DBG("ANSCV_CreateFromFile", "ERROR null path");
|
||||
std::cerr << "Error: Null input parameter in ANSCV_CreateImageFromFile_S!" << std::endl;
|
||||
return -1; // Null pointer input
|
||||
}
|
||||
@@ -4971,6 +5135,7 @@ extern "C" __declspec(dllexport) int ANSCV_CreateImageFromFile_S(const char* ima
|
||||
std::string stImageFileName(imageFilePath);
|
||||
|
||||
if (stImageFileName.empty()) {
|
||||
ANS_DBG("ANSCV_CreateFromFile", "ERROR empty path");
|
||||
std::cerr << "Error: Empty file path in ANSCV_CreateImageFromFile_S!" << std::endl;
|
||||
return -2; // Empty path
|
||||
}
|
||||
@@ -4978,6 +5143,8 @@ extern "C" __declspec(dllexport) int ANSCV_CreateImageFromFile_S(const char* ima
|
||||
// Check if file exists
|
||||
std::ifstream fileCheck(stImageFileName);
|
||||
if (!fileCheck.good()) {
|
||||
ANS_DBG("ANSCV_CreateFromFile", "ERROR file missing/inaccessible path=%s",
|
||||
stImageFileName.c_str());
|
||||
std::cerr << "Error: File does not exist or is inaccessible: " << stImageFileName << std::endl;
|
||||
return -4; // File does not exist
|
||||
}
|
||||
@@ -4989,29 +5156,41 @@ extern "C" __declspec(dllexport) int ANSCV_CreateImageFromFile_S(const char* ima
|
||||
//std::lock_guard<std::mutex> lock(imageMutex); // Automatically locks and unlocks
|
||||
std::unique_lock<std::timed_mutex> lock(timeImageMutex, std::defer_lock);
|
||||
if (!lock.try_lock_for(std::chrono::milliseconds(MUTEX_TIMEOUT_MS))) {
|
||||
ANS_DBG("ANSCV_CreateFromFile", "ERROR mutex timeout path=%s",
|
||||
stImageFileName.c_str());
|
||||
std::cerr << "Error: Mutex timeout in ANSCV_ReSizeImage_S!" << std::endl;
|
||||
return -6;
|
||||
}
|
||||
if (loadedImage.empty()) {
|
||||
ANS_DBG("ANSCV_CreateFromFile", "ERROR imread empty path=%s",
|
||||
stImageFileName.c_str());
|
||||
std::cerr << "Error: Failed to load image from file in ANSCV_CreateImageFromFile_S!" << std::endl;
|
||||
return 0; // Load failed
|
||||
}
|
||||
else {
|
||||
if (image == nullptr) {
|
||||
ANS_DBG("ANSCV_CreateFromFile", "WARN outPtr was null - allocating internal pointer (caller will leak it)");
|
||||
image = new cv::Mat*; // Allocate pointer to cv::Mat*
|
||||
*image = nullptr; // Initialize to nullptr
|
||||
}
|
||||
*image = anscv_mat_new(loadedImage); // Use registry for safe lifecycle
|
||||
ANS_DBG("ANSCV_CreateFromFile", "SUCCESS path=%s mat=%p %dx%d type=%d",
|
||||
stImageFileName.c_str(), (void*)*image,
|
||||
(*image)->cols, (*image)->rows, (*image)->type());
|
||||
return 1; // Success
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
catch (const std::exception& e) {
|
||||
ANS_DBG("ANSCV_CreateFromFile", "ERROR exception path=%s: %s",
|
||||
imageFilePath ? imageFilePath : "(null)", e.what());
|
||||
std::cerr << "Error: Exception occurred in ANSCV_CreateImageFromFile_S: " << e.what() << std::endl;
|
||||
return -3; // Exception
|
||||
}
|
||||
catch (...) {
|
||||
ANS_DBG("ANSCV_CreateFromFile", "ERROR unknown exception path=%s",
|
||||
imageFilePath ? imageFilePath : "(null)");
|
||||
std::cerr << "Unknown error occurred in ANSCV_CreateImageFromFile_S!" << std::endl;
|
||||
return -5; // Unknown error
|
||||
}
|
||||
|
||||
@@ -1262,8 +1262,6 @@ namespace ANSCENTER {
|
||||
//}
|
||||
}
|
||||
|
||||
|
||||
|
||||
// Old method
|
||||
//std::tuple<std::vector<std::string>, std::vector<float>> ANSFaceRecognizer::SearchForFaces(std::vector<std::vector<float>> detectedEmbeddings) {
|
||||
// std::lock_guard<std::recursive_mutex> lock(_mutex);
|
||||
@@ -1538,8 +1536,6 @@ namespace ANSCENTER {
|
||||
}
|
||||
} */
|
||||
|
||||
|
||||
|
||||
// Before refactor (working version)
|
||||
/*std::vector<float> ANSFaceRecognizer::Feature(const cv::Mat& image,
|
||||
ANSCENTER::Object bBox) {
|
||||
@@ -2096,8 +2092,6 @@ namespace ANSCENTER {
|
||||
// }
|
||||
//}
|
||||
|
||||
|
||||
|
||||
// std::vector<std::vector<float>> ANSFaceRecognizer::Forward(const cv::Mat& input, std::vector<ANSCENTER::Object> outputBbox)
|
||||
// {
|
||||
// std::vector<std::vector<float>> detectedEmbeddings;
|
||||
|
||||
@@ -442,7 +442,6 @@ namespace ANSCENTER {
|
||||
float iouThreshold = 0.4;
|
||||
std::vector<Object> lprOutput = ANSUtilityHelper::ApplyNMS(lprOutputRaw, iouThreshold);
|
||||
|
||||
|
||||
if (!lprOutput.empty()) {
|
||||
if (!ppocr) {
|
||||
this->_logger.LogFatal("ANSALPR_CPU::Inference", "PPOCR instance is null", __FILE__, __LINE__);
|
||||
@@ -905,7 +904,6 @@ namespace ANSCENTER {
|
||||
// std::string numberCode = cleanOCRText.substr(7, 2);// 00 to 99
|
||||
// std::string newSuburbCode = convertStringToDigits(suburbCode);
|
||||
|
||||
|
||||
// // Convert the newSuburbCode to an integer
|
||||
// int numericValue = std::stoi(newSuburbCode);
|
||||
// // Check if it is within the range 11 to 99
|
||||
@@ -968,7 +966,6 @@ namespace ANSCENTER {
|
||||
// std::string numberCode = cleanOCRText.substr(7, 3);// 00 to 99
|
||||
// std::string newSuburbCode = convertStringToDigits(suburbCode);
|
||||
|
||||
|
||||
// // Convert the newSuburbCode to an integer
|
||||
// int numericValue = std::stoi(newSuburbCode);
|
||||
// // Check if it is within the range 11 to 99
|
||||
@@ -1262,7 +1259,6 @@ namespace ANSCENTER {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Align plate
|
||||
cv::Mat ANSALPR_CPU::alignPlateForOCR(const cv::Mat& fullImage, const cv::Rect& bbox) {
|
||||
try {
|
||||
|
||||
@@ -529,7 +529,6 @@ namespace ANSCENTER {
|
||||
_lpColourModelConfig.modelConfThreshold = 0.5;
|
||||
_lpColourModelConfig.modelMNSThreshold = 0.5;
|
||||
|
||||
|
||||
_lpdmodelConfig.inpHeight = 640;
|
||||
_lpdmodelConfig.inpWidth = 640;
|
||||
|
||||
@@ -560,7 +559,6 @@ namespace ANSCENTER {
|
||||
_lpColourModelConfig.optInputHeight = 224;
|
||||
_lpColourModelConfig.optInputWidth = 224;
|
||||
|
||||
|
||||
std::string lprModel = CreateFilePath(_modelFolder, "lpd.onnx");
|
||||
std::string lprClassesFile = CreateFilePath(_modelFolder, "lpd.names");
|
||||
|
||||
@@ -1346,7 +1344,6 @@ namespace ANSCENTER {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Check if this is actually a single row
|
||||
// If max gap is too small relative to character height, it's a single row
|
||||
std::vector<std::vector<Object>> rows;
|
||||
@@ -3068,7 +3065,6 @@ namespace ANSCENTER {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (maxGap < avgHeight * ROW_SPLIT_MIN_GAP_FACTOR) {
|
||||
// Single row - sort by projection along reading direction
|
||||
std::vector<std::pair<float, size_t>> allProj;
|
||||
@@ -3101,7 +3097,6 @@ namespace ANSCENTER {
|
||||
if (avgY0 > avgY1)
|
||||
std::swap(rowIndices[0], rowIndices[1]);
|
||||
|
||||
|
||||
// Sort each row by projection along reading direction
|
||||
std::string ocrText;
|
||||
ocrText.reserve(n);
|
||||
|
||||
@@ -4,7 +4,6 @@
|
||||
#include <omp.h>
|
||||
#include <include/paddleocr_utility.h>
|
||||
|
||||
|
||||
namespace ANSCENTER {
|
||||
|
||||
bool ANSCPUOCR::Initialize(const std::string& licenseKey, OCRModelConfig modelConfig,
|
||||
@@ -433,7 +432,6 @@ namespace ANSCENTER {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
std::vector<ANSCENTER::OCRObject> ANSCPUOCR::RunInference(const cv::Mat& input,
|
||||
const std::vector<cv::Rect>& Bbox,
|
||||
const std::string& cameraId)
|
||||
|
||||
@@ -108,8 +108,6 @@ namespace ANSCENTER {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
std::vector<ANSCENTER::OCRObject> ANSOCR::RunInference(const cv::Mat& input) {
|
||||
std::vector<ANSCENTER::OCRObject> OCRObjects;
|
||||
if (input.empty()) return OCRObjects;
|
||||
@@ -175,7 +173,6 @@ namespace ANSCENTER {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
std::vector<ANSCENTER::OCRObject> ANSOCR::RunInference(const cv::Mat& input, const std::vector<cv::Rect>& Bbox) {
|
||||
// No coarse _mutex — ppOCR->Predict() / engine has its own internal lock
|
||||
std::vector<ANSCENTER::OCRObject> OCRObjects;
|
||||
@@ -269,7 +266,6 @@ namespace ANSCENTER {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
std::vector<ANSCENTER::OCRObject> ANSOCR::RunInference(const cv::Mat& input, const std::vector<cv::Rect>& Bbox, const std::string& cameraId) {
|
||||
// No coarse _mutex — ppOCR->Predict() / engine has its own internal lock
|
||||
std::vector<ANSCENTER::OCRObject> OCRObjects;
|
||||
@@ -339,7 +335,6 @@ namespace ANSCENTER {
|
||||
ocrObject.box.width = rook_points[1].x - rook_points[0].x;
|
||||
ocrObject.box.height = rook_points[2].y - rook_points[1].y;
|
||||
|
||||
|
||||
ocrObject.classId = res_ocr.cls_labels[n];
|
||||
ocrObject.confidence = res_ocr.rec_scores[n];
|
||||
ocrObject.className = res_ocr.text[n];
|
||||
|
||||
@@ -71,7 +71,6 @@ namespace ANSCENTER {
|
||||
}
|
||||
_licenseValid = true;
|
||||
|
||||
|
||||
// 0. Check if the modelZipFilePath exist?
|
||||
if (!FileExist(modelZipFilePath)) {
|
||||
this->_logger.LogFatal("ANSOCRBase::Initialize", "Model zip file is not exist", __FILE__, __LINE__);
|
||||
@@ -124,7 +123,6 @@ namespace ANSCENTER {
|
||||
}
|
||||
_licenseValid = true;
|
||||
|
||||
|
||||
// 0. Check if the modelZipFilePath exist?
|
||||
if (!FileExist(modelZipFilePath)) {
|
||||
this->_logger.LogFatal("ANSOCRBase::Initialize", "Model zip file is not exist", __FILE__, __LINE__);
|
||||
@@ -347,7 +345,6 @@ namespace ANSCENTER {
|
||||
return polygon;
|
||||
}
|
||||
|
||||
|
||||
// ── ALPR Configuration Methods ──────────────────────────────────────
|
||||
|
||||
void ANSOCRBase::SetOCRMode(OCRMode mode) { _ocrMode = mode; }
|
||||
@@ -920,5 +917,3 @@ namespace ANSCENTER {
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -357,8 +357,6 @@ namespace ANSCENTER
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
//std::vector<Object> ANSCUSTOMDETECTOR::RunInference(const cv::Mat& input, const std::string& camera_id) {
|
||||
// std::lock_guard<std::recursive_mutex> lock(_mutex);
|
||||
// std::vector<Object> result;
|
||||
|
||||
@@ -532,7 +532,6 @@ if sys.stderr is None or not hasattr(sys.stderr, "write"):
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
std::vector<Object> ANSCUSTOMPY::RunInference(const cv::Mat& input) {
|
||||
return RunInference(input, "CustomPyCam");
|
||||
}
|
||||
@@ -754,4 +753,3 @@ if sys.stderr is None or not hasattr(sys.stderr, "write"):
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -26,6 +26,7 @@
|
||||
#define DEBUG_PRINT(x) std::cout << x << std::endl;
|
||||
//#define DEBUGENGINE
|
||||
//#define USE_TV_MODEL // Use model to detect if person is on TV screen or not
|
||||
|
||||
const int MAX_HISTORY_FACE = 5;
|
||||
const int MAX_MISSING_FACE = 30;
|
||||
const int MAX_TRACKS = 200;
|
||||
|
||||
@@ -424,7 +424,6 @@ namespace ANSCENTER
|
||||
return resizedImage;
|
||||
}
|
||||
|
||||
|
||||
ANSFDBase::~ANSFDBase() {
|
||||
try {
|
||||
Cleanup();
|
||||
|
||||
@@ -108,7 +108,6 @@ namespace ANSCENTER {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void ANSMOTIONDETECTOR::setMinObjectArea(const std::string& camera_id, double area)
|
||||
{
|
||||
std::lock_guard<std::recursive_mutex> lock(cameras_mutex);
|
||||
@@ -183,7 +182,6 @@ namespace ANSCENTER {
|
||||
return 0.0;
|
||||
}
|
||||
|
||||
|
||||
bool ANSMOTIONDETECTOR::isMovementDetected(const std::string& camera_id) const
|
||||
{
|
||||
std::lock_guard<std::recursive_mutex> lock(cameras_mutex);
|
||||
@@ -303,7 +301,6 @@ namespace ANSCENTER {
|
||||
return std::vector<std::vector<cv::Point>>();
|
||||
}
|
||||
|
||||
|
||||
ANSMOTIONDETECTOR::CameraStats ANSMOTIONDETECTOR::getStats(const std::string& camera_id) const
|
||||
{
|
||||
std::lock_guard<std::recursive_mutex> lock(cameras_mutex);
|
||||
@@ -557,7 +554,6 @@ namespace ANSCENTER {
|
||||
camera.psnr_threshold = base_threshold * camera.sensitivity_multiplier;
|
||||
}
|
||||
|
||||
|
||||
std::cout << "Base threshold: " << base_threshold
|
||||
<< ", Sensitivity: " << camera.sensitivity_multiplier
|
||||
<< ", Final threshold: " << camera.psnr_threshold << std::endl;
|
||||
@@ -920,7 +916,6 @@ namespace ANSCENTER {
|
||||
return MovementDetect(camera_id, camera.next_frame_index, next_image);
|
||||
}
|
||||
|
||||
|
||||
//std::vector<Object> ANSMOTIONDETECTOR::MovementDetect(const std::string& camera_id, const size_t frame_index, const cv::Mat& image)
|
||||
//{
|
||||
// std::lock_guard<std::recursive_mutex> lock(cameras_mutex);
|
||||
@@ -1336,7 +1331,6 @@ namespace ANSCENTER {
|
||||
// return outputObjects;
|
||||
// }
|
||||
|
||||
|
||||
// // Store original dimensions for scaling back
|
||||
// const int original_width = image.cols;
|
||||
// const int original_height = image.rows;
|
||||
|
||||
@@ -721,7 +721,6 @@ namespace ANSCENTER
|
||||
className = "ClassID_" + std::to_string(bestClassId);
|
||||
}
|
||||
|
||||
|
||||
Object detection;
|
||||
if (m_imgWidth > 20 && m_imgHeight > 20) {
|
||||
detection.box = cv::Rect(10, 10, m_imgWidth - 20, m_imgHeight - 20);
|
||||
|
||||
@@ -801,7 +801,6 @@ namespace ANSCENTER {
|
||||
DEBUG_PRINT("[Instance " << instanceId_ << "] Keypoints: " << numKeypoints
|
||||
<< " (derived=" << derivedKps << ", config=" << _modelConfig.numKPS << ")");
|
||||
|
||||
|
||||
const size_t expectedFeatures = 4 + 1 + numKeypoints * featuresPerKeypoint; // box(4) + conf(1) + kpts(17*3)
|
||||
|
||||
DEBUG_PRINT("[Instance " << instanceId_ << "] Output shape: ["
|
||||
@@ -1072,7 +1071,6 @@ namespace ANSCENTER {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
std::vector<Object> ANSONNXPOSE::detect(const cv::Mat& image, const std::string& camera_id) {
|
||||
std::lock_guard<std::recursive_mutex> lock(_mutex);
|
||||
|
||||
@@ -1245,7 +1243,6 @@ namespace ANSCENTER {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Public functions
|
||||
ANSONNXPOSE::~ANSONNXPOSE() {
|
||||
Destroy();
|
||||
|
||||
@@ -549,7 +549,6 @@ namespace ANSCENTER {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
cv::Mat ANSONNXSEG::preprocess(const cv::Mat& image, float*& blobPtr, std::vector<int64_t>& inputTensorShape) {
|
||||
std::lock_guard<std::recursive_mutex> lock(_mutex);
|
||||
m_imgWidth = image.cols;
|
||||
@@ -988,7 +987,6 @@ namespace ANSCENTER {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
std::vector<Object> ANSONNXSEG::segment(const cv::Mat& image, const std::string& camera_id) {
|
||||
std::lock_guard<std::recursive_mutex> lock(_mutex);
|
||||
|
||||
@@ -1136,7 +1134,6 @@ namespace ANSCENTER {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Public functions
|
||||
ANSONNXSEG::~ANSONNXSEG() {
|
||||
Destroy();
|
||||
|
||||
@@ -98,7 +98,6 @@ namespace ANSCENTER {
|
||||
const bool isClassification = !output_node_dims.empty()
|
||||
&& output_node_dims[0].size() == 2;
|
||||
|
||||
|
||||
cv::Mat canvas;
|
||||
if (isClassification) {
|
||||
// Classification: direct resize (no letterbox padding) — matches ANSONNXCL
|
||||
@@ -1326,7 +1325,6 @@ namespace ANSCENTER {
|
||||
const bool alreadyNormalized = (rawSum > 0.9f && rawSum < 1.1f
|
||||
&& raw[0] >= 0.f); // probabilities are non-negative
|
||||
|
||||
|
||||
std::vector<float> probs(nc);
|
||||
if (alreadyNormalized) {
|
||||
// Output is already softmax — use as-is (skip double softmax)
|
||||
|
||||
@@ -420,7 +420,6 @@ namespace ANSCENTER
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//std::vector<Object> OPENVINOCL::RunInference(const cv::Mat& input, const std::string& camera_id) {
|
||||
// std::lock_guard<std::recursive_mutex> lock(_mutex);
|
||||
// std::vector<Object> outputs;
|
||||
|
||||
@@ -642,7 +642,6 @@ namespace ANSCENTER {
|
||||
|
||||
}
|
||||
|
||||
|
||||
// Only work for Yolov8 for now, extract polygons does not work as expected
|
||||
//std::vector<Object> ANSOVSEG::RunInference(const cv::Mat& input, const std::string& camera_id) {
|
||||
// std::lock_guard<std::recursive_mutex> lock(_mutex);
|
||||
|
||||
@@ -136,7 +136,6 @@ namespace ANSCENTER {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
bool ANSPOSE::Initialize(std::string licenseKey, ModelConfig modelConfig, const std::string& modelZipFilePath, const std::string& modelZipPassword, std::string& labelMap) {
|
||||
std::lock_guard<std::recursive_mutex> lock(_mutex);
|
||||
ModelLoadingGuard mlg(_modelLoading);
|
||||
@@ -393,8 +392,6 @@ namespace ANSCENTER {
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
// std::vector<Object> ANSPOSE::RunInference(const cv::Mat& input, const std::string& camera_id) {
|
||||
// std::lock_guard<std::recursive_mutex> lock(_mutex);
|
||||
// std::vector<Object> output;
|
||||
@@ -443,7 +440,6 @@ namespace ANSCENTER {
|
||||
// _poseEstimationPipeline->waitForTotalCompletion();
|
||||
// std::unique_ptr<ResultBase> result = _poseEstimationPipeline->getResult();
|
||||
|
||||
|
||||
// /* static const std::pair<int, int> keypointsOP[] = {
|
||||
// {1, 2},
|
||||
// {1, 5},
|
||||
|
||||
@@ -311,7 +311,6 @@ namespace ANSCENTER {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
void ANSSAM::ScaleBoxes(cv::Mat& box, const cv::Size& oriSize)
|
||||
@@ -425,7 +424,6 @@ namespace ANSCENTER {
|
||||
return binaryMask;
|
||||
}
|
||||
|
||||
|
||||
std::string ANSSAM::MaskToPolygons(const cv::Mat& image, cv::Rect& boundingBox, std::vector<cv::Point2f>& polygon) {
|
||||
try {
|
||||
// image is boxMask: CV_32FC1 with 0.0 / 1.0 → directly convert
|
||||
@@ -527,7 +525,6 @@ namespace ANSCENTER {
|
||||
return BuildTensor();
|
||||
}
|
||||
|
||||
|
||||
cv::Mat ANSSAM::BuildOutput0()
|
||||
{
|
||||
auto* ptr = m_request.get_output_tensor(0).data();
|
||||
|
||||
@@ -616,7 +616,6 @@ namespace ANSCENTER
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
// =========================================================================
|
||||
// EnsureEnginesBuilt — pre-build uncached engines one at a time
|
||||
// Avoids GPU OOM when building one engine while others are already loaded.
|
||||
|
||||
@@ -100,7 +100,6 @@ namespace ANSCENTER
|
||||
m_options.minInputWidth = _modelConfig.minInputWidth;
|
||||
m_options.optInputWidth = _modelConfig.optInputWidth;
|
||||
|
||||
|
||||
m_options.engineFileDir = _modelFolder;
|
||||
// Use FP16 or FP32 precision based on the input flag
|
||||
m_options.precision = (_fp16 ? Precision::FP16 : Precision::FP32);
|
||||
@@ -588,7 +587,6 @@ namespace ANSCENTER
|
||||
clsResult.className = "Unknown"; // Fallback if _classes is empty
|
||||
}
|
||||
|
||||
|
||||
clsResult.confidence = score;
|
||||
if (meta.imgWidth > 20 && meta.imgHeight > 20) {
|
||||
clsResult.box = cv::Rect(10, 10, meta.imgWidth - 20, meta.imgHeight - 20);
|
||||
|
||||
@@ -969,7 +969,6 @@ namespace ANSCENTER
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*std::vector<Object> ANSTENSORRTPOSE::RunInference(const cv::Mat& inputImgBGR, const std::string& camera_id) {
|
||||
std::lock_guard<std::recursive_mutex> lock(_mutex);
|
||||
if (!_modelLoadValid) {
|
||||
|
||||
@@ -1128,7 +1128,6 @@ namespace ANSCENTER
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*std::vector<Object> TENSORRTSEG::RunInference(const cv::Mat& inputImgBGR, const std::string& camera_id) {
|
||||
std::lock_guard<std::recursive_mutex> lock(_mutex);
|
||||
if (!_modelLoadValid) {
|
||||
|
||||
@@ -4,7 +4,6 @@
|
||||
#ifdef USEONNXOV
|
||||
#endif
|
||||
|
||||
|
||||
namespace ANSCENTER {
|
||||
bool YOLO12OD::OptimizeModel(bool fp16, std::string& optimizedModelFolder) {
|
||||
std::lock_guard<std::recursive_mutex> lock(_mutex);
|
||||
@@ -474,7 +473,6 @@ namespace ANSCENTER {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
cv::Mat YOLO12OD::preprocess(const cv::Mat& image, std::vector<float>& blob, std::vector<int64_t>& inputTensorShape) {
|
||||
std::lock_guard<std::recursive_mutex> lock(_mutex);
|
||||
m_imgWidth = image.cols;
|
||||
|
||||
@@ -1850,6 +1850,5 @@ namespace ANSCENTER
|
||||
this->_logger.LogFatal("YOLOOD::LoadDarknetNetwork()", e.what(), __FILE__, __LINE__);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -794,7 +794,6 @@ namespace ANSCENTER
|
||||
return allObjects;
|
||||
}
|
||||
|
||||
|
||||
std::vector<Object> ANSOYOLOV10OVOD::DetectObjectsBatch(const std::vector<cv::Mat>& inputImages,
|
||||
const std::string& camera_id) {
|
||||
std::lock_guard<std::recursive_mutex> lock(_mutex);
|
||||
|
||||
@@ -239,7 +239,6 @@ namespace ANSCENTER
|
||||
if (!_classes.empty())
|
||||
labelMap = VectorToCommaSeparatedString(_classes);
|
||||
|
||||
|
||||
// 2. Load the TensorRT engine file
|
||||
if (this->_loadEngineOnCreation) {
|
||||
auto succ = m_trtEngine->buildLoadNetwork(_modelFilePath, SUB_VALS, DIV_VALS, NORMALIZE, m_maxSlotsPerGpu);
|
||||
@@ -339,7 +338,6 @@ namespace ANSCENTER
|
||||
if (!_classes.empty())
|
||||
labelMap = VectorToCommaSeparatedString(_classes);
|
||||
|
||||
|
||||
// 2. Load the TensorRT engine file
|
||||
if (this->_loadEngineOnCreation && !engineAlreadyLoaded) {
|
||||
auto succ = m_trtEngine->buildLoadNetwork(_modelFilePath, SUB_VALS, DIV_VALS, NORMALIZE, m_maxSlotsPerGpu);
|
||||
@@ -744,7 +742,6 @@ namespace ANSCENTER
|
||||
roi = cv::Rect(0, 0, _modelConfig.inpWidth, _modelConfig.inpHeight * meta.imgHeight / meta.imgWidth);
|
||||
}
|
||||
|
||||
|
||||
for (size_t i = 0; i < indices.size(); i++)
|
||||
{
|
||||
cv::Mat dest, mask;
|
||||
@@ -862,7 +859,6 @@ namespace ANSCENTER
|
||||
return objects;
|
||||
}
|
||||
|
||||
|
||||
std::vector<std::vector<Object>> ANSYOLOV10RTOD::DetectObjectsBatch(
|
||||
const std::vector<cv::Mat>& inputImages, const std::string& camera_id)
|
||||
{
|
||||
|
||||
@@ -252,7 +252,6 @@ namespace ANSCENTER {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
ANSRETINAFD::~ANSRETINAFD() {
|
||||
try {
|
||||
// if (_faceDectector) {
|
||||
|
||||
@@ -410,8 +410,6 @@ namespace ANSCENTER {
|
||||
return output;
|
||||
}
|
||||
|
||||
|
||||
|
||||
std::vector<Object> ANSSCRFDFD::InferenceDynamic(const cv::Mat& input, const std::string& camera_id) {
|
||||
if (_modelLoading.load()) return {};
|
||||
auto lock = TryLockWithTimeout("ANSSCRFDFD::InferenceDynamic");
|
||||
@@ -575,7 +573,6 @@ namespace ANSCENTER {
|
||||
return output;
|
||||
}
|
||||
|
||||
|
||||
std::vector<Object> ANSSCRFDFD::Detect(const cv::Mat& input)
|
||||
{
|
||||
// Phase 1: Validation + engine dims (brief lock)
|
||||
|
||||
@@ -37,7 +37,6 @@ namespace ANSCENTER {
|
||||
<< model->input().get_any_name() << "' will be used." << slog::endl;
|
||||
}
|
||||
|
||||
|
||||
const ov::Layout& inputLayout = layout;
|
||||
|
||||
//ppp.input().tensor().set_element_type(ov::element::u8).set_layout("NHWC").set_color_format(ov::preprocess::ColorFormat::BGR);
|
||||
@@ -61,7 +60,6 @@ namespace ANSCENTER {
|
||||
int outputSize = model->outputs().size();
|
||||
std::cout << "output Size:" << outputSize << std::endl;
|
||||
|
||||
|
||||
const ov::Layout outputLayout{ "CHW" };
|
||||
maxProposalsCount = model->outputs().front().get_shape()[ov::layout::height_idx(outputLayout)];
|
||||
for (const auto& output : model->outputs()) {
|
||||
@@ -239,7 +237,6 @@ namespace ANSCENTER {
|
||||
// Perform inference
|
||||
inference_request_.infer();
|
||||
|
||||
|
||||
std::cout << "Model outputs:" << std::endl;
|
||||
auto ovOutputs= compiled_model_.outputs();
|
||||
for (int i = 0; i < ovOutputs.size();i++) {
|
||||
@@ -270,7 +267,6 @@ namespace ANSCENTER {
|
||||
|
||||
std::cout << "Total valid detections: " << valid_detections.size() << std::endl;
|
||||
|
||||
|
||||
/* float* score = inference_request_.get_output_tensor(2).data<float>();
|
||||
//if (score != nullptr) {
|
||||
// std::cout << "Score:" << score[0]<<std::endl;
|
||||
@@ -278,7 +274,6 @@ namespace ANSCENTER {
|
||||
float* bbox = inference_request_.get_output_tensor(5).data<float>();*/
|
||||
// Get the output tensor
|
||||
|
||||
|
||||
//// Step 0: Prepare input
|
||||
//this->PreprocessImage(im);
|
||||
|
||||
|
||||
@@ -62,6 +62,111 @@ namespace ANSCENTER
|
||||
return oss.str();
|
||||
}
|
||||
|
||||
// ────────────────────────────────────────────────────────────────────────
|
||||
// SummarizeChilkatError: turn Chilkat's verbose multi-line lastErrorText()
|
||||
// into a single diagnostic line suitable for _logger.LogError().
|
||||
//
|
||||
// Chilkat's log looks like:
|
||||
// ChilkatLog: Connect: DllDate: ... ChilkatVersion: ... UnlockStatus: ...
|
||||
// restConnect: domain_or_ip: s3.us-east-1.amazonaws.com
|
||||
// socket2Connect: connect2: connectImplicitSsl: connectSocket_v2:
|
||||
// connect_domain: ckDnsResolveDomainIPv4_n: ...
|
||||
// clientHandshake2: readHandshakeMessages:
|
||||
// Failed to read beginning of SSL/TLS record.
|
||||
// readTlsRecord: Socket operation timeout.
|
||||
// See https://cknotes.com/...
|
||||
// ConnectFailReason: 103
|
||||
// Failed.
|
||||
//
|
||||
// Diagnostics we care about:
|
||||
// • the deepest concrete failure reason (the non-label leaf line)
|
||||
// • ConnectFailReason: <N> if present
|
||||
// • the target (domain_or_ip / ip_or_domain + port)
|
||||
// Rest (DllDate, ChilkatVersion, Architecture, VerboseLogging, ...) is noise.
|
||||
//
|
||||
// Returns e.g.:
|
||||
// "Connect failed [reason=103] s3.us-east-1.amazonaws.com:443 — Socket operation timeout (TLS handshake). See https://cknotes.com/failed-to-read-beginning-of-ssl-tls-record-..."
|
||||
// ────────────────────────────────────────────────────────────────────────
|
||||
static std::string SummarizeChilkatError(const char* raw) {
|
||||
if (!raw || !*raw) return "(empty Chilkat log)";
|
||||
std::string s(raw);
|
||||
// Split into trimmed lines.
|
||||
std::vector<std::string> lines;
|
||||
{
|
||||
std::istringstream iss(s);
|
||||
std::string ln;
|
||||
while (std::getline(iss, ln)) {
|
||||
// Trim leading whitespace (Chilkat indents by level).
|
||||
size_t a = ln.find_first_not_of(" \t\r\n");
|
||||
if (a == std::string::npos) continue;
|
||||
size_t b = ln.find_last_not_of(" \t\r\n");
|
||||
lines.push_back(ln.substr(a, b - a + 1));
|
||||
}
|
||||
}
|
||||
if (lines.empty()) return "(empty Chilkat log)";
|
||||
|
||||
// Lines that are pure labels ("foo:" or "--foo") are scaffolding.
|
||||
auto isLabelLine = [](const std::string& ln) {
|
||||
if (ln.empty()) return true;
|
||||
if (ln.rfind("--", 0) == 0) return true; // "--foo" close-marker
|
||||
// "label: value" — keep only if value is non-empty and line doesn't
|
||||
// look like pure call-stack breadcrumb (trailing ':').
|
||||
if (!ln.empty() && ln.back() == ':') return true;
|
||||
return false;
|
||||
};
|
||||
|
||||
// Fields we want to extract.
|
||||
std::string target, failReason, tlsHint, leafError, seeUrl;
|
||||
|
||||
for (auto& ln : lines) {
|
||||
if (ln.rfind("domain_or_ip:", 0) == 0 || ln.rfind("ip_or_domain:", 0) == 0) {
|
||||
auto p = ln.find(':');
|
||||
if (p != std::string::npos) target = ln.substr(p + 1);
|
||||
} else if (ln.rfind("ConnectFailReason:", 0) == 0) {
|
||||
auto p = ln.find(':');
|
||||
if (p != std::string::npos) failReason = ln.substr(p + 1);
|
||||
} else if (ln.rfind("port:", 0) == 0) {
|
||||
auto p = ln.find(':');
|
||||
if (p != std::string::npos) {
|
||||
// Append port to target if we have one.
|
||||
std::string port = ln.substr(p + 1);
|
||||
// Trim leading space.
|
||||
size_t a = port.find_first_not_of(" \t");
|
||||
if (a != std::string::npos) port = port.substr(a);
|
||||
if (!target.empty()) target += ":" + port;
|
||||
}
|
||||
} else if (ln.rfind("See http", 0) == 0 || ln.rfind("See https", 0) == 0) {
|
||||
seeUrl = ln.substr(4); // drop "See "
|
||||
} else if (ln.rfind("Failed to read beginning of SSL/TLS record", 0) == 0) {
|
||||
tlsHint = "TLS handshake — server sent nothing (firewall/AV TLS inspection, proxy, or packet loss)";
|
||||
} else if (!isLabelLine(ln)) {
|
||||
// Candidate concrete message. Keep the LATEST one that's not a
|
||||
// stack label; Chilkat's deepest concrete error is usually the
|
||||
// most specific explanation.
|
||||
leafError = ln;
|
||||
}
|
||||
}
|
||||
|
||||
// Trim leading space on captured fields.
|
||||
auto trim = [](std::string& v) {
|
||||
size_t a = v.find_first_not_of(" \t");
|
||||
if (a == std::string::npos) { v.clear(); return; }
|
||||
size_t b = v.find_last_not_of(" \t");
|
||||
v = v.substr(a, b - a + 1);
|
||||
};
|
||||
trim(target); trim(failReason); trim(leafError); trim(seeUrl);
|
||||
|
||||
// Compose.
|
||||
std::ostringstream out;
|
||||
out << "Chilkat Connect failed";
|
||||
if (!failReason.empty()) out << " [reason=" << failReason << "]";
|
||||
if (!target.empty()) out << " " << target;
|
||||
if (!leafError.empty()) out << " — " << leafError;
|
||||
if (!tlsHint.empty()) out << " (" << tlsHint << ")";
|
||||
if (!seeUrl.empty()) out << " (" << seeUrl << ")";
|
||||
return out.str();
|
||||
}
|
||||
|
||||
// Private helper function to extract file name from a path
|
||||
// Helper function to extract filename from path
|
||||
std::string ANSAWSS3::ExtractFileName(const std::string& filePath) {
|
||||
@@ -249,7 +354,9 @@ namespace ANSCENTER
|
||||
|
||||
// Connect
|
||||
if (!conn->rest.Connect(_fullAWSURL.c_str(), _port, _bTls, _bAutoReconnect)) {
|
||||
_logger.LogError("ANSAWSS3::CreateConnection", conn->rest.lastErrorText(), __FILE__, __LINE__);
|
||||
const std::string summary = SummarizeChilkatError(conn->rest.lastErrorText());
|
||||
_logger.LogError("ANSAWSS3::CreateConnection", summary, __FILE__, __LINE__);
|
||||
ANS_DBG("AWSS3", "Connect failed: %s", summary.c_str());
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
@@ -261,7 +368,9 @@ namespace ANSCENTER
|
||||
conn->socket.put_HttpProxyPassword(_proxyPassword.c_str());
|
||||
conn->socket.put_HttpProxyForHttp(_bProxy);
|
||||
if (!conn->rest.UseConnection(conn->socket, true)) {
|
||||
_logger.LogError("ANSAWSS3::CreateConnection - Proxy error", conn->rest.lastErrorText(), __FILE__, __LINE__);
|
||||
const std::string summary = SummarizeChilkatError(conn->rest.lastErrorText());
|
||||
_logger.LogError("ANSAWSS3::CreateConnection - Proxy error", summary, __FILE__, __LINE__);
|
||||
ANS_DBG("AWSS3", "Proxy error: %s", summary.c_str());
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
@@ -275,7 +384,9 @@ namespace ANSCENTER
|
||||
if (!_bucketRegion.empty()) conn->authAws.put_Region(_bucketRegion.c_str());
|
||||
}
|
||||
if (!conn->rest.SetAuthAws(conn->authAws)) {
|
||||
_logger.LogError("ANSAWSS3::CreateConnection - Auth error", conn->rest.lastErrorText(), __FILE__, __LINE__);
|
||||
const std::string summary = SummarizeChilkatError(conn->rest.lastErrorText());
|
||||
_logger.LogError("ANSAWSS3::CreateConnection - Auth error", summary, __FILE__, __LINE__);
|
||||
ANS_DBG("AWSS3", "Auth error: %s", summary.c_str());
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -318,11 +318,11 @@ int TestValidateExample() {
|
||||
|
||||
int main()
|
||||
{
|
||||
TestValidateExample();
|
||||
//TestValidateExample();
|
||||
//std::cout << "_MSC_VER: " << _MSC_VER << std::endl;
|
||||
//std::cout << "Start tesing..." << std::endl;
|
||||
//RemoveTrialLicenseKey();
|
||||
//getSystemInformation();
|
||||
getSystemInformation();
|
||||
//ValidateExample();
|
||||
//GenerateOfflineActivationData();
|
||||
//TestLocalTemplate();
|
||||
|
||||
Reference in New Issue
Block a user