MCPcopy Create free account
hub / github.com/HyperInspire/InspireFace / faceTrackingThread

Function faceTrackingThread

cpp/sample/api/sample_cpp_multithreading.cpp:114–162  ·  view source on GitHub ↗

Face tracking thread function

Source from the content-addressed store, hash-verified

112
113// Face tracking thread function
114void faceTrackingThread(ThreadSafeTokenStorage& tokenStorage,
115 HFSession session,
116 const std::string& imagePath,
117 int maxFrames = 100) {
118 std::cout << "Face tracking thread started" << std::endl;
119
120 // Load image using C API
121 HFImageBitmap imageBitmap = {0};
122 HResult ret = HFCreateImageBitmapFromFilePath(imagePath.c_str(), 3, &imageBitmap);
123 if (ret != HSUCCEED) {
124 std::cerr << "Failed to create image bitmap: " << ret << std::endl;
125 return;
126 }
127
128 // Create image stream
129 HFImageStream stream;
130 ret = HFCreateImageStreamFromImageBitmap(imageBitmap, HF_CAMERA_ROTATION_0, &stream);
131 if (ret != HSUCCEED) {
132 std::cerr << "Failed to create image stream: " << ret << std::endl;
133 HFReleaseImageBitmap(imageBitmap);
134 return;
135 }
136
137 int frameCount = 0;
138 while (!tokenStorage.shouldStop() && frameCount < maxFrames) {
139 // Perform face detection and tracking using C API
140 HFMultipleFaceData multipleFaceData = {0};
141 ret = HFExecuteFaceTrack(session, stream, &multipleFaceData);
142
143 if (ret == HSUCCEED && multipleFaceData.detectedNum > 0) {
144 // Add tokens to storage
145 for (int i = 0; i < multipleFaceData.detectedNum; i++) {
146 tokenStorage.addToken(multipleFaceData.tokens[i]);
147
148 std::cout << "Frame " << frameCount << ": Added token for face "
149 << multipleFaceData.trackIds[i] << std::endl;
150 }
151 }
152
153 frameCount++;
154 std::this_thread::sleep_for(std::chrono::milliseconds(100)); // Simulate frame processing
155 }
156
157 // Cleanup
158 HFReleaseImageStream(stream);
159 HFReleaseImageBitmap(imageBitmap);
160
161 std::cout << "Face tracking thread finished after " << frameCount << " frames" << std::endl;
162}
163
164// Face feature extraction thread function
165void featureExtractionThread(ThreadSafeTokenStorage& tokenStorage,

Callers

nothing calls this directly

Calls 7

HFReleaseImageBitmapFunction · 0.85
HFExecuteFaceTrackFunction · 0.85
HFReleaseImageStreamFunction · 0.85
shouldStopMethod · 0.80
addTokenMethod · 0.80

Tested by

no test coverage detected