Prevent OOM

This commit is contained in:
2026-06-18 05:55:31 +10:00
parent ebba70b9d9
commit b3436a61ee
44 changed files with 1797 additions and 66 deletions
+84 -3
View File
@@ -1631,6 +1631,88 @@ int TestCompleteFR1() {
std::cout << "End of program.\n";
return 1;
}
// ---- SCRFD-TRT face-detection reproduction on a video (headless) ----------
int SCRFDVideoRepro()
{
std::string licenseKey = "";
const char* configFilePath = "";
std::string databaseFilePath = "C:\\ProgramData\\ANSCENTER\\ANSVIS Server\\ANSFR\\ANSFR.db";
std::string recognizerFile = "C:\\ProgramData\\ANSCENTER\\ANSVIS Server\\ANSFR\\ServerOptimised\\ANS_FaceRecognizer_v1.1_NVIDIAGeForceRTX3070LaptopGPU.zip";
std::string detectorFile = "C:\\ProgramData\\ANSCENTER\\ANSVIS Server\\ANSFDET\\ServerOptimised\\ANS_GenericFD(GPU)_v1.0_NVIDIAGeForceRTX3070LaptopGPU.zip";
std::string videoPath = "C:\\Programs\\DemoAssets\\Videos\\classroom.mp4";
std::cout << "[REPRO] detector = " << detectorFile << std::endl;
std::cout << "[REPRO] recognizer = " << recognizerFile << std::endl;
ANSCENTER::ANSFacialRecognition* h = nullptr;
int cr = CreateANSRFHandle(&h, licenseKey.c_str(), configFilePath,
databaseFilePath.c_str(), recognizerFile.c_str(),
detectorFile.c_str(), 0.3, 1, 1, 1);
std::cout << "[REPRO] CreateANSRFHandle = " << cr << std::endl;
int le = LoadANSRFEngine(&h);
std::cout << "[REPRO] LoadANSRFEngine = " << le << std::endl;
cv::VideoCapture cap(videoPath);
if (!cap.isOpened()) { std::cout << "[REPRO] ERROR: cannot open video " << videoPath << std::endl; return 1; }
const std::string win = "ANSFR - SCRFD/TensorRT Face Detection (ESC to quit)";
cv::namedWindow(win, cv::WINDOW_NORMAL);
cv::resizeWindow(win, 1280, 720);
int frameIdx = 0, totalDet = 0, saved = 0;
cv::Mat frame;
while (cap.read(frame)) {
if (frame.empty()) break;
++frameIdx;
if (frameIdx > 300) break; // proof run: first 300 frames
unsigned int bufLen = 0;
unsigned char* jpg = ANSCENTER::ANSFRHelper::CVMatToBytes(frame, bufLen);
std::string res = RunANSRFInferenceBinary(&h, jpg, frame.cols, frame.rows);
delete jpg;
int n = 0;
try {
boost::property_tree::ptree pt; std::stringstream ss; ss << res;
boost::property_tree::read_json(ss, pt);
if (pt.count("results")) {
BOOST_FOREACH(const boost::property_tree::ptree::value_type& child, pt.get_child("results")) {
const boost::property_tree::ptree& r = child.second;
const int uid = GetData<int>(r, "user_id");
const std::string uname = GetData<std::string>(r, "user_name");
const float x = GetData<float>(r, "x");
const float y = GetData<float>(r, "y");
const float w = GetData<float>(r, "width");
const float ht = GetData<float>(r, "height");
cv::rectangle(frame, cv::Rect((int)x, (int)y, (int)w, (int)ht), cv::Scalar(0, 255, 0), 2);
cv::putText(frame, cv::format("%s:%d", uname.c_str(), uid), cv::Point((int)x, (int)y - 8),
cv::FONT_HERSHEY_SIMPLEX, 0.7, cv::Scalar(0, 0, 255), 2, cv::LINE_AA);
++n;
}
}
} catch (...) {}
totalDet += n;
cv::putText(frame, cv::format("Frame %d faces detected = %d", frameIdx, n),
cv::Point(25, 45), cv::FONT_HERSHEY_SIMPLEX, 1.1, cv::Scalar(0, 255, 255), 2, cv::LINE_AA);
if (frameIdx % 30 == 0) {
std::string fp = cv::format("C:\\Programs\\DemoAssets\\ANSFR_proof_frame_%04d_faces%d.jpg", frameIdx, n);
cv::imwrite(fp, frame);
++saved;
std::cout << "[REPRO] saved annotated frame: " << fp << std::endl;
}
cv::imshow(win, frame);
if (cv::waitKey(1) == 27) break; // ESC to quit
}
std::cout << "[REPRO] played " << frameIdx << " frames, total faces drawn = " << totalDet
<< ", saved " << saved << " annotated images to C:\\Programs\\DemoAssets\\" << std::endl;
cap.release();
cv::destroyAllWindows();
// NOTE: intentionally skipping ReleaseANSRFHandle/cudaDeviceReset here — there is
// a known C++ exception at teardown (0xE06D7363); process exit reclaims everything.
return 0;
}
int main()
{
@@ -1653,8 +1735,7 @@ int main()
// TestCompleteFR();
//TestFaceRecognition();
//FaceRecognitionBenchmark();
ANSVISTestCPU_Lightweight();
//ANSVISTestCPU();
std::cin.get();
SCRFDVideoRepro();
return 0;
}