/
Source.cpp
53 lines (33 loc) · 1.19 KB
/
Source.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
51
52
53
#include "Object_Detection.h"
using namespace std;
using namespace cv;
using namespace cv::dnn;
int main()
{
Object_Detection Detect;
//loading configuration files and weights
//string cfg_path = "yolov3-tiny.cfg";
//string weights_path = "yolov3-tiny.weights";
string cfg_path = "yolov3.cfg";
string weights_path = "yolov3.weights";
//loading names of classes
string classesFile = "coco.names";
ifstream ifs(classesFile.c_str());
string line;
while (getline(ifs, line)) Detect.classes.push_back(line);
Net net = readNet(cfg_path, weights_path);
Mat frame = imread("yo.png");
//creating a blob to feed to neural network
Mat blob = blobFromImage(frame, Detect.scale, cvSize(412, 412), Scalar(0, 0, 0), true, false);
//Sets the input to the network
net.setInput(blob);
// Runs the forward pass to get output of the output layers
vector<Mat> outs;
net.forward(outs, Detect.getOutput(net));
// Remove the bounding boxes with low confidence and draw bounding box with highest confidence
Detect.postProcessing(frame, outs);
//namedWindow("Detection", WINDOW_NORMAL);
//imshow("Detection", frame);
cin.get();
return 0;
}