-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathmain.cpp
50 lines (43 loc) · 1.53 KB
/
main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
/*
* Copyright (C) 2020-2024 Intel Corporation
* SPDX-License-Identifier: Apache-2.0
*/
#include <models/detection_model.h>
#include <models/input_data.h>
#include <models/results.h>
#include <stddef.h>
#include <cstdint>
#include <exception>
#include <iomanip>
#include <iostream>
#include <opencv2/core.hpp>
#include <opencv2/highgui.hpp>
#include <opencv2/imgcodecs.hpp>
#include <openvino/openvino.hpp>
#include <stdexcept>
#include <string>
int main(int argc, char* argv[]) try {
if (argc != 3) {
throw std::runtime_error(std::string{"Usage: "} + argv[0] + " <path_to_model> <path_to_image>");
}
cv::Mat image = cv::imread(argv[2]);
if (!image.data) {
throw std::runtime_error{"Failed to read the image"};
}
// Instantiate Object Detection model
auto model = DetectionModel::create_model(argv[1]); // works with SSD models. Download it using Python Model API
// Run the inference
auto result = model->infer(image);
// Process detections
for (auto& obj : result->objects) {
std::cout << " " << std::left << std::setw(9) << obj.label << " | " << std::setw(10) << obj.confidence << " | "
<< std::setw(4) << int(obj.x) << " | " << std::setw(4) << int(obj.y) << " | " << std::setw(4)
<< int(obj.x + obj.width) << " | " << std::setw(4) << int(obj.y + obj.height) << "\n";
}
} catch (const std::exception& error) {
std::cerr << error.what() << '\n';
return 1;
} catch (...) {
std::cerr << "Non-exception object thrown\n";
return 1;
}