in image/image.cpp [101:189]
int main() {
std::map<std::string, std::string> config = readConfig("config.ini");
std::string licenseText = config["licenseText"];
ImageModelConfig aacsConfig;
aacsConfig.gpuEnabled = (config["gpuEnabled"] == "true");
aacsConfig.gpuDeviceId = std::stoi(config["gpuDeviceId"]);
aacsConfig.numThreads = std::stoi(config["numThreads"]);
aacsConfig.modelDirectory = config["modelDirectory"];
aacsConfig.modelName = config["modelName"];
std::cout << "gpuEnabled: " << aacsConfig.gpuEnabled << std::endl;
std::cout << "gpuDeviceId: " << aacsConfig.gpuDeviceId << std::endl;
std::cout << "numThreads: " << aacsConfig.numThreads << std::endl;
std::cout << "modelDirectory: " << aacsConfig.modelDirectory << std::endl;
std::cout << "modelName: " << aacsConfig.modelName << std::endl;
// Get the starting timepoint
auto start = std::chrono::high_resolution_clock::now();
ImageModelRuntime aacs(licenseText.c_str(), aacsConfig);
// Get the ending timepoint
auto end = std::chrono::high_resolution_clock::now();
auto modelLoadDuration = std::chrono::duration_cast<std::chrono::milliseconds>(end - start);
std::cout << "Model loaded successfully, duration: " << modelLoadDuration.count() << " milliseconds" << std::endl;
std::cout << "--------------------------------------------------------------------------------------" << std::endl;
start = std::chrono::high_resolution_clock::now();
aacs.Unload();
end = std::chrono::high_resolution_clock::now();
auto modelOffloadDuration = std::chrono::duration_cast<std::chrono::milliseconds>(end - start);
std::cout << "Model offloaded successfully, duration: " << modelOffloadDuration.count() << " milliseconds"
<< std::endl;
std::cout << "--------------------------------------------------------------------------------------" << std::endl;
start = std::chrono::high_resolution_clock::now();
aacs.Reload();
end = std::chrono::high_resolution_clock::now();
auto modelReloadDuration = std::chrono::duration_cast<std::chrono::milliseconds>(end - start);
std::cout << "Model Reloaded successfully, duration: " << modelReloadDuration.count() << " milliseconds"
<< std::endl;
std::cout << "--------------------------------------------------------------------------------------" << std::endl;
auto startTime = std::chrono::high_resolution_clock::now();
std::string folderPath = config["inputImagesDirectory"];
for (const auto& entry : std::filesystem::directory_iterator(folderPath)) {
if (entry.is_regular_file()) {
std::string filePath = entry.path().string();
try {
std::string base64String = fileToBase64(filePath);
std::cout << "File: " << filePath << std::endl;
//std::cout << "Base64: " << base64String << std::endl << std::endl;
AnalyzeImageOptions request;
request.imageData = base64String; // base64 encoded image data
std::cout << " Analyze Image Result: " << std::endl;
auto severityThreshold = 3;
// Run inference
auto analyzeStart = std::chrono::high_resolution_clock::now();
auto* result = new AnalyzeImageResult();
aacs.AnalyzeImage(request, *result);
// Print the result to the console
for (const auto& categoryAnalysis : result->categoriesAnalysis) {
if (categoryAnalysis.severity > 0 && categoryAnalysis.severity < severityThreshold) {
std::cout << "\033[33m"; // Set the text color to yellow
}
else if (categoryAnalysis.severity >= severityThreshold) {
std::cout << "\033[31m"; // Set the text color to red
}
else {
std::cout << "\033[32m"; // Set the text color to green
}
std::cout << " Category: " << getCategoryName(categoryAnalysis.category) << ", Severity: "
<< static_cast<int>(categoryAnalysis.severity) << std::endl;
std::cout << "\033[0m"; // Reset the text color
}
auto analyzeEnd = std::chrono::high_resolution_clock::now();
auto analyzeTextDuration = std::chrono::duration_cast<std::chrono::milliseconds>(analyzeEnd - analyzeStart);
std::cout << "Analyze Image duration: " << analyzeTextDuration.count() << " milliseconds" << std::endl;
std::cout << "--------------------------------------------------------------------------------------"
<< std::endl;
auto endTime = std::chrono::high_resolution_clock::now();
}
catch (const std::exception& e) {
std::cerr << "Error processing file " << filePath << ": " << e.what() << std::endl;
}
}
}
std::cout << "Press any key to continue..";
_getch();
}