-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathncnnTest
46 lines (41 loc) · 1.3 KB
/
ncnnTest
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
#include <iostream>
#include "mat.h" //ncnn header
#include "net.h" //ncnn header
#include <opencv2/opencv.hpp>
#include <fstream>
#include <string>
#include <iostream>
using namespace std;
int main() {
ncnn::Net net;
//load model and image
net.load_param("ncnn/blurposeMix.param");
net.load_model("ncnn/blurposeMix.bin");
string img_name = "img_21._0.jpg";
cv::Mat img = cv::imread(img_name);
int img_h = img.rows;
int img_w = img.cols;
//pre-process
ncnn::Mat in = ncnn::Mat::from_pixels_resize(img.data, ncnn::Mat::PIXEL_BGR2RGB, img_w, img_h, 112, 112);
ncnn::Mat blur_o;
ncnn::Mat pose_o;
const float mean_vals[3] = {0.485f*255.f, 0.456f*255.f, 0.406f*255.f};
float std_vals[3] = {1/0.229f/255.f, 1/0.224f/255.f, 1/0.225f/255.f};
in.substract_mean_normalize(mean_vals, std_vals);
//inference
ncnn::Extractor ex = net.create_extractor();
ex.set_light_mode(true);
ex.set_num_threads(4);
ex.input("input", in);
ex.extract("output", blur_o);
ex.extract("576", pose_o);
float blur =blur_o[0];
cout<<blur<<endl;
float yaw =pose_o[0]*10; //out put euler angles should be scale by 10
cout<<yaw<<endl;
float pitch =pose_o[1]*10;
cout<<pitch<<endl;
float roll =pose_o[2]*10;
cout<<roll<<endl;
return 0;
}