88
99
1010
11- Tracker::Tracker (PositionSolver* solver, std::wstring& detection_model_path, std::wstring& landmark_model_path):
12- improc()
11+ Tracker::Tracker (std::unique_ptr<PositionSolver>&& solver, std::wstring& detection_model_path, std::wstring& landmark_model_path):
12+ improc(),
13+ memory_info(allocator.GetInfo()),
14+ enviro(std::make_unique<Ort::Env>(ORT_LOGGING_LEVEL_WARNING, " env" )),
15+ detection_input_node_names{ " input" },
16+ detection_output_node_names{ " output" , " maxpool" },
17+ landmarks_input_node_names{ " input" },
18+ landmarks_output_node_names{ " output" }
1319{
14-
15- this ->solver = solver;
16-
17-
18- session_options = new Ort::SessionOptions ();
19- session_options->SetGraphOptimizationLevel (GraphOptimizationLevel::ORT_ENABLE_EXTENDED);
20- session_options->SetInterOpNumThreads (1 );
21- session_options->SetInterOpNumThreads (1 );
22- allocator = new Ort::AllocatorWithDefaultOptions ();
23- memory_info = (Ort::MemoryInfo*)allocator->GetInfo ();
24- enviro = new Ort::Env (ORT_LOGGING_LEVEL_WARNING, " env" );
25-
26- enviro->DisableTelemetryEvents ();
27-
20+ this ->solver = std::move (solver);
2821
29- session = new Ort::Session (*enviro, detection_model_path.data (), *session_options);
30- session_lm = new Ort::Session (*enviro, landmark_model_path.data (), *session_options);
22+ auto session_options = Ort::SessionOptions ();
23+ session_options.SetGraphOptimizationLevel (GraphOptimizationLevel::ORT_ENABLE_EXTENDED);
24+ session_options.SetInterOpNumThreads (1 );
25+ session_options.SetIntraOpNumThreads (1 );
3126
32- tensor_input_size = tensor_input_dims[ 1 ] * tensor_input_dims[ 2 ] * tensor_input_dims[ 3 ] ;
27+ enviro-> DisableTelemetryEvents () ;
3328
34- detection_input_node_names = {" input" };
35- detection_output_node_names = {" output" , " maxpool" };
36- landmarks_input_node_names = {" input" };
37- landmarks_output_node_names = {" output" };
38- }
29+ session = std::make_unique<Ort::Session>(*enviro, detection_model_path.data (), session_options);
30+ session_lm = std::make_unique<Ort::Session>(*enviro, landmark_model_path.data (), session_options);
3931
40- Tracker::~Tracker ()
41- {
42- delete this ->session_options ;
43- delete this ->enviro ;
44- delete this ->session ;
45- delete this ->session_lm ;
46- delete this ->solver ;
32+ tensor_input_size = tensor_input_dims[1 ] * tensor_input_dims[2 ] * tensor_input_dims[3 ];
4733}
4834
49- void Tracker::predict (cv::Mat& image, FaceData& face_data, IFilter* filter)
35+ void Tracker::predict (cv::Mat& image, FaceData& face_data, const std::unique_ptr< IFilter>& filter)
5036{
5137 cv::Mat img_copy = image.clone ();
5238 img_copy.convertTo (img_copy, CV_32F);
@@ -95,7 +81,7 @@ void Tracker::detect_face(const cv::Mat& image, FaceData& face_data)
9581 improc.normalize (resized);
9682 improc.transpose ((float *)resized.data , buffer_data);
9783
98- Ort::Value input_tensor = Ort::Value::CreateTensor<float >(* memory_info, buffer_data, tensor_input_size, tensor_input_dims, 4 );
84+ Ort::Value input_tensor = Ort::Value::CreateTensor<float >(memory_info, buffer_data, tensor_input_size, tensor_input_dims, 4 );
9985
10086
10187 auto output_tensors = session->Run (Ort::RunOptions{ nullptr },
@@ -107,7 +93,7 @@ void Tracker::detect_face(const cv::Mat& image, FaceData& face_data)
10793
10894 cv::Mat out (4 , tensor_detection_output_dims, CV_32F, output_arr);
10995 cv::Mat maxpool (4 , tensor_detection_output_dims, CV_32F, maxpool_arr);
110-
96+
11197
11298 cv::Mat first (56 , 56 , CV_32F, out.ptr <float >(0 ,0 ));
11399 cv::Mat second (56 , 56 , CV_32F, out.ptr <float >(0 ,1 ));
@@ -123,7 +109,7 @@ void Tracker::detect_face(const cv::Mat& image, FaceData& face_data)
123109
124110
125111 face_data.face_detected = c > .6 ? true : false ;
126-
112+
127113 if (face_data.face_detected )
128114 {
129115 float face[] = { x - r, y - r, 2 * r, 2 * r };
@@ -144,7 +130,7 @@ void Tracker::detect_face(const cv::Mat& image, FaceData& face_data)
144130 face_data.face_coords [2 ] = face[2 ];
145131 face_data.face_coords [3 ] = face[3 ];
146132 }
147-
133+
148134}
149135
150136
@@ -156,10 +142,10 @@ void Tracker::detect_landmarks(const cv::Mat& image, int x0, int y0, float scale
156142 improc.normalize (resized);
157143 improc.transpose ((float *)resized.data , buffer_data);
158144
159- Ort::Value input_tensor = Ort::Value::CreateTensor<float >(* memory_info, buffer_data, tensor_input_size, tensor_input_dims, 4 );
145+ Ort::Value input_tensor = Ort::Value::CreateTensor<float >(memory_info, buffer_data, tensor_input_size, tensor_input_dims, 4 );
160146
161147
162- auto output_tensors = session_lm->Run (Ort::RunOptions{ nullptr },
148+ auto output_tensors = session_lm->Run (Ort::RunOptions{ nullptr },
163149 landmarks_input_node_names.data (), &input_tensor, 1 , landmarks_output_node_names.data (), 1 );
164150
165151 float * output_arr = output_tensors[0 ].GetTensorMutableData <float >();
0 commit comments