22#include " c_api/intypedef.h"
33#include " opencv2/opencv.hpp"
44#include " inspireface/c_api/inspireface.h"
5+ #include < unordered_map>
6+ #include < functional>
57
68void drawMode (cv::Mat& frame, HFDetectMode mode) {
79 std::string modeText;
@@ -19,9 +21,26 @@ void drawMode(cv::Mat& frame, HFDetectMode mode) {
1921 modeText = " Mode: Unknown" ;
2022 break ;
2123 }
22- cv::putText (frame, modeText, cv::Point (10 , 30 ), cv::FONT_HERSHEY_SIMPLEX, 1.0 , cv::Scalar (255 , 255 , 255 ), 2 );
24+ cv::putText (frame, modeText, cv::Point (10 , 30 ), cv::FONT_HERSHEY_SIMPLEX, 1.0 , cv::Scalar (90 , 100 , 255 ), 2 );
2325}
2426
27+ cv::Scalar generateColor (int id) {
28+ int maxID = 100 ;
29+ id = id % maxID;
30+
31+ int hue = (id * 360 / maxID) % 360 ;
32+ int saturation = 255 ;
33+ int value = 200 ;
34+
35+ cv::Mat hsv (1 , 1 , CV_8UC3, cv::Scalar (hue, saturation, value));
36+ cv::Mat rgb;
37+ cv::cvtColor (hsv, rgb, cv::COLOR_HSV2BGR);
38+
39+ cv::Vec3b rgbColor = rgb.at <cv::Vec3b>(0 , 0 );
40+ return cv::Scalar (rgbColor[0 ], rgbColor[1 ], rgbColor[2 ]);
41+ }
42+
43+
2544int main (int argc, char * argv[]) {
2645 // Check whether the number of parameters is correct
2746 if (argc != 3 ) {
@@ -46,11 +65,11 @@ int main(int argc, char* argv[]) {
4665 // Enable the functions in the pipeline: mask detection, live detection, and face quality detection
4766 HOption option = HF_ENABLE_QUALITY | HF_ENABLE_MASK_DETECT | HF_ENABLE_INTERACTION;
4867 // Video or frame sequence mode uses VIDEO-MODE, which is face detection with tracking
49- HFDetectMode detMode = HF_DETECT_MODE_LIGHT_TRACK ;
68+ HFDetectMode detMode = HF_DETECT_MODE_TRACK_BY_DETECTION ;
5069 // Maximum number of faces detected
5170 HInt32 maxDetectNum = 20 ;
5271 // Face detection image input level
53- HInt32 detectPixelLevel = 160 ;
72+ HInt32 detectPixelLevel = 640 ;
5473 // fps in tracking-by-detection mode
5574 HInt32 trackByDetectFps = 20 ;
5675 HFSession session = {0 };
@@ -122,35 +141,36 @@ int main(int argc, char* argv[]) {
122141
123142 // Draw detection mode on the frame
124143 drawMode (draw, detMode);
125- if (faceNum > 0 ) {
126- ret = HFMultipleFacePipelineProcessOptional (session, imageHandle, &multipleFaceData, option);
127- if (ret != HSUCCEED)
128- {
129- std::cout << " HFMultipleFacePipelineProcessOptional error: " << ret << std::endl;
130- return ret;
131- }
132- HFFaceIntereactionResult result;
133- ret = HFGetFaceIntereactionResult (session, &result);
134- if (ret != HSUCCEED)
135- {
136- std::cout << " HFGetFaceIntereactionResult error: " << ret << std::endl;
137- return ret;
138- }
139- std::cout << " Left eye status: " << result.leftEyeStatusConfidence [0 ] << std::endl;
140- std::cout << " Righ eye status: " << result.rightEyeStatusConfidence [0 ] << std::endl;
141-
142- }
144+ // if (faceNum > 0) {
145+ // ret = HFMultipleFacePipelineProcessOptional(session, imageHandle, &multipleFaceData, option);
146+ // if (ret != HSUCCEED)
147+ // {
148+ // std::cout << "HFMultipleFacePipelineProcessOptional error: " << ret << std::endl;
149+ // return ret;
150+ // }
151+ // HFFaceIntereactionResult result;
152+ // ret = HFGetFaceIntereactionResult(session, &result);
153+ // if (ret != HSUCCEED)
154+ // {
155+ // std::cout << "HFGetFaceIntereactionResult error: " << ret << std::endl;
156+ // return ret;
157+ // }
158+ // std::cout << "Left eye status: " << result.leftEyeStatusConfidence[0] << std::endl;
159+ // std::cout << "Righ eye status: " << result.rightEyeStatusConfidence[0] << std::endl;
160+
161+ // }
143162
144163 for (int index = 0 ; index < faceNum; ++index) {
145164 // std::cout << "========================================" << std::endl;
146165 // std::cout << "Process face index: " << index << std::endl;
166+ // Print FaceID, In VIDEO-MODE it is fixed, but it may be lost
167+ auto trackId = multipleFaceData.trackIds [index];
168+
147169 // Use OpenCV's Rect to receive face bounding boxes
148170 auto rect = cv::Rect (multipleFaceData.rects [index].x , multipleFaceData.rects [index].y ,
149171 multipleFaceData.rects [index].width , multipleFaceData.rects [index].height );
150- cv::rectangle (draw, rect, cv::Scalar ( 0 , 100 , 255 ), 5 );
172+ cv::rectangle (draw, rect, generateColor (trackId ), 3 );
151173
152- // Print FaceID, In VIDEO-MODE it is fixed, but it may be lost
153- auto trackId = multipleFaceData.trackIds [index];
154174 // std::cout << "FaceID: " << trackId << std::endl;
155175
156176 // Print Head euler angle, It can often be used to judge the quality of a face by the Angle of the head
@@ -160,7 +180,7 @@ int main(int argc, char* argv[]) {
160180
161181 // Add TrackID to the drawing
162182 cv::putText (draw, " ID: " + std::to_string (trackId), cv::Point (rect.x , rect.y - 10 ),
163- cv::FONT_HERSHEY_SIMPLEX, 0.5 , cv::Scalar ( 0 , 255 , 0 ), 2 );
183+ cv::FONT_HERSHEY_SIMPLEX, 0.5 , generateColor (trackId ), 2 );
164184
165185 HInt32 numOfLmk;
166186 HFGetNumOfFaceDenseLandmark (&numOfLmk);
@@ -172,7 +192,7 @@ int main(int argc, char* argv[]) {
172192 }
173193 for (size_t i = 0 ; i < numOfLmk; i++) {
174194 cv::Point2f p (denseLandmarkPoints[i].x , denseLandmarkPoints[i].y );
175- cv::circle (draw, p, 0 , ( 0 , 0 , 255 ), 2 );
195+ cv::circle (draw, p, 0 , generateColor (trackId ), 2 );
176196 }
177197 }
178198
0 commit comments