| 20 | } |
| 21 | |
| 22 | int main(int argc, char* argv[]) |
| 23 | { |
| 24 | QGuiApplication app(argc, argv); |
| 25 | |
| 26 | if (argc < 4) { |
| 27 | std::cerr << "Usage: test_inference <model.onnx> <image> <conf_threshold>" << std::endl; |
| 28 | return 1; |
| 29 | } |
| 30 | |
| 31 | std::string modelPath = argv[1]; |
| 32 | QString imagePath = QString::fromLocal8Bit(argv[2]); |
| 33 | float confThreshold = std::stof(argv[3]); |
| 34 | |
| 35 | QImage image(imagePath); |
| 36 | if (image.isNull()) { |
| 37 | std::cerr << "Error: cannot load image: " << imagePath.toStdString() << std::endl; |
| 38 | return 1; |
| 39 | } |
| 40 | |
| 41 | YoloDetector detector; |
| 42 | std::string errorMsg; |
| 43 | if (!detector.loadModel(modelPath, errorMsg)) { |
| 44 | std::cerr << "Error loading model: " << errorMsg << std::endl; |
| 45 | return 1; |
| 46 | } |
| 47 | |
| 48 | auto detections = detector.detect(image, confThreshold); |
| 49 | |
| 50 | // Build JSON output |
| 51 | QJsonObject root; |
| 52 | root["model"] = QString::fromStdString(modelPath); |
| 53 | root["version"] = versionToString(detector.getVersion()); |
| 54 | root["endToEnd"] = detector.isEndToEnd(); |
| 55 | root["numClasses"] = detector.getNumClasses(); |
| 56 | |
| 57 | QJsonArray detsArray; |
| 58 | for (const auto& det : detections) { |
| 59 | QJsonObject obj; |
| 60 | obj["classId"] = det.classId; |
| 61 | obj["confidence"] = static_cast<double>(det.confidence); |
| 62 | obj["x"] = static_cast<double>(det.x); |
| 63 | obj["y"] = static_cast<double>(det.y); |
| 64 | obj["width"] = static_cast<double>(det.width); |
| 65 | obj["height"] = static_cast<double>(det.height); |
| 66 | detsArray.append(obj); |
| 67 | } |
| 68 | root["detections"] = detsArray; |
| 69 | |
| 70 | QJsonDocument doc(root); |
| 71 | std::cout << doc.toJson(QJsonDocument::Indented).toStdString(); |
| 72 | |
| 73 | return 0; |
| 74 | } |
nothing calls this directly
no test coverage detected