#include "ANSODTest.h" int GPUYolov10EngineUnitTest(std::string modelFilePath, std::string videoFilePath) { boost::property_tree::ptree root; boost::property_tree::ptree detectionObjects; boost::property_tree::ptree pt; std::vector classes; std::filesystem::path currentPath = std::filesystem::current_path(); ANSCENTER::ANSODBase* infHandle; std::string labelMap; std::string licenseKey = ""; std::string modelZipFilePassword = ""; float modelThreshold = 0.5; float modelConfThreshold = 0.5; float modelNMSThreshold = 0.5; int modelType = 14;//TENSORRT V10 int detectorType = 1; std::string optmizedModelFolder; // Optimise model std::cout << "Optimizing model, please wait...." << std::endl; OptimizeModelStr(modelFilePath.c_str(), modelZipFilePassword.c_str(), modelType, 1,1, optmizedModelFolder); std::cout << "Model is optmized, run inference...." << std::endl; labelMap = CreateANSODHandle(&infHandle, licenseKey.c_str(), modelFilePath.c_str(), modelZipFilePassword.c_str(), modelThreshold, modelConfThreshold, modelNMSThreshold, 1, modelType, detectorType); std::stringstream ss(labelMap); while (ss.good()) { std::string substr; getline(ss, substr, ','); classes.push_back(substr); } std::cout << "classes:" << classes.size(); std::cout << "begin read video" << std::endl; cv::VideoCapture capture(videoFilePath); if (!capture.isOpened()) { printf("could not read this video file...\n"); return -1; } std::cout << "end read video" << std::endl; while (true) { cv::Mat frame; if (!capture.read(frame)) // if not success, break loop { std::cout << "\n Cannot read the video file. please check your video.\n"; break; } unsigned int bufferLength = 0; unsigned char* jpeg_string = ANSCENTER::ANSUtilityHelper::CVMatToBytes(frame, bufferLength); int height = frame.rows; int width = frame.cols; auto start = std::chrono::system_clock::now(); /* measured work */ std::string detectionResult = RunInferenceBinary(&infHandle, jpeg_string, width, height); auto end = std::chrono::system_clock::now(); auto elapsed = std::chrono::duration_cast(end - start); printf("Time = %lld ms\n", static_cast(elapsed.count())); delete jpeg_string; if (!detectionResult.empty()) { pt.clear(); std::stringstream ss; ss.clear(); ss << detectionResult; boost::property_tree::read_json(ss, pt); BOOST_FOREACH(const boost::property_tree::ptree::value_type & child, pt.get_child("results")) { const boost::property_tree::ptree& result = child.second; const auto class_id = GetData(result, "class_id"); const auto x = GetData(result, "x"); const auto y = GetData(result, "y"); const auto width = GetData(result, "width"); const auto height = GetData(result, "height"); cv::rectangle(frame, cv::Rect(x, y, width, height), 123, 2); cv::putText(frame, cv::format("%s:%d", classes[class_id], class_id), cv::Point(x, y - 5), 0, 0.6, cv::Scalar(0, 0, 255), 1, cv::LINE_AA); } } cv::imshow("ANS Object Tracking", frame); if (cv::waitKey(30) == 27) // Wait for 'esc' key press to exit { break; } } capture.release(); cv::destroyAllWindows(); ReleaseANSODHandle(&infHandle); std::cout << "End of program.\n"; return 0; } int OpenVINOYolov10EngineUnitTest(std::string modelFilePath, std::string videoFilePath) { boost::property_tree::ptree root; boost::property_tree::ptree detectionObjects; boost::property_tree::ptree pt; std::vector classes; std::filesystem::path currentPath = std::filesystem::current_path(); ANSCENTER::ANSODBase* infHandle; std::string labelMap; std::string licenseKey = ""; std::string modelZipFilePassword = ""; float detectionScoreThreshold = 0.48; float modelConfThreshold = 0.48; float modelNMSThreshold = 0.48; int modelType = 15;//OPENVINO int detectorType = 1; // Detection labelMap = CreateANSODHandle(&infHandle, licenseKey.c_str(), modelFilePath.c_str(), modelZipFilePassword.c_str(), detectionScoreThreshold, modelConfThreshold, modelNMSThreshold, 1, modelType, detectorType); std::stringstream ss(labelMap); while (ss.good()) { std::string substr; getline(ss, substr, ','); classes.push_back(substr); } std::cout << "classes:" << classes.size(); std::cout << "begin read video" << std::endl; cv::VideoCapture capture(videoFilePath); if (!capture.isOpened()) { printf("could not read this video file...\n"); return -1; } std::cout << "end read video" << std::endl; while (true) { cv::Mat frame; if (!capture.read(frame)) // if not success, break loop { std::cout << "\n Cannot read the video file. please check your video.\n"; break; } unsigned int bufferLength = 0; unsigned char* jpeg_string = ANSCENTER::ANSUtilityHelper::CVMatToBytes(frame, bufferLength); int height = frame.rows; int width = frame.cols; auto start = std::chrono::system_clock::now(); /* measured work */ std::string detectionResult = RunInferenceBinary(&infHandle, jpeg_string, width, height); auto end = std::chrono::system_clock::now(); auto elapsed = std::chrono::duration_cast(end - start); printf("Time = %lld ms\n", static_cast(elapsed.count())); delete jpeg_string; if (!detectionResult.empty()) { pt.clear(); std::stringstream ss; ss.clear(); ss << detectionResult; boost::property_tree::read_json(ss, pt); BOOST_FOREACH(const boost::property_tree::ptree::value_type & child, pt.get_child("results")) { const boost::property_tree::ptree& result = child.second; const auto class_id = GetData(result, "class_id"); const auto x = GetData(result, "x"); const auto y = GetData(result, "y"); const auto prob = GetData(result, "prob"); const auto width = GetData(result, "width"); const auto height = GetData(result, "height"); cv::rectangle(frame, cv::Rect(x, y, width, height), 123, 2); cv::putText(frame, cv::format("%s:%d:%.2f", classes[class_id], class_id, prob), cv::Point(x, y - 5), 0, 0.6, cv::Scalar(0, 0, 255), 1, cv::LINE_AA); } } cv::imshow("ANS Object Tracking", frame); if (cv::waitKey(30) == 27) // Wait for 'esc' key press to exit { break; } } capture.release(); cv::destroyAllWindows(); ReleaseANSODHandle(&infHandle); std::cout << "End of program.\n"; return 0; } int OpenVINOYolov10EngineUnitTestLoop(std::string modelFilePath, std::string videoFilePath) { boost::property_tree::ptree root; boost::property_tree::ptree detectionObjects; boost::property_tree::ptree pt; std::vector classes; std::filesystem::path currentPath = std::filesystem::current_path(); ANSCENTER::ANSODBase* infHandle; std::string labelMap; std::string licenseKey = ""; std::string modelZipFilePassword = ""; float detectionScoreThreshold = 0.48; float modelConfThreshold = 0.48; float modelNMSThreshold = 0.48; int modelType = 15; // OPENVINO int detectorType = 1; // Detection labelMap = CreateANSODHandle(&infHandle, licenseKey.c_str(), modelFilePath.c_str(), modelZipFilePassword.c_str(), detectionScoreThreshold, modelConfThreshold, modelNMSThreshold, 1, modelType, detectorType); std::stringstream ss(labelMap); while (ss.good()) { std::string substr; getline(ss, substr, ','); classes.push_back(substr); } std::cout << "classes:" << classes.size() << std::endl; while (true) { std::cout << "begin read video" << std::endl; cv::VideoCapture capture(videoFilePath); if (!capture.isOpened()) { printf("could not read this video file...\n"); return -1; } std::cout << "end read video" << std::endl; while (true) { cv::Mat frame; if (!capture.read(frame)) { std::cout << "\n Cannot read the video file. Restarting...\n"; capture.set(cv::CAP_PROP_POS_FRAMES, 0); // Reset to the beginning of the video continue; } unsigned int bufferLength = 0; cv::Mat croppedFrame = frame(cv::Rect(0, 0, 1920, 1080)); auto start1 = std::chrono::system_clock::now(); std::vector imageData; bool success = cv::imencode(".jpg", croppedFrame, imageData); if (!success) { std::cout << "Failed to encode the image" << std::endl; break; } std::string jpegImage(imageData.begin(), imageData.end()); auto end1 = std::chrono::system_clock::now(); auto elapsed1 = std::chrono::duration_cast(end1 - start1); //printf("Conversion Time = %lld ms\n", static_cast(elapsed1.count())); int height = croppedFrame.rows; int width = croppedFrame.cols; auto start = std::chrono::system_clock::now(); /* measured work */ std::string detectionResult = RunInferenceFromCV(&infHandle, croppedFrame);//RunInferenceFromJpegString(&infHandle, jpegImage.c_str(), imageData.size());// , 100, 100, 0.2); auto end = std::chrono::system_clock::now(); auto elapsed = std::chrono::duration_cast(end - start); printf("Time = %lld ms\n", static_cast(elapsed.count())); if (!detectionResult.empty()) { pt.clear(); std::stringstream ss; ss.clear(); ss << detectionResult; boost::property_tree::read_json(ss, pt); BOOST_FOREACH(const boost::property_tree::ptree::value_type & child, pt.get_child("results")) { const boost::property_tree::ptree& result = child.second; const auto class_id = GetData(result, "class_id"); const auto x = GetData(result, "x"); const auto y = GetData(result, "y"); const auto prob = GetData(result, "prob"); const auto width = GetData(result, "width"); const auto height = GetData(result, "height"); cv::rectangle(croppedFrame, cv::Rect(x, y, width, height), 123, 2); cv::putText(croppedFrame, cv::format("%s:%d:%.2f", classes[class_id], class_id, prob), cv::Point(x, y - 5), 0, 0.6, cv::Scalar(0, 0, 255), 1, cv::LINE_AA); } } cv::imshow("ANS Object Tracking", croppedFrame); if (cv::waitKey(30) == 27) { // Wait for 'esc' key press to exit capture.release(); cv::destroyAllWindows(); ReleaseANSODHandle(&infHandle); std::cout << "End of program.\n"; return 0; } } } } int OpenVINOEngineUnitTest(std::string modelFilePath, std::string videoFilePath) { boost::property_tree::ptree root; boost::property_tree::ptree detectionObjects; boost::property_tree::ptree pt; std::vector classes; std::filesystem::path currentPath = std::filesystem::current_path(); ANSCENTER::ANSODBase* infHandle; std::string labelMap; std::string licenseKey = ""; std::string modelZipFilePassword = ""; float modelThreshold = 0.2; float modelConfThreshold = 0.2; float modelNMSThreshold = 0.2; int modelType = 5;//OPENVINO int detectorType = 1; // Detection labelMap = CreateANSODHandle(&infHandle, licenseKey.c_str(), modelFilePath.c_str(), modelZipFilePassword.c_str(), modelThreshold, modelConfThreshold, modelNMSThreshold, 1, modelType, detectorType); std::stringstream ss(labelMap); while (ss.good()) { std::string substr; getline(ss, substr, ','); classes.push_back(substr); } std::cout << "classes:" << classes.size(); std::cout << "begin read video" << std::endl; cv::VideoCapture capture(videoFilePath); if (!capture.isOpened()) { printf("could not read this video file...\n"); return -1; } std::cout << "end read video" << std::endl; while (true) { cv::Mat frame; if (!capture.read(frame)) // if not success, break loop { std::cout << "\n Cannot read the video file. please check your video.\n"; break; } unsigned int bufferLength = 0; cv::Mat croppedframe = frame(cv::Rect(0, 0, frame.cols, frame.rows)); unsigned char* jpeg_string = ANSCENTER::ANSUtilityHelper::CVMatToBytes(croppedframe, bufferLength); int height = croppedframe.rows; int width = croppedframe.cols; auto start = std::chrono::system_clock::now(); /* measured work */ std::string detectionResult = RunInferenceBinary(&infHandle, jpeg_string, width, height); auto end = std::chrono::system_clock::now(); auto elapsed = std::chrono::duration_cast(end - start); printf("Time = %lld ms\n", static_cast(elapsed.count())); delete jpeg_string; if (!detectionResult.empty()) { pt.clear(); std::stringstream ss; ss.clear(); ss << detectionResult; boost::property_tree::read_json(ss, pt); BOOST_FOREACH(const boost::property_tree::ptree::value_type & child, pt.get_child("results")) { const boost::property_tree::ptree& result = child.second; const auto class_id = GetData(result, "class_id"); const auto x = GetData(result, "x"); const auto y = GetData(result, "y"); const auto prob = GetData(result, "prob"); const auto width = GetData(result, "width"); const auto height = GetData(result, "height"); cv::rectangle(croppedframe, cv::Rect(x, y, width, height), 123, 2); cv::putText(croppedframe, cv::format("%s:%d:%.2f", classes[class_id], class_id, prob), cv::Point(x, y - 5), 0, 0.6, cv::Scalar(0, 0, 255), 1, cv::LINE_AA); } } cv::imshow("ANS Object Tracking", croppedframe); if (cv::waitKey(30) == 27) // Wait for 'esc' key press to exit { break; } } capture.release(); cv::destroyAllWindows(); ReleaseANSODHandle(&infHandle); std::cout << "End of program.\n"; return 0; } int Yolov8EngineUnitTest(std::string modelFilePath, std::string videoFilePath) { boost::property_tree::ptree root; boost::property_tree::ptree detectionObjects; boost::property_tree::ptree pt; std::vector classes; std::filesystem::path currentPath = std::filesystem::current_path(); ANSCENTER::ANSODBase* infHandle; std::string labelMap; std::string licenseKey = ""; std::string modelZipFilePassword = ""; float modelThreshold = 0.5; float modelConfThreshold = 0.5; float modelNMSThreshold = 0.5; int modelType = 3;//TENSORRT int detectorType = 1; std::string optmizedModelFolder; // Optimise model std::cout << "Optimizing model, please wait...." << std::endl; OptimizeModelStr(modelFilePath.c_str(), modelZipFilePassword.c_str(), modelType,1, 1, optmizedModelFolder); std::cout << "Model is optmized, run inference...." << std::endl; labelMap = CreateANSODHandle(&infHandle, licenseKey.c_str(), modelFilePath.c_str(), modelZipFilePassword.c_str(), modelThreshold, modelConfThreshold, modelNMSThreshold, 1, modelType, detectorType); std::stringstream ss(labelMap); while (ss.good()) { std::string substr; getline(ss, substr, ','); classes.push_back(substr); } std::cout << "classes:" << classes.size(); std::cout << "begin read video" << std::endl; cv::VideoCapture capture(videoFilePath); if (!capture.isOpened()) { printf("could not read this video file...\n"); return -1; } std::cout << "end read video" << std::endl; while (true) { cv::Mat frame; if (!capture.read(frame)) // if not success, break loop { std::cout << "\n Cannot read the video file. please check your video.\n"; break; } unsigned int bufferLength = 0; cv::Mat croppedFrame = frame.clone();// frame(cv::Rect(1440, 0, 320, 320)).clone();// frame.clone();//frame(cv::Rect(1250, 0, 640, 640)).clone();//frame.clone();// frame.clone();// unsigned char* jpeg_string = ANSCENTER::ANSUtilityHelper::CVMatToBytes(croppedFrame, bufferLength); int height = croppedFrame.rows; int width = croppedFrame.cols; auto start = std::chrono::system_clock::now(); /* measured work */ std::string detectionResult = RunInferenceBinary(&infHandle, jpeg_string, width, height); auto end = std::chrono::system_clock::now(); auto elapsed = std::chrono::duration_cast(end - start); printf("Time = %lld ms\n", static_cast(elapsed.count())); delete jpeg_string; if (!detectionResult.empty()) { pt.clear(); std::stringstream ss; ss.clear(); ss << detectionResult; boost::property_tree::read_json(ss, pt); BOOST_FOREACH(const boost::property_tree::ptree::value_type & child, pt.get_child("results")) { const boost::property_tree::ptree& result = child.second; const auto class_id = GetData(result, "class_id"); const auto x = GetData(result, "x"); const auto y = GetData(result, "y"); const auto width = GetData(result, "width"); const auto height = GetData(result, "height"); cv::rectangle(croppedFrame, cv::Rect(x, y, width, height), 123, 2); cv::putText(croppedFrame, cv::format("%s:%d", classes[class_id], class_id), cv::Point(x, y - 5), 0, 0.6, cv::Scalar(0, 0, 255), 1, cv::LINE_AA); } } cv::imshow("ANS Object Tracking", croppedFrame); if (cv::waitKey(30) == 27) // Wait for 'esc' key press to exit { break; } croppedFrame.release(); } capture.release(); cv::destroyAllWindows(); ReleaseANSODHandle(&infHandle); std::cout << "End of program.\n"; return 0; } int Yolov5EngineUnitTest(std::string modelFilePath, std::string videoFilePath) { boost::property_tree::ptree root; boost::property_tree::ptree detectionObjects; boost::property_tree::ptree pt; std::vector classes; std::filesystem::path currentPath = std::filesystem::current_path(); ANSCENTER::ANSODBase* infHandle; std::string labelMap; std::string licenseKey = ""; std::string modelZipFilePassword = ""; float modelThreshold = 0.2; float modelConfThreshold = 0.2; float modelNMSThreshold = 0.2; int modelType = 2;//Yolov5 int detectorType = 1; std::string optmizedModelFolder; // Optimise model std::cout << "Optimizing model, please wait...." << std::endl; OptimizeModelStr(modelFilePath.c_str(), modelZipFilePassword.c_str(), modelType,1, 1, optmizedModelFolder); std::cout << "Model is optmized, run inference...." << std::endl; labelMap = CreateANSODHandle(&infHandle, licenseKey.c_str(), modelFilePath.c_str(), modelZipFilePassword.c_str(), modelThreshold, modelConfThreshold, modelNMSThreshold, 1, modelType, detectorType); std::stringstream ss(labelMap); while (ss.good()) { std::string substr; getline(ss, substr, ','); classes.push_back(substr); } std::cout << "classes:" << classes.size(); std::cout << "begin read video" << std::endl; cv::VideoCapture capture(videoFilePath); if (!capture.isOpened()) { printf("could not read this video file...\n"); return -1; } std::cout << "end read video" << std::endl; while (true) { cv::Mat frame; if (!capture.read(frame)) // if not success, break loop { std::cout << "\n Cannot read the video file. please check your video.\n"; break; } unsigned int bufferLength = 0; cv::Mat croppedFrame = frame.clone();// frame(cv::Rect(1440, 0, 320, 320)).clone();// frame.clone();//frame(cv::Rect(1250, 0, 640, 640)).clone();//frame.clone();// frame.clone();// unsigned char* jpeg_string = ANSCENTER::ANSUtilityHelper::CVMatToBytes(croppedFrame, bufferLength); int height = croppedFrame.rows; int width = croppedFrame.cols; auto start = std::chrono::system_clock::now(); /* measured work */ std::string detectionResult = RunInferenceBinary(&infHandle, jpeg_string, width, height); auto end = std::chrono::system_clock::now(); auto elapsed = std::chrono::duration_cast(end - start); printf("Time = %lld ms\n", static_cast(elapsed.count())); delete jpeg_string; if (!detectionResult.empty()) { pt.clear(); std::stringstream ss; ss.clear(); ss << detectionResult; boost::property_tree::read_json(ss, pt); BOOST_FOREACH(const boost::property_tree::ptree::value_type & child, pt.get_child("results")) { const boost::property_tree::ptree& result = child.second; const auto class_id = GetData(result, "class_id"); const auto x = GetData(result, "x"); const auto y = GetData(result, "y"); const auto width = GetData(result, "width"); const auto height = GetData(result, "height"); cv::rectangle(croppedFrame, cv::Rect(x, y, width, height), 123, 2); cv::putText(croppedFrame, cv::format("%s:%d", classes[class_id], class_id), cv::Point(x, y - 5), 0, 0.6, cv::Scalar(0, 0, 255), 1, cv::LINE_AA); } } cv::imshow("ANS Object Tracking", croppedFrame); if (cv::waitKey(30) == 27) // Wait for 'esc' key press to exit { break; } croppedFrame.release(); } capture.release(); cv::destroyAllWindows(); ReleaseANSODHandle(&infHandle); std::cout << "End of program.\n"; return 0; } int Yolov12EngineUnitTest(std::string modelFilePath, std::string videoFilePath) { boost::property_tree::ptree root; boost::property_tree::ptree detectionObjects; boost::property_tree::ptree pt; std::vector classes; std::filesystem::path currentPath = std::filesystem::current_path(); ANSCENTER::ANSODBase* infHandle; std::string labelMap; std::string licenseKey = ""; std::string modelZipFilePassword = ""; float modelThreshold = 0.25; float modelConfThreshold = 0.5; float modelNMSThreshold = 0.5; int modelType = 17;//Yolov12 (4 RT) int detectorType = 1; std::string optmizedModelFolder; // Optimise model std::cout << "Optimizing model, please wait...." << std::endl; OptimizeModelStr(modelFilePath.c_str(), modelZipFilePassword.c_str(), modelType,1, 1, optmizedModelFolder); std::cout << "Model is optmized, run inference...." << std::endl; labelMap = CreateANSODHandle(&infHandle, licenseKey.c_str(), modelFilePath.c_str(), modelZipFilePassword.c_str(), modelThreshold, modelConfThreshold, modelNMSThreshold, 1, modelType, detectorType); std::stringstream ss(labelMap); while (ss.good()) { std::string substr; getline(ss, substr, ','); classes.push_back(substr); } std::cout << "classes:" << classes.size(); std::cout << "begin read video" << std::endl; cv::VideoCapture capture(videoFilePath); if (!capture.isOpened()) { printf("could not read this video file...\n"); return -1; } std::cout << "end read video" << std::endl; while (true) { cv::Mat frame; if (!capture.read(frame)) // if not success, break loop { std::cout << "\n Cannot read the video file. please check your video.\n"; break; } unsigned int bufferLength = 0; cv::Mat croppedFrame = frame.clone();// frame(cv::Rect(1440, 0, 320, 320)).clone();// frame.clone();//frame(cv::Rect(1250, 0, 640, 640)).clone();//frame.clone();// frame.clone();// unsigned char* jpeg_string = ANSCENTER::ANSUtilityHelper::CVMatToBytes(croppedFrame, bufferLength); int height = croppedFrame.rows; int width = croppedFrame.cols; auto start = std::chrono::system_clock::now(); /* measured work */ std::string detectionResult = RunInferenceBinary(&infHandle, jpeg_string, width, height); auto end = std::chrono::system_clock::now(); auto elapsed = std::chrono::duration_cast(end - start); printf("Time = %lld ms\n", static_cast(elapsed.count())); delete jpeg_string; if (!detectionResult.empty()) { pt.clear(); std::stringstream ss; ss.clear(); ss << detectionResult; boost::property_tree::read_json(ss, pt); BOOST_FOREACH(const boost::property_tree::ptree::value_type & child, pt.get_child("results")) { const boost::property_tree::ptree& result = child.second; const auto class_id = GetData(result, "class_id"); const auto x = GetData(result, "x"); const auto y = GetData(result, "y"); const auto width = GetData(result, "width"); const auto height = GetData(result, "height"); cv::rectangle(croppedFrame, cv::Rect(x, y, width, height), 123, 2); cv::putText(croppedFrame, cv::format("%s:%d", classes[class_id], class_id), cv::Point(x, y - 5), 0, 0.6, cv::Scalar(0, 0, 255), 1, cv::LINE_AA); } } cv::imshow("ANS Object Tracking", croppedFrame); if (cv::waitKey(30) == 27) // Wait for 'esc' key press to exit { break; } croppedFrame.release(); } capture.release(); cv::destroyAllWindows(); ReleaseANSODHandle(&infHandle); std::cout << "End of program.\n"; return 0; } int GPUEngineUnitTest(std::string modelFilePath, std::string videoFilePath) { boost::property_tree::ptree root; boost::property_tree::ptree detectionObjects; boost::property_tree::ptree pt; std::vector classes; std::filesystem::path currentPath = std::filesystem::current_path(); ANSCENTER::ANSODBase* infHandle; std::string labelMap; std::string licenseKey = ""; std::string modelZipFilePassword = ""; float modelThreshold = 0.2; float modelConfThreshold = 0.2; float modelNMSThreshold = 0.2; int modelType = 4;//TENSORRT int detectorType = 1; std::string optmizedModelFolder; // Optimise model std::cout << "Optimizing model, please wait...." << std::endl; OptimizeModelStr(modelFilePath.c_str(), modelZipFilePassword.c_str(), modelType,1, 1, optmizedModelFolder); std::cout << "Model is optmized, run inference...." << std::endl; labelMap = CreateANSODHandle(&infHandle, licenseKey.c_str(), modelFilePath.c_str(), modelZipFilePassword.c_str(), modelThreshold, modelConfThreshold, modelNMSThreshold, 1, modelType, detectorType); std::stringstream ss(labelMap); while (ss.good()) { std::string substr; getline(ss, substr, ','); classes.push_back(substr); } std::cout << "classes:" << classes.size(); std::cout << "begin read video" << std::endl; cv::VideoCapture capture(videoFilePath); if (!capture.isOpened()) { printf("could not read this video file...\n"); return -1; } std::cout << "end read video" << std::endl; while (true) { cv::Mat frame; if (!capture.read(frame)) // if not success, break loop { std::cout << "\n Cannot read the video file. please check your video.\n"; break; } unsigned int bufferLength = 0; cv::Mat croppedFrame = frame.clone();// frame(cv::Rect(1440, 0, 320, 320)).clone();// frame.clone();//frame(cv::Rect(1250, 0, 640, 640)).clone();//frame.clone();// frame.clone();// unsigned char* jpeg_string = ANSCENTER::ANSUtilityHelper::CVMatToBytes(croppedFrame, bufferLength); int height = croppedFrame.rows; int width = croppedFrame.cols; auto start = std::chrono::system_clock::now(); /* measured work */ std::string detectionResult = RunInferenceBinary(&infHandle, jpeg_string, width, height); auto end = std::chrono::system_clock::now(); auto elapsed = std::chrono::duration_cast(end - start); printf("Time = %lld ms\n", static_cast(elapsed.count())); delete jpeg_string; if (!detectionResult.empty()) { pt.clear(); std::stringstream ss; ss.clear(); ss << detectionResult; boost::property_tree::read_json(ss, pt); BOOST_FOREACH(const boost::property_tree::ptree::value_type & child, pt.get_child("results")) { const boost::property_tree::ptree& result = child.second; const auto class_id = GetData(result, "class_id"); const auto x = GetData(result, "x"); const auto y = GetData(result, "y"); const auto width = GetData(result, "width"); const auto height = GetData(result, "height"); cv::rectangle(croppedFrame, cv::Rect(x, y, width, height), 123, 2); cv::putText(croppedFrame, cv::format("%s:%d", classes[class_id], class_id), cv::Point(x, y - 5), 0, 0.6, cv::Scalar(0, 0, 255), 1, cv::LINE_AA); } } cv::imshow("ANS Object Tracking", croppedFrame); if (cv::waitKey(30) == 27) // Wait for 'esc' key press to exit { break; } croppedFrame.release(); } capture.release(); cv::destroyAllWindows(); ReleaseANSODHandle(&infHandle); std::cout << "End of program.\n"; return 0; } int ONNXEngineUnitTest(std::string modelFilePath, std::string videoFilePath) { boost::property_tree::ptree root; boost::property_tree::ptree detectionObjects; boost::property_tree::ptree pt; std::vector classes; std::filesystem::path currentPath = std::filesystem::current_path(); ANSCENTER::ANSODBase* infHandle; std::string labelMap; std::string licenseKey = ""; std::string modelZipFilePassword = ""; float modelThreshold = 0.5; float modelConfThreshold = 0.5; float modelNMSThreshold = 0.5; int modelType = 3;//ONNX int detectorType = 1; std::string optmizedModelFolder; // Optimise model std::cout << "Optimizing model, please wait...." << std::endl; OptimizeModelStr(modelFilePath.c_str(), modelZipFilePassword.c_str(), modelType,1, 0, optmizedModelFolder); std::cout << "Model is optmized, run inference...." << std::endl; labelMap = CreateANSODHandle(&infHandle, licenseKey.c_str(), modelFilePath.c_str(), modelZipFilePassword.c_str(), modelThreshold, modelConfThreshold, modelNMSThreshold, 1, modelType, detectorType); std::stringstream ss(labelMap); while (ss.good()) { std::string substr; getline(ss, substr, ','); classes.push_back(substr); } std::cout << "classes:" << classes.size(); std::cout << "begin read video" << std::endl; cv::VideoCapture capture(videoFilePath); if (!capture.isOpened()) { printf("could not read this video file...\n"); return -1; } std::cout << "end read video" << std::endl; while (true) { cv::Mat frame; if (!capture.read(frame)) // if not success, break loop { std::cout << "\n Cannot read the video file. please check your video.\n"; break; } unsigned int bufferLength = 0; unsigned char* jpeg_string = ANSCENTER::ANSUtilityHelper::CVMatToBytes(frame, bufferLength); int height = frame.rows; int width = frame.cols; auto start = std::chrono::system_clock::now(); /* measured work */ std::string detectionResult = RunInferenceBinary(&infHandle, jpeg_string, width, height); auto end = std::chrono::system_clock::now(); auto elapsed = std::chrono::duration_cast(end - start); printf("Time = %lld ms\n", static_cast(elapsed.count())); delete jpeg_string; if (!detectionResult.empty()) { pt.clear(); std::stringstream ss; ss.clear(); ss << detectionResult; boost::property_tree::read_json(ss, pt); BOOST_FOREACH(const boost::property_tree::ptree::value_type & child, pt.get_child("results")) { const boost::property_tree::ptree& result = child.second; const auto class_id = GetData(result, "class_id"); const auto x = GetData(result, "x"); const auto y = GetData(result, "y"); const auto width = GetData(result, "width"); const auto height = GetData(result, "height"); cv::rectangle(frame, cv::Rect(x, y, width, height), 123, 2); cv::putText(frame, cv::format("%s:%d", classes[class_id], class_id), cv::Point(x, y - 5), 0, 0.6, cv::Scalar(0, 0, 255), 1, cv::LINE_AA); } } cv::imshow("ANS Object Tracking", frame); if (cv::waitKey(30) == 27) // Wait for 'esc' key press to exit { break; } } capture.release(); cv::destroyAllWindows(); ReleaseANSODHandle(&infHandle); std::cout << "End of program.\n"; return 0; } int GPUEngineImageTest(std::string modelFilePath, std::string imageFilePath) { boost::property_tree::ptree root; boost::property_tree::ptree detectionObjects; boost::property_tree::ptree pt; std::vector classes; std::filesystem::path currentPath = std::filesystem::current_path(); ANSCENTER::ANSODBase* infHandle; std::string labelMap; std::string licenseKey = ""; std::string modelZipFilePassword = ""; float modelThreshold = 0.5; float modelConfThreshold = 0.5; float modelNMSThreshold = 0.5; int modelType = 4;//TENSORRT int detectorType = 1; std::string optmizedModelFolder; // Optimise model std::cout << "Optimizing model, please wait...." << std::endl; OptimizeModelStr(modelFilePath.c_str(), modelZipFilePassword.c_str(), modelType,1, 1, optmizedModelFolder); std::cout << "Model is optmized, run inference...." << std::endl; labelMap = CreateANSODHandle(&infHandle, licenseKey.c_str(), modelFilePath.c_str(), modelZipFilePassword.c_str(), modelThreshold, modelConfThreshold, modelNMSThreshold, 1, modelType, detectorType); std::stringstream ss(labelMap); while (ss.good()) { std::string substr; getline(ss, substr, ','); classes.push_back(substr); } cv::Mat frame = cv::imread(imageFilePath, cv::IMREAD_COLOR); unsigned int bufferLength = 0; unsigned char* jpeg_string = ANSCENTER::ANSUtilityHelper::CVMatToBytes(frame, bufferLength); int height = frame.rows; int width = frame.cols; auto start = std::chrono::system_clock::now(); /* measured work */ std::string detectionResult = RunInferenceBinary(&infHandle, jpeg_string, width, height); auto end = std::chrono::system_clock::now(); auto elapsed = std::chrono::duration_cast(end - start); printf("Time = %lld ms\n", static_cast(elapsed.count())); std::cout << "Result:" << detectionResult << std::endl; delete jpeg_string; if (!detectionResult.empty()) { pt.clear(); std::stringstream ss; ss.clear(); ss << detectionResult; boost::property_tree::read_json(ss, pt); BOOST_FOREACH(const boost::property_tree::ptree::value_type & child, pt.get_child("results")) { const boost::property_tree::ptree& result = child.second; const auto class_id = GetData(result, "class_id"); const auto x = GetData(result, "x"); const auto y = GetData(result, "y"); const auto width = GetData(result, "width"); const auto height = GetData(result, "height"); cv::rectangle(frame, cv::Rect(x, y, width, height), 123, 2); cv::putText(frame, cv::format("%s:%d", classes[class_id], class_id), cv::Point(x, y - 5), 0, 0.6, cv::Scalar(0, 0, 255), 1, cv::LINE_AA); std::cout << "Keypoints =[" << GetData(result, "extra_info") << "]" << std::endl; } } //cv::imshow("ANS Object Tracking", frame); //if (cv::waitKey(0) == 0) // Wait for 'esc' key press to exit //{ // std::cout << "End of facial detection.\n"; //} cv::destroyAllWindows(); ReleaseANSODHandle(&infHandle); std::cout << "End of program.\n"; return 0; } int GPU11EngineImageTest(std::string modelFilePath, std::string imageFilePath) { boost::property_tree::ptree root; boost::property_tree::ptree detectionObjects; boost::property_tree::ptree pt; std::vector classes; std::filesystem::path currentPath = std::filesystem::current_path(); ANSCENTER::ANSODBase* infHandle; std::string labelMap; std::string licenseKey = ""; std::string modelZipFilePassword = ""; float modelThreshold = 0.5; float modelConfThreshold = 0.5; float modelNMSThreshold = 0.5; int modelType = 4;//TENSORRTyolo11 same as yolov8 int detectorType = 1; std::string optmizedModelFolder; // Optimise model std::cout << "Optimizing model, please wait...." << std::endl; OptimizeModelStr(modelFilePath.c_str(), modelZipFilePassword.c_str(), modelType, 1,1, optmizedModelFolder); std::cout << "Model is optmized, run inference...." << std::endl; labelMap = CreateANSODHandle(&infHandle, licenseKey.c_str(), modelFilePath.c_str(), modelZipFilePassword.c_str(), modelThreshold, modelConfThreshold, modelNMSThreshold, 1, modelType, detectorType,1); std::stringstream ss(labelMap); while (ss.good()) { std::string substr; getline(ss, substr, ','); classes.push_back(substr); } cv::Mat frame = cv::imread(imageFilePath, cv::IMREAD_COLOR); unsigned int bufferLength = 0; unsigned char* jpeg_string = ANSCENTER::ANSUtilityHelper::CVMatToBytes(frame, bufferLength); int height = frame.rows; int width = frame.cols; auto start = std::chrono::system_clock::now(); /* measured work */ std::string detectionResult = RunInferenceBinary(&infHandle, jpeg_string, width, height); auto end = std::chrono::system_clock::now(); auto elapsed = std::chrono::duration_cast(end - start); printf("Time = %lld ms\n", static_cast(elapsed.count())); std::cout << "Result:" << detectionResult << std::endl; delete jpeg_string; if (!detectionResult.empty()) { pt.clear(); std::stringstream ss; ss.clear(); ss << detectionResult; boost::property_tree::read_json(ss, pt); BOOST_FOREACH(const boost::property_tree::ptree::value_type & child, pt.get_child("results")) { const boost::property_tree::ptree& result = child.second; const auto class_id = GetData(result, "class_id"); const auto x = GetData(result, "x"); const auto y = GetData(result, "y"); const auto width = GetData(result, "width"); const auto height = GetData(result, "height"); cv::rectangle(frame, cv::Rect(x, y, width, height), 123, 2); cv::putText(frame, cv::format("%s:%d", classes[class_id], class_id), cv::Point(x, y - 5), 0, 0.6, cv::Scalar(0, 0, 255), 1, cv::LINE_AA); std::cout << "Keypoints =[" << GetData(result, "extra_info") << "]" << std::endl; } } cv::imshow("ANS Object Tracking", frame); if (cv::waitKey(0) == 0) // Wait for 'esc' key press to exit { std::cout << "End of facial detection.\n"; } cv::destroyAllWindows(); ReleaseANSODHandle(&infHandle); std::cout << "End of program.\n"; return 0; } int GPU11EngineUnitTest(std::string modelFilePath, std::string videoFilePath) { boost::property_tree::ptree root; boost::property_tree::ptree detectionObjects; boost::property_tree::ptree pt; std::vector classes; std::filesystem::path currentPath = std::filesystem::current_path(); ANSCENTER::ANSODBase* infHandle; std::string labelMap; std::string licenseKey = ""; std::string modelZipFilePassword = ""; float modelThreshold = 0.2; float modelConfThreshold = 0.2; float modelNMSThreshold = 0.2; int modelType = 4;//TENSORRTv11 same as Yolov8 int detectorType = 1; std::string optmizedModelFolder; // Optimise model std::cout << "Optimizing model, please wait...." << std::endl; OptimizeModelStr(modelFilePath.c_str(), modelZipFilePassword.c_str(), modelType,1, 1, optmizedModelFolder); std::cout << "Model is optmized, run inference...." << std::endl; labelMap = CreateANSODHandle(&infHandle, licenseKey.c_str(), modelFilePath.c_str(), modelZipFilePassword.c_str(), modelThreshold, modelConfThreshold, modelNMSThreshold, 1, modelType, detectorType); std::stringstream ss(labelMap); while (ss.good()) { std::string substr; getline(ss, substr, ','); classes.push_back(substr); } std::cout << "classes:" << classes.size(); std::cout << "begin read video" << std::endl; cv::VideoCapture capture(videoFilePath); if (!capture.isOpened()) { printf("could not read this video file...\n"); return -1; } std::cout << "end read video" << std::endl; while (true) { cv::Mat frame; if (!capture.read(frame)) // if not success, break loop { std::cout << "\n Cannot read the video file. please check your video.\n"; break; } unsigned int bufferLength = 0; cv::Mat croppedFrame = frame.clone();// frame(cv::Rect(1440, 0, 320, 320)).clone();// frame.clone();//frame(cv::Rect(1250, 0, 640, 640)).clone();//frame.clone();// frame.clone();// unsigned char* jpeg_string = ANSCENTER::ANSUtilityHelper::CVMatToBytes(croppedFrame, bufferLength); int height = croppedFrame.rows; int width = croppedFrame.cols; auto start = std::chrono::system_clock::now(); /* measured work */ std::string detectionResult = RunInferenceBinary(&infHandle, jpeg_string, width, height); auto end = std::chrono::system_clock::now(); auto elapsed = std::chrono::duration_cast(end - start); printf("Time = %lld ms\n", static_cast(elapsed.count())); delete jpeg_string; if (!detectionResult.empty()) { pt.clear(); std::stringstream ss; ss.clear(); ss << detectionResult; boost::property_tree::read_json(ss, pt); BOOST_FOREACH(const boost::property_tree::ptree::value_type & child, pt.get_child("results")) { const boost::property_tree::ptree& result = child.second; const auto class_id = GetData(result, "class_id"); const auto x = GetData(result, "x"); const auto y = GetData(result, "y"); const auto width = GetData(result, "width"); const auto height = GetData(result, "height"); cv::rectangle(croppedFrame, cv::Rect(x, y, width, height), 123, 2); cv::putText(croppedFrame, cv::format("%s:%d", classes[class_id], class_id), cv::Point(x, y - 5), 0, 0.6, cv::Scalar(0, 0, 255), 1, cv::LINE_AA); } } cv::imshow("ANS Object Tracking", croppedFrame); if (cv::waitKey(30) == 27) // Wait for 'esc' key press to exit { break; } croppedFrame.release(); } capture.release(); cv::destroyAllWindows(); ReleaseANSODHandle(&infHandle); std::cout << "End of program.\n"; return 0; } int UnitTests() { std::string defaultDir = "C:\\Programs"; std::string abmodelFilePath = defaultDir + "\\DemoAssets\\ANSAIModels\\anomalibmodel.zip"; std::string cpumodelFilePath = "C:\\ProgramData\\ANSCENTER\\Shared\\ANS_GenericOD(CPU)_v1.0.zip"; std::string gpumodelFilePath = defaultDir + "\\DemoAssets\\ANSAIModels\\OptimisedModels\\ANS_GenericOD(GPU)_v1.0.zip"; std::string Yolov8OpenVINOModelPath = defaultDir + "\\DemoAssets\\Models\\ANS_GenericOD(CPU)YL8_v1.0.zip"; std::string Yolov8OTensorRTModelPath = defaultDir + "\\DemoAssets\\ANSAIModels\\OptimisedModels\\PPEGPU.zip"; std::string odhubModelPath = defaultDir + "\\DemoAssets\\Models\\openflapmulticat_v1.zip"; std::string openposeModelPath = defaultDir + "\\ANSAIModels\\ANS_PoseEstimation_v1.0.zip"; std::string samModelPath = defaultDir + "\\ANSAIModels\\ANS_SAM_v1.0.zip"; std::string customModelPath = defaultDir + "\\ANLS\\AIModels\\ANSCustomModel_v3.zip"; std::string abImageFilePath = defaultDir + "\\TestImages\\brokenlarge.png"; std::string customModelImage = defaultDir + "\\ANLS\\AIModels\\LP2.jpg"; std::string imageDataPath = defaultDir + "\\DemoAssets\\TestImages\\ALPR\\101_EUS664.jpg"; std::string videoDataPath = defaultDir + "\\DemoAssets\\Videos\\road.mp4"; std::string videoPPEPath = defaultDir + "\\DemoAssets\\Videos\\Factory1.mp4"; std::string odhubVideoPath = defaultDir + "\\DemoAssets\\Videos\\openflap.mp4"; std::string openposeVideoPath = defaultDir + "\\DemoAssets\\Videos\\train.mp4";; std::string openposeImagePath = defaultDir + "\\DemoAssets\\TestImages\\ANSCVAImages\\openpose.jpg"; std::string classroom = defaultDir + "\\DemoAssets\\Videos\\classroom.mp4"; std::string classroomGPUTest = "C:\\ProgramData\\ANSCENTER\\Shared\\classroom.mp4"; std::string modelGPUTest = "C:\\ProgramData\\ANSCENTER\\Shared\\ANS_GenericOD(GPU)_v1.0.zip"; // OpenVINOEngineUnitTest(Yolov8OpenVINOModelPath, videoDataPath); // Yolov8 //GPUEngineUnitTest(Yolov8OTensorRTModelPath, videoPPEPath);// yolov8 // OpenVINOYolov10EngineUnitTestLoop(cpumodelFilePath, classroom);//yolov10 OpenVINOYolov10EngineUnitTest(cpumodelFilePath, classroom);//yolov10 // GPUYolov10EngineUnitTest(modelGPUTest, classroomGPUTest);// yolov10 //ODHUBAPITest(odhubModelPath, odhubVideoPath); //AnomalibTest(abmodelFilePath, abImageFilePath); //FacialDetectorTest(cpumodelFilePath, imageDataPath); //HumanPoseTest(openposeModelPath, openposeVideoPath); //HumanPoseImageTest(openposeModelPath, openposeImagePath); //ANSSAMTest(samModelPath, openflapVideoPath); //CustomCodeImageTest(customModelPath, customModelImage); //ALPRPipeLineTest(gpumodelFilePath, videoFilePathPipeLine); return 0; } int FacialDetectorTest(std::string modelFilePath, std::string imagePath) { boost::property_tree::ptree root; boost::property_tree::ptree detectionObjects; boost::property_tree::ptree pt; std::vector classes; std::filesystem::path currentPath = std::filesystem::current_path(); ANSCENTER::ANSODBase* infHandle; std::string labelMap; std::string licenseKey = ""; std::string modelZipFilePassword = ""; float modelThreshold = 0.5; float modelConfThreshold = 0.5; float modelNMSThreshold = 0.5; int modelType = 6;//Facial int detectorType = 1; // Detection labelMap = CreateANSODHandle(&infHandle, licenseKey.c_str(), modelFilePath.c_str(), modelZipFilePassword.c_str(), modelThreshold, modelConfThreshold, modelNMSThreshold, 1, modelType, detectorType); std::stringstream ss(labelMap); while (ss.good()) { std::string substr; getline(ss, substr, ','); classes.push_back(substr); } std::cout << "classes:" << classes.size(); cv::Mat frame = cv::imread(imagePath, cv::IMREAD_COLOR); unsigned int bufferLength = 0; unsigned char* jpeg_string = ANSCENTER::ANSUtilityHelper::CVMatToBytes(frame, bufferLength); int height = frame.rows; int width = frame.cols; auto start = std::chrono::system_clock::now(); /* measured work */ std::string detectionResult = RunInferenceBinary(&infHandle, jpeg_string, width, height); auto end = std::chrono::system_clock::now(); auto elapsed = std::chrono::duration_cast(end - start); printf("Time = %lld ms\n", static_cast(elapsed.count())); std::cout << "Result:" << detectionResult << std::endl; delete jpeg_string; if (!detectionResult.empty()) { pt.clear(); std::stringstream ss; ss.clear(); ss << detectionResult; boost::property_tree::read_json(ss, pt); BOOST_FOREACH(const boost::property_tree::ptree::value_type & child, pt.get_child("results")) { const boost::property_tree::ptree& result = child.second; const auto class_id = GetData(result, "class_id"); const auto x = GetData(result, "x"); const auto y = GetData(result, "y"); const auto width = GetData(result, "width"); const auto height = GetData(result, "height"); cv::rectangle(frame, cv::Rect(x, y, width, height), 123, 2); cv::putText(frame, cv::format("%s:%d", classes[class_id], class_id), cv::Point(x, y - 5), 0, 0.6, cv::Scalar(0, 0, 255), 1, cv::LINE_AA); } } cv::imshow("ANS Object Tracking", frame); if (cv::waitKey(0) == 27) // Wait for 'esc' key press to exit { std::cout << "End of facial detection.\n"; } cv::destroyAllWindows(); ReleaseANSODHandle(&infHandle); std::cout << "End of program.\n"; return 0; } int AnomalibTest(std::string abmodelFilePath, std::string abImageFilePath) { boost::property_tree::ptree root; boost::property_tree::ptree detectionObjects; boost::property_tree::ptree pt; std::vector classes; ANSCENTER::ANSODBase* infHandle; std::string labelMap; std::string licenseKey = ""; std::string modelZipFilePassword = ""; float modelThreshold = 0.5; float modelConfThreshold = 0.5; float modelNMSThreshold = 0.5; int modelType = 10;//Facial int detectorType = 2; // Segmentation labelMap = CreateANSODHandle(&infHandle, licenseKey.c_str(), abmodelFilePath.c_str(), modelZipFilePassword.c_str(), modelThreshold, modelConfThreshold, modelNMSThreshold, 1, modelType, detectorType); std::stringstream ss(labelMap); while (ss.good()) { std::string substr; getline(ss, substr, ','); classes.push_back(substr); } std::cout << "label map:" << labelMap << std::endl; std::string imagePath = abImageFilePath; cv::Mat frame = cv::imread(imagePath, cv::IMREAD_COLOR); unsigned int bufferLength = 0; unsigned char* jpeg_string = ANSCENTER::ANSUtilityHelper::CVMatToBytes(frame, bufferLength); int height = frame.rows; int width = frame.cols; auto start = std::chrono::system_clock::now(); /* measured work */ std::string detectionResult = RunInferenceBinary(&infHandle, jpeg_string, width, height); auto end = std::chrono::system_clock::now(); auto elapsed = std::chrono::duration_cast(end - start); printf("Time = %lld ms\n", static_cast(elapsed.count())); std::cout << "Result:" << detectionResult << std::endl; delete jpeg_string; cv::imshow("ANS Object Tracking", frame); if (cv::waitKey(0) == 27) // Wait for 'esc' key press to exit { std::cout << "End of abnomalib detection.\n"; } cv::destroyAllWindows(); ReleaseANSODHandle(&infHandle); std::cout << "End of program.\n"; return 0; } int HumanPoseTest(std::string modelFilePath, std::string imagePath) { boost::property_tree::ptree root; boost::property_tree::ptree detectionObjects; boost::property_tree::ptree pt; std::vector classes; std::filesystem::path currentPath = std::filesystem::current_path(); ANSCENTER::ANSODBase* infHandle; std::string labelMap; std::string licenseKey = ""; std::string modelZipFilePassword = ""; float modelThreshold = 0.5; float modelConfThreshold = 0.5; float modelNMSThreshold = 0.5; int modelType = 11;//POSE int detectorType = 7; // KEYPOINT labelMap = CreateANSODHandle(&infHandle, licenseKey.c_str(), modelFilePath.c_str(), modelZipFilePassword.c_str(), modelThreshold, modelConfThreshold, modelNMSThreshold, 1, modelType, detectorType); std::stringstream ss(labelMap); while (ss.good()) { std::string substr; getline(ss, substr, ','); classes.push_back(substr); } std::cout << "classes:" << classes.size(); cv::VideoCapture capture(imagePath); if (!capture.isOpened()) { printf("could not read this video file...\n"); return -1; } while (true) { cv::Mat frame; if (!capture.read(frame)) // if not success, break loop { std::cout << "\n Cannot read the video file. please check your video.\n"; break; } unsigned int bufferLength = 0; unsigned char* jpeg_string = ANSCENTER::ANSUtilityHelper::CVMatToBytes(frame, bufferLength); int height = frame.rows; int width = frame.cols; auto start = std::chrono::system_clock::now(); /* measured work */ std::string detectionResult = RunInferenceBinary(&infHandle, jpeg_string, width, height); auto end = std::chrono::system_clock::now(); auto elapsed = std::chrono::duration_cast(end - start); printf("Time = %lld ms\n", static_cast(elapsed.count())); delete jpeg_string; if (!detectionResult.empty()) { pt.clear(); std::stringstream ss; ss.clear(); ss << detectionResult; boost::property_tree::read_json(ss, pt); BOOST_FOREACH(const boost::property_tree::ptree::value_type & child, pt.get_child("results")) { const boost::property_tree::ptree& result = child.second; const auto class_id = GetData(result, "class_id"); const auto x = GetData(result, "x"); const auto y = GetData(result, "y"); const auto width = GetData(result, "width"); const auto height = GetData(result, "height"); cv::rectangle(frame, cv::Rect(x, y, width, height), 123, 2); cv::putText(frame, cv::format("%s:%d", classes[class_id], class_id), cv::Point(x, y - 5), 0, 0.6, cv::Scalar(0, 0, 255), 1, cv::LINE_AA); std::cout << "Keypoints =[" << GetData(result, "extra_info") << "]" << std::endl; } } cv::imshow("ANS Object Tracking", frame); if (cv::waitKey(30) == 27) // Wait for 'esc' key press to exit { break; } } capture.release(); cv::destroyAllWindows(); ReleaseANSODHandle(&infHandle); std::cout << "End of program.\n"; return 0; } int HumanPoseImageTest(std::string modelFilePath, std::string imagePath) { boost::property_tree::ptree root; boost::property_tree::ptree detectionObjects; boost::property_tree::ptree pt; std::vector classes; std::filesystem::path currentPath = std::filesystem::current_path(); ANSCENTER::ANSODBase* infHandle; std::string labelMap; std::string licenseKey = ""; std::string modelZipFilePassword = ""; float modelThreshold = 0.5; float modelConfThreshold = 0.5; float modelNMSThreshold = 0.5; int modelType = 11;//POSE int detectorType = 7; // KEYPOINT labelMap = CreateANSODHandle(&infHandle, licenseKey.c_str(), modelFilePath.c_str(), modelZipFilePassword.c_str(), modelThreshold, modelConfThreshold, modelNMSThreshold, 1, modelType, detectorType); std::stringstream ss(labelMap); while (ss.good()) { std::string substr; getline(ss, substr, ','); classes.push_back(substr); } std::cout << "classes:" << classes.size(); cv::Mat frame = cv::imread(imagePath, cv::IMREAD_COLOR); unsigned int bufferLength = 0; unsigned char* jpeg_string = ANSCENTER::ANSUtilityHelper::CVMatToBytes(frame, bufferLength); int height = frame.rows; int width = frame.cols; auto start = std::chrono::system_clock::now(); /* measured work */ std::string detectionResult = RunInferenceBinary(&infHandle, jpeg_string, width, height); auto end = std::chrono::system_clock::now(); auto elapsed = std::chrono::duration_cast(end - start); printf("Time = %lld ms\n", static_cast(elapsed.count())); std::cout << "Result:" << detectionResult << std::endl; delete jpeg_string; if (!detectionResult.empty()) { pt.clear(); std::stringstream ss; ss.clear(); ss << detectionResult; boost::property_tree::read_json(ss, pt); BOOST_FOREACH(const boost::property_tree::ptree::value_type & child, pt.get_child("results")) { const boost::property_tree::ptree& result = child.second; const auto class_id = GetData(result, "class_id"); const auto x = GetData(result, "x"); const auto y = GetData(result, "y"); const auto width = GetData(result, "width"); const auto height = GetData(result, "height"); cv::rectangle(frame, cv::Rect(x, y, width, height), 123, 2); cv::putText(frame, cv::format("%s:%d", classes[class_id], class_id), cv::Point(x, y - 5), 0, 0.6, cv::Scalar(0, 0, 255), 1, cv::LINE_AA); std::cout << "Keypoints =[" << GetData(result, "extra_info") << "]" << std::endl; } } cv::imshow("ANS Object Tracking", frame); if (cv::waitKey(0) == 27) // Wait for 'esc' key press to exit { std::cout << "End of facial detection.\n"; } cv::destroyAllWindows(); ReleaseANSODHandle(&infHandle); std::cout << "End of program.\n"; return 0; } int ANSSAMTest(std::string modelFilePath, std::string videoPath) { ANSCENTER::ANSSAM infHandle; std::string licenseKey = ""; std::string labelmap = ""; std::string modelZipFilePassword = ""; ANSCENTER::ModelConfig modelConfig; modelConfig.modelConfThreshold = 0.5f; infHandle.Initialize(licenseKey, modelConfig, modelFilePath, modelZipFilePassword, labelmap); cv::VideoCapture capture(videoPath); if (!capture.isOpened()) { printf("could not read this video file...\n"); return -1; } while (true) { cv::Mat frame; if (!capture.read(frame)) // if not success, break loop { std::cout << "\n Cannot read the video file. please check your video.\n"; break; } auto start = std::chrono::system_clock::now(); std::vector masks = infHandle.RunInference(frame); auto end = std::chrono::system_clock::now(); auto elapsed = std::chrono::duration_cast(end - start); printf("Time = %lld ms\n", static_cast(elapsed.count())); for (int i = 0; i < masks.size(); i++) { cv::rectangle(frame, masks.at(i).box, 123, 2); //const cv::Point* pts = (const cv::Point*)cv::Mat(masks.at(i).polygon).data; //int npts = cv::Mat(masks.at(i).polygon).rows; //polylines(frame, &pts, &npts, 1, true, cv::Scalar(0, 255, 0), 1); // Green color, line thickness 3 } cv::imshow("ANS Object Tracking", frame); if (cv::waitKey(30) == 27) // Wait for 'esc' key press to exit { break; } } capture.release(); cv::destroyAllWindows(); infHandle.Destroy(); std::cout << "End of program.\n"; return 0; } int ODHUBAPITest(std::string modelFilePath, std::string videoFilePath) { boost::property_tree::ptree root; boost::property_tree::ptree detectionObjects; boost::property_tree::ptree pt; std::vector classes; std::filesystem::path currentPath = std::filesystem::current_path(); ANSCENTER::ANSODBase* infHandle; std::string labelMap; std::string modelZipFilePassword = ""; float modelThreshold = 0.7; float modelConfThreshold = 0.5; float modelNMSThreshold = 0.5; int modelType = 13;//ODHUBAPI ;1 is yolov4 opencv int detectorType = 1; std::string optmizedModelFolder; // Optimise model std::cout << "Optimizing model, please wait...." << std::endl; OptimizeModelStr(modelFilePath.c_str(), modelZipFilePassword.c_str(), modelType,1, 1, optmizedModelFolder); std::cout << "Model is optmized, run inference...." << std::endl; labelMap = CreateANSODHandle(&infHandle, "", modelFilePath.c_str(), modelZipFilePassword.c_str(), modelThreshold, modelConfThreshold, modelNMSThreshold, 1, modelType, detectorType); std::stringstream ss(labelMap); while (ss.good()) { std::string substr; getline(ss, substr, ','); classes.push_back(substr); } std::cout << "classes:" << classes.size(); std::cout << "begin read video" << std::endl; cv::VideoCapture capture(videoFilePath); if (!capture.isOpened()) { printf("could not read this video file...\n"); return -1; } std::cout << "end read video" << std::endl; while (true) { cv::Mat frame; if (!capture.read(frame)) // if not success, break loop { std::cout << "\n Cannot read the video file. please check your video.\n"; break; } unsigned int bufferLength = 0; unsigned char* jpeg_string = ANSCENTER::ANSUtilityHelper::CVMatToBytes(frame, bufferLength); int height = frame.rows; int width = frame.cols; auto start = std::chrono::system_clock::now(); /* measured work */ std::string detectionResult = RunInferenceBinary(&infHandle, jpeg_string, width, height); auto end = std::chrono::system_clock::now(); auto elapsed = std::chrono::duration_cast(end - start); printf("Time = %lld ms\n", static_cast(elapsed.count())); delete jpeg_string; if (!detectionResult.empty()) { pt.clear(); std::stringstream ss; ss.clear(); ss << detectionResult; boost::property_tree::read_json(ss, pt); BOOST_FOREACH(const boost::property_tree::ptree::value_type & child, pt.get_child("results")) { const boost::property_tree::ptree& result = child.second; const auto class_id = GetData(result, "class_id"); const auto x = GetData(result, "x"); const auto y = GetData(result, "y"); const auto width = GetData(result, "width"); const auto height = GetData(result, "height"); cv::rectangle(frame, cv::Rect(x, y, width, height), 123, 2); cv::putText(frame, cv::format("%s:%d", classes[class_id], class_id), cv::Point(x, y - 5), 0, 0.6, cv::Scalar(0, 0, 255), 1, cv::LINE_AA); } } cv::imshow("ANS Object Tracking", frame); if (cv::waitKey(30) == 27) // Wait for 'esc' key press to exit { break; } } capture.release(); cv::destroyAllWindows(); ReleaseANSODHandle(&infHandle); std::cout << "End of program.\n"; return 0; } int ODHUBOpenCVAPITest(std::string modelFilePath, std::string videoFilePath) { boost::property_tree::ptree root; boost::property_tree::ptree detectionObjects; boost::property_tree::ptree pt; std::vector classes; std::filesystem::path currentPath = std::filesystem::current_path(); ANSCENTER::ANSODBase* infHandle; std::string labelMap; std::string modelZipFilePassword = ""; float modelThreshold = 0.7; float modelConfThreshold = 0.5; float modelNMSThreshold = 0.5; int modelType = 13;//ODHUBAPI ;1 is yolov4 opencv int detectorType = 1; std::string optmizedModelFolder; // Optimise model std::cout << "Optimizing model, please wait...." << std::endl; OptimizeModelStr(modelFilePath.c_str(), modelZipFilePassword.c_str(), modelType,1, 1, optmizedModelFolder); std::cout << "Model is optmized, run inference...." << std::endl; labelMap = CreateANSODHandle(&infHandle, "", modelFilePath.c_str(), modelZipFilePassword.c_str(), modelThreshold, modelConfThreshold, modelNMSThreshold, 1, modelType, detectorType); std::stringstream ss(labelMap); while (ss.good()) { std::string substr; getline(ss, substr, ','); classes.push_back(substr); } std::cout << "classes:" << classes.size(); std::cout << "begin read video" << std::endl; cv::VideoCapture capture(videoFilePath); if (!capture.isOpened()) { printf("could not read this video file...\n"); return -1; } std::cout << "end read video" << std::endl; while (true) { cv::Mat frame; if (!capture.read(frame)) // if not success, break loop { std::cout << "\n Cannot read the video file. please check your video.\n"; break; } unsigned int bufferLength = 0; unsigned char* jpeg_string = ANSCENTER::ANSUtilityHelper::CVMatToBytes(frame, bufferLength); int height = frame.rows; int width = frame.cols; auto start = std::chrono::system_clock::now(); /* measured work */ std::string detectionResult = RunInferenceBinary(&infHandle, jpeg_string, width, height); auto end = std::chrono::system_clock::now(); auto elapsed = std::chrono::duration_cast(end - start); printf("Time = %lld ms\n", static_cast(elapsed.count())); delete jpeg_string; if (!detectionResult.empty()) { pt.clear(); std::stringstream ss; ss.clear(); ss << detectionResult; boost::property_tree::read_json(ss, pt); BOOST_FOREACH(const boost::property_tree::ptree::value_type & child, pt.get_child("results")) { const boost::property_tree::ptree& result = child.second; const auto class_id = GetData(result, "class_id"); const auto x = GetData(result, "x"); const auto y = GetData(result, "y"); const auto width = GetData(result, "width"); const auto height = GetData(result, "height"); cv::rectangle(frame, cv::Rect(x, y, width, height), 123, 2); cv::putText(frame, cv::format("%s:%d", classes[class_id], class_id), cv::Point(x, y - 5), 0, 0.6, cv::Scalar(0, 0, 255), 1, cv::LINE_AA); } } cv::imshow("ANS Object Tracking", frame); if (cv::waitKey(30) == 27) // Wait for 'esc' key press to exit { break; } } capture.release(); cv::destroyAllWindows(); ReleaseANSODHandle(&infHandle); std::cout << "End of program.\n"; return 0; } int ODHUBAPIImageTest(std::string modelFilePath, std::string imageFilePath) { boost::property_tree::ptree root; boost::property_tree::ptree detectionObjects; boost::property_tree::ptree pt; std::vector classes; std::filesystem::path currentPath = std::filesystem::current_path(); ANSCENTER::ANSODBase* infHandle; std::string labelMap; std::string modelZipFilePassword = ""; float modelThreshold = 0.7; float modelConfThreshold = 0.5; float modelNMSThreshold = 0.5; int modelType = 13;//ODHUBAPI ;1 is yolov4 opencv int detectorType = 1; std::string optmizedModelFolder; // Optimise model std::cout << "Optimizing model, please wait...." << std::endl; OptimizeModelStr(modelFilePath.c_str(), modelZipFilePassword.c_str(), modelType,1, 1, optmizedModelFolder); std::cout << "Model is optmized, run inference...." << std::endl; labelMap = CreateANSODHandle(&infHandle, "", modelFilePath.c_str(), modelZipFilePassword.c_str(), modelThreshold, modelConfThreshold, modelNMSThreshold, 1, modelType, detectorType); std::stringstream ss(labelMap); while (ss.good()) { std::string substr; getline(ss, substr, ','); classes.push_back(substr); } std::cout << "classes:" << classes.size(); std::cout << "begin read video" << std::endl; cv::Mat frame = cv::imread(imageFilePath, cv::IMREAD_COLOR); unsigned int bufferLength = 0; unsigned char* jpeg_string = ANSCENTER::ANSUtilityHelper::CVMatToBytes(frame, bufferLength); int height = frame.rows; int width = frame.cols; auto start = std::chrono::system_clock::now(); /* measured work */ std::string detectionResult = RunInferenceBinary(&infHandle, jpeg_string, width, height); auto end = std::chrono::system_clock::now(); auto elapsed = std::chrono::duration_cast(end - start); printf("Time = %lld ms\n", static_cast(elapsed.count())); std::cout << "Result:" << detectionResult << std::endl; delete jpeg_string; if (!detectionResult.empty()) { pt.clear(); std::stringstream ss; ss.clear(); ss << detectionResult; boost::property_tree::read_json(ss, pt); BOOST_FOREACH(const boost::property_tree::ptree::value_type & child, pt.get_child("results")) { const boost::property_tree::ptree& result = child.second; const auto class_id = GetData(result, "class_id"); const auto x = GetData(result, "x"); const auto y = GetData(result, "y"); const auto width = GetData(result, "width"); const auto height = GetData(result, "height"); cv::rectangle(frame, cv::Rect(x, y, width, height), 123, 2); cv::putText(frame, cv::format("%s:%d", classes[class_id], class_id), cv::Point(x, y - 5), 0, 0.6, cv::Scalar(255, 0, 0), 1, cv::LINE_AA); std::cout << "Keypoints =[" << GetData(result, "extra_info") << "]" << std::endl; } } resize(frame, frame, Size(frame.cols / 2, frame.rows / 2)); // to half size or even smaller namedWindow("Display frame", WINDOW_AUTOSIZE); cv::imshow("Display frame", frame); if (cv::waitKey(0) == 3) // Wait for 'esc' key press to exit { std::cout << "End of facial detection.\n"; } cv::destroyAllWindows(); ReleaseANSODHandle(&infHandle); std::cout << "End of program.\n"; return 0; } int ODHUBCVAPIImageTest(std::string modelFilePath, std::string imageFilePath) { boost::property_tree::ptree root; boost::property_tree::ptree detectionObjects; boost::property_tree::ptree pt; std::vector classes; std::filesystem::path currentPath = std::filesystem::current_path(); ANSCENTER::ANSODBase* infHandle; std::string labelMap; std::string modelZipFilePassword = ""; float modelThreshold = 0.7; float modelConfThreshold = 0.5; float modelNMSThreshold = 0.5; int modelType = 1;//ODHUBAPI ;1 is yolov4 opencv int detectorType = 1; std::string optmizedModelFolder; // Optimise model std::cout << "Optimizing model, please wait...." << std::endl; OptimizeModelStr(modelFilePath.c_str(), modelZipFilePassword.c_str(), modelType, 1,1, optmizedModelFolder); std::cout << "Model is optmized, run inference...." << std::endl; labelMap = CreateANSODHandle(&infHandle, "", modelFilePath.c_str(), modelZipFilePassword.c_str(), modelThreshold, modelConfThreshold, modelNMSThreshold, 1, modelType, detectorType); std::stringstream ss(labelMap); while (ss.good()) { std::string substr; getline(ss, substr, ','); classes.push_back(substr); } std::cout << "classes:" << classes.size(); std::cout << "begin read video" << std::endl; cv::Mat frame = cv::imread(imageFilePath, cv::IMREAD_COLOR); unsigned int bufferLength = 0; unsigned char* jpeg_string = ANSCENTER::ANSUtilityHelper::CVMatToBytes(frame, bufferLength); int height = frame.rows; int width = frame.cols; auto start = std::chrono::system_clock::now(); /* measured work */ std::string detectionResult = RunInferenceBinary(&infHandle, jpeg_string, width, height); auto end = std::chrono::system_clock::now(); auto elapsed = std::chrono::duration_cast(end - start); printf("Time = %lld ms\n", static_cast(elapsed.count())); std::cout << "Result:" << detectionResult << std::endl; delete jpeg_string; if (!detectionResult.empty()) { pt.clear(); std::stringstream ss; ss.clear(); ss << detectionResult; boost::property_tree::read_json(ss, pt); BOOST_FOREACH(const boost::property_tree::ptree::value_type & child, pt.get_child("results")) { const boost::property_tree::ptree& result = child.second; const auto class_id = GetData(result, "class_id"); const auto x = GetData(result, "x"); const auto y = GetData(result, "y"); const auto width = GetData(result, "width"); const auto height = GetData(result, "height"); cv::rectangle(frame, cv::Rect(x, y, width, height), 123, 2); cv::putText(frame, cv::format("%s:%d", classes[class_id], class_id), cv::Point(x, y - 5), 0, 0.6, cv::Scalar(255, 0, 0), 1, cv::LINE_AA); std::cout << "Keypoints =[" << GetData(result, "extra_info") << "]" << std::endl; } } resize(frame, frame, Size(frame.cols / 2, frame.rows / 2)); // to half size or even smaller namedWindow("Display frame", WINDOW_AUTOSIZE); cv::imshow("Display frame", frame); if (cv::waitKey(0) == 3) // Wait for 'esc' key press to exit { std::cout << "End of facial detection.\n"; } cv::destroyAllWindows(); ReleaseANSODHandle(&infHandle); std::cout << "End of program.\n"; return 0; } int CustomCodeImageTest(std::string modelFilePath, std::string imageFilePath) { boost::property_tree::ptree root; boost::property_tree::ptree detectionObjects; boost::property_tree::ptree pt; std::vector classes; std::filesystem::path currentPath = std::filesystem::current_path(); ANSCENTER::ANSODBase* infHandle; std::string labelMap; std::string modelZipFilePassword = ""; float modelThreshold = 0.7; float modelConfThreshold = 0.5; float modelNMSThreshold = 0.5; int modelType = 16;//Customized int detectorType = 1; std::string optmizedModelFolder; labelMap = CreateANSODHandle(&infHandle, "", modelFilePath.c_str(), modelZipFilePassword.c_str(), modelThreshold, modelConfThreshold, modelNMSThreshold, 1, modelType, detectorType); cv::Mat frame = cv::imread(imageFilePath, cv::IMREAD_COLOR); unsigned int bufferLength = 0; unsigned char* jpeg_string = ANSCENTER::ANSUtilityHelper::CVMatToBytes(frame, bufferLength); int height = frame.rows; int width = frame.cols; auto start = std::chrono::system_clock::now(); /* measured work */ std::string detectionResult = RunInferenceBinary(&infHandle, jpeg_string, width, height); auto end = std::chrono::system_clock::now(); auto elapsed = std::chrono::duration_cast(end - start); printf("Time = %lld ms\n", static_cast(elapsed.count())); std::cout << "Result:" << detectionResult << std::endl; delete jpeg_string; if (!detectionResult.empty()) { pt.clear(); std::stringstream ss; ss.clear(); ss << detectionResult; boost::property_tree::read_json(ss, pt); BOOST_FOREACH(const boost::property_tree::ptree::value_type & child, pt.get_child("results")) { const boost::property_tree::ptree& result = child.second; const auto class_id = GetData(result, "class_id"); const auto x = GetData(result, "x"); const auto y = GetData(result, "y"); const auto width = GetData(result, "width"); const auto height = GetData(result, "height"); cv::rectangle(frame, cv::Rect(x, y, width, height), 123, 2); cv::putText(frame, cv::format("%s:%d", "Test", class_id), cv::Point(x, y - 5), 0, 0.6, cv::Scalar(0, 0, 255), 1, cv::LINE_AA); std::cout << "Keypoints =[" << GetData(result, "extra_info") << "]" << std::endl; } } cv::imshow("ANS Object Tracking", frame); if (cv::waitKey(0) == 27) // Wait for 'esc' key press to exit { std::cout << "End of facial detection.\n"; } cv::destroyAllWindows(); ReleaseANSODHandle(&infHandle); std::cout << "End of program.\n"; return 0; } int FallDetection() { std::string cpumodelFilePath = "C:\\Projects\\ANSVIS\\Models\\ANS_FallDetection(CPU)_v1.0.zip"; std::string gpumodelFilePath = "C:\\Projects\\ANSVIS\\Models\\ANS_FallDetection(GPU)_v1.0.zip"; std::string videoFile = "C:\\Programs\\TrainingWorkingStation\\Projects\\FallDetection\\video\\Fall.mp4"; std::string MAFallVideo = "C:\\Programs\\DemoAssets\\Videos\\MAFall.mp4"; std::string cpumodelFilePathM = "C:\\Programs\\TrainingWorkingStation\\Projects\\FallDetection\\RawModelModified\\ANS_FallDetectionM(CPU)_v1.0.zip"; std::string gpumodelFilePathM = "C:\\Programs\\TrainingWorkingStation\\Projects\\FallDetection\\RawModelModified\\ANS_FallDetectionM(GPU)_v1.0.zip"; std::string odhubModelPath = "C:\\Programs\\DemoAssets\\Models\\Fall_ODHUB.zip"; //OpenVINOEngineUnitTest(cpumodelFilePathM, videoFile);//yolov8 //GPUEngineUnitTest(gpumodelFilePath, videoFile);// yolov8 ODHUBOpenCVAPITest(odhubModelPath, MAFallVideo); return 0; } int HeadDetection() { std::string cpumodelFilePath = "C:\\Programs\\DemoAssets\\ANSAIModels\\ANS_PeopleHead(CPU)_v1.zip"; std::string gpumodelFilePath = "C:\\ProgramData\\ANSCENTER\\ANSVIS Server\\Models\\ServerOptimised\\B-IN_ANS_PeopleHead(GPU)_v1.0_6111783b89cda8cf337ad2d60c8b2eea_NVIDIAGeForceRTX4070LaptopGPU.zip";// "C:\\Projects\\ANSVIS\\Models\\ANS_PeopleHead(GPU)_v1.0.zip"; std::string videoFile = "C:\\Programs\\DemoAssets\\Videos\\video_20.mp4"; // OpenVINOEngineUnitTest(gpumodelFilePath, videoFile);//yolov8 //OpenVINOEngineUnitTest(FallModelCPU, FallVideoFile);//yolov8 //OpenVINOEngineUnitTest(PPECPUMOdel, PPEVideoFile);//yolov8 GPUEngineUnitTest(gpumodelFilePath, videoFile);// yolov8 //GPUEngineUnitTest(PPEGPUMOdel, PPEVideoFile);// yolov8 return 0; } int FireNSmokeDetection() { std::string cpumodelFilePath = "C:\\Projects\\ANSVIS\\Models\\ANS_FireSmoke(CPU)_v1.0.zip"; std::string gpumodelFilePath = "C:\\Programs\\ModelExports\\ANS_FireSmoke(GPU)_v1.0\\ANS_FireSmoke(GPU)_v1.0.zip"; std::string gpumodel10FilePath = "C:\\Programs\\ModelExports\\HoangWork\\ANS_FireSmoke(GPU)_v2.0.zip"; std::string optimisedModelPath = "C:\\ProgramData\\ANSCENTER\\ANSVIS Server\\Models\\ServerOptimised\\B-IN_ANS_GenericOD(GPU)_v1.0_d52ffdcc7241b541fdcf17f2eff78b89_NVIDIAGeForceRTX4070LaptopGPU.zip"; std::string optimisedModelPath8 = "C:\\ProgramData\\ANSCENTER\\ANSVIS Server\\Models\\ServerOptimised\\B-IN_ANS_PeopleHead(GPU)_v1.0_6111783b89cda8cf337ad2d60c8b2eea_NVIDIAGeForceRTX4070LaptopGPU.zip"; std::string videoFile = "C:\\Programs\\DemoAssets\\Videos\\FireNSmoke\\Fire1.mp4"; //GPUYolov10EngineUnitTest(optimisedModelPath, videoFile);// yolov10 GPUEngineUnitTest(optimisedModelPath8, videoFile);// yolov8 //OpenVINOEngineUnitTest(cpumodelFilePath, videoFile);//yolov8 //GPUEngineUnitTest(gpumodelFilePath, videoFile);// yolov8 // ONNXEngineUnitTest(gpumodelFilePath, videoFile); return 0; } int VehicleDetection() { std::string cpumodelFilePath = "C:\\Programs\\DemoAssets\\ANSAIModels\\ANS_GenericVehicle8(CPU)_v1.0.zip"; std::string gpumodelFilePath = "C:\\Programs\\DemoAssets\\AIModels\\ODv8xGPUGeneric.zip"; std::string cpumodel10FilePath = "C:\\Programs\\DemoAssets\\ANSAIModels\\ANS_GenericVehicle(CPU)_v1.0.zip"; std::string gpumodel10FilePath = "C:\\Programs\\AIModels\\ANS_GenericOD(GPU)_v1.0.zip"; std::string videoFile = "C:\\Programs\\DemoAssets\\Videos\\road.mp4"; std::string hotelvideoFile = "C:\\Programs\\DemoAssets\\Videos\\video_20.mp4"; std::string testModel = "C:\\ProgramData\\ANSCENTER\\ANSVIS Server\\Models\\ServerOptimised\\B-IN_ANS_PeopleHead(GPU)_v1.0_6111783b89cda8cf337ad2d60c8b2eea_NVIDIAGeForceRTX4070LaptopGPU.zip"; // std::string testModel = "C:\\ProgramData\\ANSCENTER\\ANSVIS Server\\Models\\ServerOptimised\\B-IN_ANS_PeopleHead(GPU)_v1.0_6111783b89cda8cf337ad2d60c8b2eea_NVIDIARTXA500EmbeddedGPU.zip"; //GPUYolov10EngineUnitTest(gpumodel10FilePath, videoFile);// yolov10 //OpenVINOYolov10EngineUnitTestLoop(cpumodel10FilePath, videoFile);//yolov10 //OpenVINOEngineUnitTest(testModel, hotelvideoFile);//yolov8 GPUEngineUnitTest(testModel, hotelvideoFile);// yolov8 return 0; } void TestODHUB() { std::string odhubModelPath = "C:\\Programs\\DemoAssets\\ANSAIModels\\Models\\openflapmulticat_v1.zip"; std::string odhubVideoPath = "C:\\Programs\\DemoAssets\\Videos\\openflap.mp4"; ODHUBAPITest(odhubModelPath, odhubVideoPath); //ODHUBOpenCVAPITest(odhubModelPath, odhubVideoPath); } void DissemTest() { std::string odhubModelPath = "C:\\Workstation\\CustomerSupport\\Dissem\\EngineTest\\Test_Model Type\\20240705_Waper_1.zip"; std::string odhubImagePath = "C:\\Workstation\\CustomerSupport\\Dissem\\EngineTest\\Test_Model Type\\0711_10_0051.jpg"; //ODHUBAPIImageTest(odhubModelPath, odhubImagePath); ODHUBCVAPIImageTest(odhubModelPath, odhubImagePath); } int DissemParallelTest(std::string modelFilePath, std::string imageFilePath) { boost::property_tree::ptree root; boost::property_tree::ptree detectionObjects; boost::property_tree::ptree pt; std::vector classes; std::filesystem::path currentPath = std::filesystem::current_path(); ANSCENTER::ANSODBase* infHandle; std::string labelMap; std::string modelZipFilePassword = ""; float modelThreshold = 0.7; float modelConfThreshold = 0.5; float modelNMSThreshold = 0.5; int modelType = 13;//ODHUBAPI ;1 is yolov4 opencv int detectorType = 1; std::string optmizedModelFolder; // Optimise model std::cout << "Optimizing model, please wait...." << std::endl; OptimizeModelStr(modelFilePath.c_str(), modelZipFilePassword.c_str(), modelType, 1,1, optmizedModelFolder); std::cout << "Model is optmized, run inference...." << std::endl; labelMap = CreateANSODHandle(&infHandle, "", modelFilePath.c_str(), modelZipFilePassword.c_str(), modelThreshold, modelConfThreshold, modelNMSThreshold, 1, modelType, detectorType); std::stringstream ss(labelMap); while (ss.good()) { std::string substr; getline(ss, substr, ','); classes.push_back(substr); } std::cout << "classes:" << classes.size(); std::cout << "begin read video" << std::endl; cv::Mat frame = cv::imread(imageFilePath, cv::IMREAD_COLOR); unsigned int bufferLength = 0; unsigned char* jpeg_string = ANSCENTER::ANSUtilityHelper::CVMatToBytes(frame, bufferLength); int height = frame.rows; int width = frame.cols; auto start = std::chrono::system_clock::now(); /* measured work */ std::string detectionResult = RunInferenceBinary(&infHandle, jpeg_string, width, height); auto end = std::chrono::system_clock::now(); auto elapsed = std::chrono::duration_cast(end - start); printf("Time = %lld ms\n", static_cast(elapsed.count())); std::cout << "Result:" << detectionResult << std::endl; delete jpeg_string; if (!detectionResult.empty()) { pt.clear(); std::stringstream ss; ss.clear(); ss << detectionResult; boost::property_tree::read_json(ss, pt); BOOST_FOREACH(const boost::property_tree::ptree::value_type & child, pt.get_child("results")) { const boost::property_tree::ptree& result = child.second; const auto class_id = GetData(result, "class_id"); const auto x = GetData(result, "x"); const auto y = GetData(result, "y"); const auto width = GetData(result, "width"); const auto height = GetData(result, "height"); cv::rectangle(frame, cv::Rect(x, y, width, height), 123, 2); cv::putText(frame, cv::format("%s:%d", classes[class_id], class_id), cv::Point(x, y - 5), 0, 0.6, cv::Scalar(255, 0, 0), 1, cv::LINE_AA); std::cout << "Keypoints =[" << GetData(result, "extra_info") << "]" << std::endl; } } resize(frame, frame, Size(frame.cols / 2, frame.rows / 2)); // to half size or even smaller namedWindow("Display frame", WINDOW_AUTOSIZE); cv::imshow("Display frame", frame); if (cv::waitKey(0) == 3) // Wait for 'esc' key press to exit { std::cout << "End of facial detection.\n"; } cv::destroyAllWindows(); ReleaseANSODHandle(&infHandle); std::cout << "End of program.\n"; return 0; } int CustomTest() { std::string customModelPath = "C:\\Programs\\DemoAssets\\AIModels\\ANSCustomFaceDetector.zip"; std::string imageDataPath = "C:\\Projects\\ANSVISCustomFunction\\Examples\\FaceDetector\\test.jpg"; CustomCodeImageTest(customModelPath, imageDataPath); return 0; } int CocoTest() { std::string gpumodelFilePath = "C:\\ProgramData\\ANSCENTER\\Shared\\ANS_Coco_format(GPU)_1.zip"; std::string imageFile = "C:\\ProgramData\\ANSCENTER\\Shared\\20240620_132740_256.jpg"; GPUEngineImageTest(gpumodelFilePath, imageFile); return 0; } int FaceDetector(std::string modelFilePath, std::string videoFilePath) { boost::property_tree::ptree root; boost::property_tree::ptree detectionObjects; boost::property_tree::ptree pt; std::vector classes; std::filesystem::path currentPath = std::filesystem::current_path(); ANSCENTER::ANSODBase* infHandle; std::string labelMap; std::string licenseKey = ""; std::string modelZipFilePassword = ""; float modelThreshold = 0.5; float modelConfThreshold = 0.5; float modelNMSThreshold = 0.5; int modelType = 6;//Facial int detectorType = 1; // Detection // Optimise model std::cout << "Model is optmized, run inference...." << std::endl; labelMap = CreateANSODHandle(&infHandle, licenseKey.c_str(), modelFilePath.c_str(), modelZipFilePassword.c_str(), modelThreshold, modelConfThreshold, modelNMSThreshold, 1, modelType, detectorType); std::stringstream ss(labelMap); while (ss.good()) { std::string substr; getline(ss, substr, ','); classes.push_back(substr); } std::cout << "classes:" << classes.size(); std::cout << "begin read video" << std::endl; cv::VideoCapture capture(videoFilePath); if (!capture.isOpened()) { printf("could not read this video file...\n"); return -1; } std::cout << "end read video" << std::endl; while (true) { cv::Mat frame; if (!capture.read(frame)) // if not success, break loop { std::cout << "\n Cannot read the video file. please check your video.\n"; break; } unsigned int bufferLength = 0; unsigned char* jpeg_string = ANSCENTER::ANSUtilityHelper::CVMatToBytes(frame, bufferLength); int height = frame.rows; int width = frame.cols; auto start = std::chrono::system_clock::now(); /* measured work */ std::string detectionResult = RunInferenceBinary(&infHandle, jpeg_string, width, height); auto end = std::chrono::system_clock::now(); auto elapsed = std::chrono::duration_cast(end - start); printf("Time = %lld ms\n", static_cast(elapsed.count())); delete jpeg_string; if (!detectionResult.empty()) { pt.clear(); std::stringstream ss; ss.clear(); ss << detectionResult; boost::property_tree::read_json(ss, pt); BOOST_FOREACH(const boost::property_tree::ptree::value_type & child, pt.get_child("results")) { const boost::property_tree::ptree& result = child.second; const auto class_id = GetData(result, "class_id"); const auto x = GetData(result, "x"); const auto y = GetData(result, "y"); const auto width = GetData(result, "width"); const auto height = GetData(result, "height"); cv::rectangle(frame, cv::Rect(x, y, width, height), 123, 2); cv::putText(frame, cv::format("%s:%d", classes[class_id], class_id), cv::Point(x, y - 5), 0, 0.6, cv::Scalar(0, 0, 255), 1, cv::LINE_AA); } } cv::imshow("ANS Object Tracking", frame); if (cv::waitKey(30) == 27) // Wait for 'esc' key press to exit { break; } } capture.release(); cv::destroyAllWindows(); ReleaseANSODHandle(&infHandle); std::cout << "End of program.\n"; return 0; } int TiledInferenceTest(std::string modelFilePath, std::string imageFilePath) { boost::property_tree::ptree root; boost::property_tree::ptree detectionObjects; boost::property_tree::ptree pt; std::vector classes; std::filesystem::path currentPath = std::filesystem::current_path(); ANSCENTER::ANSODBase* infHandle; std::string labelMap; std::string modelZipFilePassword = ""; float modelThreshold = 0.55; float modelConfThreshold = 5; float modelNMSThreshold = 0.5; int modelType = 14;// int detectorType = 1; std::string optmizedModelFolder; // Optimise model std::cout << "Optimizing model, please wait...." << std::endl; OptimizeModelStr(modelFilePath.c_str(), modelZipFilePassword.c_str(), modelType,1, 1, optmizedModelFolder); std::cout << "Model is optmized, run inference...." << std::endl; labelMap = CreateANSODHandle(&infHandle, "", modelFilePath.c_str(), modelZipFilePassword.c_str(), modelThreshold, modelConfThreshold, modelNMSThreshold, 1, modelType, detectorType); std::stringstream ss(labelMap); while (ss.good()) { std::string substr; getline(ss, substr, ','); classes.push_back(substr); } cv::Mat frame = cv::imread(imageFilePath, cv::IMREAD_COLOR); auto start1 = std::chrono::system_clock::now(); std::vector imageData; bool success = cv::imencode(".jpg", frame, imageData); if (!success) { std::cout << "Failed to encode the image" << std::endl; return 0; } std::string jpegImage(imageData.begin(), imageData.end()); int height = frame.rows; int width = frame.cols; auto start = std::chrono::system_clock::now(); std::string detectionResult = RunTiledInferenceFromJpegString(&infHandle, jpegImage.c_str(), imageData.size(), 640, 640, 0.2, "TestCam"); auto end = std::chrono::system_clock::now(); auto elapsed = std::chrono::duration_cast(end - start); printf("Time = %lld ms\n", static_cast(elapsed.count())); std::cout << "Result:" << detectionResult << std::endl; if (!detectionResult.empty()) { pt.clear(); std::stringstream ss; ss.clear(); ss << detectionResult; boost::property_tree::read_json(ss, pt); BOOST_FOREACH(const boost::property_tree::ptree::value_type & child, pt.get_child("results")) { const boost::property_tree::ptree& result = child.second; const auto class_id = GetData(result, "class_id"); const auto x = GetData(result, "x"); const auto y = GetData(result, "y"); const auto width = GetData(result, "width"); const auto height = GetData(result, "height"); cv::rectangle(frame, cv::Rect(x, y, width, height), 123, 2); //cv::putText(frame, cv::format("%s:%d", classes[class_id], class_id), cv::Point(x, y - 5), // 0, 0.6, cv::Scalar(255, 0, 0), 1, cv::LINE_AA); // std::cout << "Keypoints =[" << GetData(result, "extra_info") << "]" << std::endl; } } //resize(frame, frame, Size(frame.cols / 2, frame.rows / 2)); // to half size or even smaller //namedWindow("Display frame", WINDOW_AUTOSIZE); cv::imshow("Display frame", frame); if (cv::waitKey(0) == 3) // Wait for 'esc' key press to exit { std::cout << "End of facial detection.\n"; } cv::destroyAllWindows(); ReleaseANSODHandle(&infHandle); std::cout << "End of program.\n"; return 0; } int NormalInferenceTest(std::string modelFilePath, std::string imageFilePath) { boost::property_tree::ptree root; boost::property_tree::ptree detectionObjects; boost::property_tree::ptree pt; std::vector classes; std::filesystem::path currentPath = std::filesystem::current_path(); ANSCENTER::ANSODBase* infHandle; std::string labelMap; std::string modelZipFilePassword = ""; float modelThreshold = 0.55; float modelConfThreshold = 5; float modelNMSThreshold = 0.5; int modelType = 14;// int detectorType = 1; std::string optmizedModelFolder; // Optimise model std::cout << "Optimizing model, please wait...." << std::endl; OptimizeModelStr(modelFilePath.c_str(), modelZipFilePassword.c_str(), modelType,1, 1, optmizedModelFolder); std::cout << "Model is optmized, run inference...." << std::endl; labelMap = CreateANSODHandle(&infHandle, "", modelFilePath.c_str(), modelZipFilePassword.c_str(), modelThreshold, modelConfThreshold, modelNMSThreshold, 1, modelType, detectorType); std::stringstream ss(labelMap); while (ss.good()) { std::string substr; getline(ss, substr, ','); classes.push_back(substr); } cv::Mat frame = cv::imread(imageFilePath, cv::IMREAD_COLOR); auto start1 = std::chrono::system_clock::now(); std::vector imageData; bool success = cv::imencode(".jpg", frame, imageData); if (!success) { std::cout << "Failed to encode the image" << std::endl; return 0; } std::string jpegImage(imageData.begin(), imageData.end()); int height = frame.rows; int width = frame.cols; auto start = std::chrono::system_clock::now(); std::string detectionResult = RunInferenceFromJpegString(&infHandle, jpegImage.c_str(), imageData.size(), "TestCam"); auto end = std::chrono::system_clock::now(); auto elapsed = std::chrono::duration_cast(end - start); printf("Time = %lld ms\n", static_cast(elapsed.count())); std::cout << "Result:" << detectionResult << std::endl; if (!detectionResult.empty()) { pt.clear(); std::stringstream ss; ss.clear(); ss << detectionResult; boost::property_tree::read_json(ss, pt); BOOST_FOREACH(const boost::property_tree::ptree::value_type & child, pt.get_child("results")) { const boost::property_tree::ptree& result = child.second; const auto class_id = GetData(result, "class_id"); const auto x = GetData(result, "x"); const auto y = GetData(result, "y"); const auto width = GetData(result, "width"); const auto height = GetData(result, "height"); cv::rectangle(frame, cv::Rect(x, y, width, height), 123, 2); /* cv::putText(frame, cv::format("%s:%d", classes[class_id], class_id), cv::Point(x, y - 5), 0, 0.6, cv::Scalar(255, 0, 0), 1, cv::LINE_AA);*/ // std::cout << "Keypoints =[" << GetData(result, "extra_info") << "]" << std::endl; } } //resize(frame, frame, Size(frame.cols / 2, frame.rows / 2)); // to half size or even smaller namedWindow("Display frame", WINDOW_AUTOSIZE); cv::imshow("Display frame", frame); if (cv::waitKey(0) == 3) // Wait for 'esc' key press to exit { std::cout << "End of facial detection.\n"; } cv::destroyAllWindows(); ReleaseANSODHandle(&infHandle); std::cout << "End of program.\n"; return 0; } int TiledInferenceTest() { std::string modelFilePath = "C:\\ProgramData\\ANSCENTER\\Shared\\ANS_GenericOD(GPU)_v1.0.zip"; std::string imageFilePath = "C:\\Programs\\DemoAssets\\Images\\SAHI\\smallobjects.jpeg"; //TiledInferenceTest(modelFilePath, imageFilePath); NormalInferenceTest(modelFilePath, imageFilePath); return 0; } int MotionDetection(std::string modelFilePath, std::string videoFilePath) { boost::property_tree::ptree root; boost::property_tree::ptree detectionObjects; boost::property_tree::ptree pt; std::vector classes; std::filesystem::path currentPath = std::filesystem::current_path(); ANSCENTER::ANSODBase* infHandle; std::string labelMap; std::string licenseKey = ""; std::string modelZipFilePassword = ""; float detectionScoreThreshold = 0.2; float modelConfThreshold = 0.48; float modelNMSThreshold = 0.48; int modelType = 17; // ANSFIRESMOKE int detectorType = 1; // Detection labelMap = CreateANSODHandle(&infHandle, licenseKey.c_str(), modelFilePath.c_str(), modelZipFilePassword.c_str(), detectionScoreThreshold, modelConfThreshold, modelNMSThreshold, 1, modelType, detectorType); std::stringstream ss(labelMap); while (ss.good()) { std::string substr; getline(ss, substr, ','); classes.push_back(substr); } std::cout << "classes:" << classes.size(); std::cout << "classes:" << classes.size() << std::endl; while (true) { std::cout << "begin read video" << std::endl; cv::VideoCapture capture(videoFilePath); if (!capture.isOpened()) { printf("could not read this video file...\n"); return -1; } std::cout << "end read video" << std::endl; while (true) { cv::Mat frame; if (!capture.read(frame)) { std::cout << "\n Cannot read the video file. Restarting...\n"; capture.set(cv::CAP_PROP_POS_FRAMES, 0); // Reset to the beginning of the video continue; } unsigned int bufferLength = 0; //cv::Mat croppedFrame = frame(cv::Rect(0, 0, 1920, 1080)); auto start1 = std::chrono::system_clock::now(); //std::vector imageData; //bool success = cv::imencode(".jpg", frame, imageData); //if (!success) { // std::cout << "Failed to encode the image" << std::endl; // break; //} //std::string jpegImage(imageData.begin(), imageData.end()); auto end1 = std::chrono::system_clock::now(); auto elapsed1 = std::chrono::duration_cast(end1 - start1); //printf("Conversion Time = %lld ms\n", static_cast(elapsed1.count())); int height = frame.rows; int width = frame.cols; auto start = std::chrono::system_clock::now(); /* measured work */ std::string detectionResult = RunInferenceFromCV(&infHandle, frame);//RunInferenceFromJpegString(&infHandle, jpegImage.c_str(), imageData.size());// , 100, 100, 0.2); auto end = std::chrono::system_clock::now(); auto elapsed = std::chrono::duration_cast(end - start); printf("Time = %lld ms\n", static_cast(elapsed.count())); if (!detectionResult.empty()) { pt.clear(); std::stringstream ss; ss.clear(); ss << detectionResult; boost::property_tree::read_json(ss, pt); BOOST_FOREACH(const boost::property_tree::ptree::value_type & child, pt.get_child("results")) { const boost::property_tree::ptree& result = child.second; const auto class_id = GetData(result, "class_id"); const auto x = GetData(result, "x"); const auto y = GetData(result, "y"); const auto prob = GetData(result, "prob"); const auto width = GetData(result, "width"); const auto height = GetData(result, "height"); cv::rectangle(frame, cv::Rect(x, y, width, height), 123, 2); cv::putText(frame, cv::format("%s:%d:%.2f", classes[class_id], class_id, prob), cv::Point(x, y - 5), 0, 0.6, cv::Scalar(0, 0, 255), 1, cv::LINE_AA); } } cv::imshow("ANS Object Tracking", frame); if (cv::waitKey(30) == 27) { // Wait for 'esc' key press to exit capture.release(); cv::destroyAllWindows(); ReleaseANSODHandle(&infHandle); std::cout << "End of program.\n"; return 0; } } } } int MotionDetectionForFireNSmoke() { std::string cpumodelFilePath = "C:\\Projects\\ANSVIS\\Models\\ANS_FireSmoke(CPU)_v1.0.zip"; std::string gpumodelFilePath = "C:\\Projects\\ANSVIS\\Models\\ANS_FireSmoke(GPU)_v1.0.zip"; std::string videoFile = "C:\\Programs\\DemoAssets\\Videos\\FireNSmoke\\BCA2.mp4"; //std::string videoFile = "C:\\Programs\\DemoAssets\\Videos\\FireNSmoke\\Fire25m.mp4"; //std::string videoFile = "C:\\Programs\\DemoAssets\\Videos\\FireNSmoke\\fire2.mp4"; //std::string videoFile = "C:\\Programs\\DemoAssets\\Videos\\FireNSmoke\\ANSFireFull.mp4"; // std::string videoFile = "C:\\Programs\\DemoAssets\\Videos\\video_20.mp4"; // std::string videoFile = "C:\\Programs\\DemoAssets\\Videos\\road.mp4"; //GPUYolov10EngineUnitTest(gpumodel10FilePath, videoFile);// yolov10 MotionDetection(gpumodelFilePath, videoFile);//yolov10 //OpenVINOEngineUnitTest(cpumodelFilePath, videoFile);//yolov8 //GPUEngineUnitTest(gpumodelFilePath, videoFile);// yolov8 return 0; } int StressTest() { std::string gpumodelFilePath = "C:\\Projects\\ANSVIS\\Models\\ANS_PeopleHead(GPU)_v1.0.zip"; std::string imageFile = "C:\\Programs\\DemoAssets\\Images\\bus.jpg"; for (int i = 0; i < 100; i++) { std::cout << "Test:" << i << std::endl; GPUEngineImageTest(gpumodelFilePath, imageFile); } } int OpenVINOCLEngineImageTest(std::string modelFilePath, std::string imageFilePath) { boost::property_tree::ptree root; boost::property_tree::ptree detectionObjects; boost::property_tree::ptree pt; std::vector classes; std::filesystem::path currentPath = std::filesystem::current_path(); ANSCENTER::ANSODBase* infHandle; std::string labelMap; std::string licenseKey = ""; std::string modelZipFilePassword = ""; float modelThreshold = 0.5; float modelConfThreshold = 0.5; float modelNMSThreshold = 0.5; int modelType = 5;//OpenVINO int detectorType = 0;// Classification std::string optmizedModelFolder; // Optimise model std::cout << "Optimizing model, please wait...." << std::endl; OptimizeModelStr(modelFilePath.c_str(), modelZipFilePassword.c_str(), modelType,1, 1, optmizedModelFolder); std::cout << "Model is optmized, run inference...." << std::endl; labelMap = CreateANSODHandle(&infHandle, licenseKey.c_str(), modelFilePath.c_str(), modelZipFilePassword.c_str(), modelThreshold, modelConfThreshold, modelNMSThreshold, 1, modelType, detectorType); std::stringstream ss(labelMap); while (ss.good()) { std::string substr; getline(ss, substr, ','); classes.push_back(substr); } cv::Mat frame = cv::imread(imageFilePath, cv::IMREAD_COLOR); unsigned int bufferLength = 0; unsigned char* jpeg_string = ANSCENTER::ANSUtilityHelper::CVMatToBytes(frame, bufferLength); int height = frame.rows; int width = frame.cols; auto start = std::chrono::system_clock::now(); /* measured work */ std::string detectionResult = RunInferenceBinary(&infHandle, jpeg_string, width, height); auto end = std::chrono::system_clock::now(); auto elapsed = std::chrono::duration_cast(end - start); printf("Time = %lld ms\n", static_cast(elapsed.count())); std::cout << "Result:" << detectionResult << std::endl; delete jpeg_string; if (!detectionResult.empty()) { pt.clear(); std::stringstream ss; ss.clear(); ss << detectionResult; boost::property_tree::read_json(ss, pt); BOOST_FOREACH(const boost::property_tree::ptree::value_type & child, pt.get_child("results")) { const boost::property_tree::ptree& result = child.second; const auto class_id = GetData(result, "class_id"); const auto x = GetData(result, "x"); const auto y = GetData(result, "y"); const auto width = GetData(result, "width"); const auto height = GetData(result, "height"); cv::rectangle(frame, cv::Rect(x, y, width, height), 123, 2); cv::putText(frame, cv::format("%s:%d", classes[class_id], class_id), cv::Point(x, y - 5), 0, 0.6, cv::Scalar(0, 0, 255), 1, cv::LINE_AA); std::cout << "Keypoints =[" << GetData(result, "extra_info") << "]" << std::endl; } } cv::imshow("ANS Object Tracking", frame); if (cv::waitKey(0) == 0) // Wait for 'esc' key press to exit { std::cout << "End of facial detection.\n"; } cv::destroyAllWindows(); ReleaseANSODHandle(&infHandle); std::cout << "End of program.\n"; return 0; } int TENSORRTCLEngineImageTest(std::string modelFilePath, std::string imageFilePath) { boost::property_tree::ptree root; boost::property_tree::ptree detectionObjects; boost::property_tree::ptree pt; std::vector classes; std::filesystem::path currentPath = std::filesystem::current_path(); ANSCENTER::ANSODBase* infHandle; std::string labelMap; std::string licenseKey = ""; std::string modelZipFilePassword = ""; float modelThreshold = 0.5; float modelConfThreshold = 0.5; float modelNMSThreshold = 0.5; int modelType = 4;//OpenVINO int detectorType = 0;// Classification std::string optmizedModelFolder; // Optimise model std::cout << "Optimizing model, please wait...." << std::endl; OptimizeModelStr(modelFilePath.c_str(), modelZipFilePassword.c_str(), modelType,1, 1, optmizedModelFolder); std::cout << "Model is optmized, run inference...." << std::endl; labelMap = CreateANSODHandle(&infHandle, licenseKey.c_str(), modelFilePath.c_str(), modelZipFilePassword.c_str(), modelThreshold, modelConfThreshold, modelNMSThreshold, 1, modelType, detectorType); std::stringstream ss(labelMap); while (ss.good()) { std::string substr; getline(ss, substr, ','); classes.push_back(substr); } cv::Mat frame = cv::imread(imageFilePath, cv::IMREAD_COLOR); unsigned int bufferLength = 0; unsigned char* jpeg_string = ANSCENTER::ANSUtilityHelper::CVMatToBytes(frame, bufferLength); int height = frame.rows; int width = frame.cols; auto start = std::chrono::system_clock::now(); /* measured work */ std::string detectionResult = RunInferenceBinary(&infHandle, jpeg_string, width, height); auto end = std::chrono::system_clock::now(); auto elapsed = std::chrono::duration_cast(end - start); printf("Time = %lld ms\n", static_cast(elapsed.count())); std::cout << "Result:" << detectionResult << std::endl; delete jpeg_string; if (!detectionResult.empty()) { pt.clear(); std::stringstream ss; ss.clear(); ss << detectionResult; boost::property_tree::read_json(ss, pt); BOOST_FOREACH(const boost::property_tree::ptree::value_type & child, pt.get_child("results")) { const boost::property_tree::ptree& result = child.second; const auto class_id = GetData(result, "class_id"); const auto x = GetData(result, "x"); const auto y = GetData(result, "y"); const auto width = GetData(result, "width"); const auto height = GetData(result, "height"); cv::rectangle(frame, cv::Rect(x, y, width, height), 123, 2); cv::putText(frame, cv::format("%s:%d", classes[class_id], class_id), cv::Point(x, y - 5), 0, 0.6, cv::Scalar(0, 0, 255), 1, cv::LINE_AA); std::cout << "Keypoints =[" << GetData(result, "extra_info") << "]" << std::endl; } } cv::imshow("ANS Object Tracking", frame); if (cv::waitKey(0) == 0) // Wait for 'esc' key press to exit { std::cout << "End of facial detection.\n"; } cv::destroyAllWindows(); ReleaseANSODHandle(&infHandle); std::cout << "End of program.\n"; return 0; } int TestCL() { std::string cpumodelFilePath = "C:\\Programs\\DemoAssets\\AIModels\\ANSFireNSmokeCL(CPU).zip"; std::string gpumodelFilePath = "C:\\Programs\\DemoAssets\\AIModels\\ANSFireNSmokeCL(GPU).zip"; std::string imageFile = "C:\\Programs\\DemoAssets\\TestImages\\FireNSmoke\\smoke\\test1.jpg"; //std::string imageFile = "C:\\Programs\\DemoAssets\\Images\\bus.jpg"; TENSORRTCLEngineImageTest(gpumodelFilePath, imageFile); } int Engine_Test() { std::string gpumodelFilePath = "C:\\ProgramData\\ANSCENTER\\Shared\\ANS_GenericOD(GPU)_v1.0.zip"; std::string imageFile = "C:\\ProgramData\\ANSCENTER\\Shared\\bus.jpg"; GPUEngineImageTest(gpumodelFilePath, imageFile); } int SegEngineImageTest(std::string modelFilePath, std::string imageFilePath) { boost::property_tree::ptree root; boost::property_tree::ptree detectionObjects; boost::property_tree::ptree pt; std::vector classes; std::filesystem::path currentPath = std::filesystem::current_path(); ANSCENTER::ANSODBase* infHandle; std::string labelMap; std::string licenseKey = ""; std::string modelZipFilePassword = ""; float modelThreshold = 0.5; float modelConfThreshold = 0.5; float modelNMSThreshold = 0.5; int modelType = 5;//OpenVINO int detectorType = 2;// Segmentation std::string optmizedModelFolder; // Optimise model std::cout << "Optimizing model, please wait...." << std::endl; OptimizeModelStr(modelFilePath.c_str(), modelZipFilePassword.c_str(), modelType, 1,1, optmizedModelFolder); std::cout << "Model is optmized, run inference...." << std::endl; labelMap = CreateANSODHandle(&infHandle, licenseKey.c_str(), modelFilePath.c_str(), modelZipFilePassword.c_str(), modelThreshold, modelConfThreshold, modelNMSThreshold, 1, modelType, detectorType); std::stringstream ss(labelMap); while (ss.good()) { std::string substr; getline(ss, substr, ','); classes.push_back(substr); } cv::Mat frame = cv::imread(imageFilePath, cv::IMREAD_COLOR); unsigned int bufferLength = 0; unsigned char* jpeg_string = ANSCENTER::ANSUtilityHelper::CVMatToBytes(frame, bufferLength); int height = frame.rows; int width = frame.cols; auto start = std::chrono::system_clock::now(); /* measured work */ std::string detectionResult = RunInferenceBinary(&infHandle, jpeg_string, width, height); auto end = std::chrono::system_clock::now(); auto elapsed = std::chrono::duration_cast(end - start); printf("Time = %lld ms\n", static_cast(elapsed.count())); std::cout << "Result:" << detectionResult << std::endl; delete jpeg_string; if (!detectionResult.empty()) { pt.clear(); std::stringstream ss; ss.clear(); ss << detectionResult; boost::property_tree::read_json(ss, pt); BOOST_FOREACH(const boost::property_tree::ptree::value_type & child, pt.get_child("results")) { const boost::property_tree::ptree& result = child.second; const auto class_id = GetData(result, "class_id"); const auto x = GetData(result, "x"); const auto y = GetData(result, "y"); const auto width = GetData(result, "width"); const auto height = GetData(result, "height"); cv::rectangle(frame, cv::Rect(x, y, width, height), 123, 2); cv::putText(frame, cv::format("%s:%d", classes[class_id], class_id), cv::Point(x, y - 5), 0, 0.6, cv::Scalar(0, 0, 255), 1, cv::LINE_AA); std::cout << "Keypoints =[" << GetData(result, "extra_info") << "]" << std::endl; } } //cv::imshow("ANS Object Tracking", frame); //if (cv::waitKey(0) == 0) // Wait for 'esc' key press to exit //{ // std::cout << "End of facial detection.\n"; //} cv::destroyAllWindows(); ReleaseANSODHandle(&infHandle); std::cout << "End of program.\n"; return 0; } int SegmentationTest() { std::string segmodelFilePath = "C:\\Programs\\TrainingToolTest\\SegmentationEngine\\SegmeTxtYolo\\Models\\ANS_MySegmentation(CPU)_1.zip"; // std::string segmodelFilePath = "C:\\Programs\\TrainingToolTest\\SegmentationEngine\\SegmeTxtYolo\\Models\\Yolov8\\ANS_MySegmentation(CPU)_1.zip"; std::string imageFile = "C:\\Programs\\TrainingToolTest\\SegmentationEngine\\SegmeTxtYolo\\data\\20241220_173948_695.jpg"; //std::string imageFile = "C:\\Programs\\DemoAssets\\Images\\bus.jpg"; SegEngineImageTest(segmodelFilePath, imageFile); } int LocSetTest() { std::string gpumodelFilePath = "C:\\Programs\\LocSet\\LocSetGPU_v1.0.zip"; std::string cpumodelFilePath = "C:\\Programs\\LocSet\\LocSetCPU_v1.0.zip"; std::string yolov8ModeFilePath = "C:\\Programs\\Yolov8\\Yolov8_General\\ANS_GenericODM.zip";//"C:\\Programs\\LocSet\\LocSet_v1.0.zip";// std::string videoFilePath = "C:\\Programs\\LocSet\\loc_set 1.mp4"; std::string videoFile = "C:\\Programs\\DemoAssets\\Videos\\video_20.mp4"; Yolov8EngineUnitTest(yolov8ModeFilePath, videoFile); //GPUEngineUnitTest(gpumodelFilePath, videoFilePath); //OpenVINOEngineUnitTest(cpumodelFilePath, videoFilePath); //GPUYolov10EngineUnitTest(cpumodelFilePath, videoFilePath); } int PPETest() { //std::string gpumodelFilePath = "C:\\Programs\\DemoAssets\\ANSAIModels\\Models\\PPEGPU.zip"; std::string gpumodelFilePath = "C:\\Programs\\Yolov8\\ANS_PPE(GPU)_v3.0.zip"; std::string videoFilePath = "C:\\Programs\\DemoAssets\\Videos\\Factory1.mp4"; Yolov8EngineUnitTest(gpumodelFilePath, videoFilePath); return 1; } int RectifierTest() { std::string Yolov5Model = "C:\\Programs\\Yolov5\\Rectifier_v1.zip"; std::string videoFilePath = "C:\\Programs\\Yolov5\\rectifier.mp4"; //std::string videoFile = "C:\\Programs\\DemoAssets\\Videos\\video_20.mp4"; //GPUEngineUnitTest(yolov5ModeFilePaht, videoFile);// Yolov5EngineUnitTest(Yolov5Model, videoFilePath); } int FaceTest() { std::string facemodeFile = "C:\\ProgramData\\ANSCENTER\\Shared\\ANS_GenericFD(GPU)_v1.0.zip"; std::string video = "C:\\Programs\\DemoAssets\\Videos\\BMIP.mp4"; FaceDetector(facemodeFile, video); return 0; } int FaceOVTest() { std::string facemodeFile = "C:\\ProgramData\\ANSCENTER\\Shared\\ANS_GenericFD(CPU)_v1.0.zip"; std::string imagePath = "C:\\Programs\\DemoAssets\\TestImages\\Face\\Hoang2.jpg";// "C:\\Programs\\DemoAssets\\Images\\Tien\\80.jpg"; FacialDetectorTest(facemodeFile, imagePath);// yolov8 return 0; } int FaceYoloTest() { std::string facecpumodeFile = "C:\\Projects\\ANSVIS\\Models\\ANS_Face(CPU)_v1.0.zip"; std::string facegpumodeFile = "C:\\Projects\\ANSVIS\\Models\\ANS_Face(GPU)_v1.0.zip"; std::string video = "C:\\Programs\\DemoAssets\\Videos\\classroom.mp4"; OpenVINOEngineUnitTest(facecpumodeFile, video);//yolov8 // GPUEngineUnitTest(facegpumodeFile, video);// yolov8 return 0; } int Yolov11RT_Test() { std::string gpumodelFilePath = "C:\\Users\\nghia\\Downloads\\Generic11GPU.zip";// "C:\\Programs\\DemoAssets\\AIModels\\ANS_PersonHead(GPU)_1.zip"; std::string cpumodelFilePath = "C:\\Programs\\DemoAssets\\AIModels\\ODv11nCPUGeneric.zip"; std::string imageFile = "C:\\Programs\\DemoAssets\\Images\\bus.jpg"; std::string videoFile = "C:\\Programs\\DemoAssets\\Videos\\video_20.mp4"; std::string videoFilePath = "C:\\Programs\\DemoAssets\\Videos\\classroom.mp4"; // GPU11EngineImageTest(gpumodelFilePath, imageFile); GPUEngineUnitTest(gpumodelFilePath, videoFile); //OpenVINOEngineUnitTest(cpumodelFilePath, videoFile); } int Yolov10RT_Test() { std::string gpumodelFilePath = "C:\\ProgramData\\ANSCENTER\\Shared\\ANS_GenericOD(GPU)_v1.0.zip"; std::string videoFilePath = "C:\\Programs\\DemoAssets\\Videos\\classroom.mp4"; GPUYolov10EngineUnitTest(gpumodelFilePath, videoFilePath); } int TestYOLOV12() { std::string modelPath = "C:\\Programs\\Yolov12\\GenericYolov12.zip"; std::string videoFile = "C:\\Programs\\DemoAssets\\Videos\\FireNSmoke\\SimFire.mp4"; Yolov12EngineUnitTest(modelPath, videoFile); } int GenericModelTest() { //std::string cpumodelFilePath = "C:\\ProgramData\\ANSCENTER\\Shared\\ANS_GenericOD(CPU)_v1.0.zip"; std::string gpumodelFilePath = "C:\\ProgramData\\ANSCENTER\\Shared\\ANS_GenericOD(GPU)_v1.0.zip";// "C:\\ProgramData\\ANSCENTER\\ANSVIS Server\\Models\\B-IN_ANS_PeopleHead(GPU)_v1.0_54a7944906d79395a9840945d3c24b9a.zip";// "C:\\ProgramData\\ANSCENTER\\Shared\\ANS_GenericOD(GPU)_v1.0.zip"; //std::string gpumodelFilePath = "C:\\ProgramData\\ANSCENTER\\ANSVIS Server\\Models\\ServerOptimised\\B-IN_ANS_GenericOD(GPU)_v1.0_101944350_NVIDIAGeForceRTX4070LaptopGPU.zip"; std::string videoFile = "E:\\Programs\\DemoAssets\\Videos\\TestFR\\school1.mp4"; //OpenVINOYolov10EngineUnitTest(cpumodelFilePath, videoFile);//yolov10 GPUYolov10EngineUnitTest(gpumodelFilePath, videoFile);//yolov10 return 0; } int PersonHead() { std::string cpumodelFilePath = "C:\\Projects\\ANSVIS\\Models\\ANS_PeopleHead(CPU)_v1.0.zip"; std::string gpumodelFilePath = "C:\\Projects\\ANSVIS\\Models\\ANS_PeopleHead(CPU)_v1.0.zip"; std::string videoFile = "C:\\Programs\\DemoAssets\\Videos\\video_20.mp4"; OpenVINOEngineUnitTest(cpumodelFilePath, videoFile);//yolov8 return 0; } int RVATest() { std::string rvamodelFilePath = "C:\\Programs\\Braemac\\BR_RVA\\Models\\ANS_BR_RVA(GPU)_1.zip"; std::string rvaImageFile = "C:\\Programs\\Braemac\\TestData\\2025-07-29-122338.jpg"; GPU11EngineImageTest(rvamodelFilePath, rvaImageFile); return 0; }