Skip to content

Commit

Permalink
Merge pull request #114 from HyperInspire/feature/add-lib-config
Browse files Browse the repository at this point in the history
Feature/add lib config
  • Loading branch information
tunmx authored Nov 22, 2024
2 parents 00b6488 + cdc773b commit 471387d
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 32 deletions.
3 changes: 3 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ string(CONCAT INSPIRE_FACE_VERSION_PATCH_STR ${INSPIRE_FACE_VERSION_PATCH})
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/cpp/inspireface/information.h.in ${CMAKE_CURRENT_SOURCE_DIR}/cpp/inspireface/information.h)
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/cpp/inspireface/version.txt.in ${CMAKE_CURRENT_SOURCE_DIR}/cpp/inspireface/version.txt)

# Creates a package config file
configure_file("${InspireFace_SOURCE_DIR}/cpp/inspireface/cmake/templates/InspireFaceConfig.cmake.in" "${CMAKE_BINARY_DIR}/install/InspireFaceConfig.cmake" @ONLY)

# Set the ISF_THIRD_PARTY_DIR variable to allow it to be set externally from the command line, or use the default path if it is not set
set(ISF_THIRD_PARTY_DIR "${CMAKE_CURRENT_SOURCE_DIR}/3rdparty" CACHE PATH "Path to the third-party libraries directory")

Expand Down
28 changes: 28 additions & 0 deletions cpp/inspireface/cmake/templates/InspireFaceConfig.cmake.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// clang-format off
# ===================================================================================
# The InspireFace CMake configuration file
#
# ** File generated automatically, do not modify **
# Usage from an external project:
# In your CMakeLists.txt, add these lines:
#
# find_package(InspireFace REQUIRED)
# include_directories(${InspireFace_INCLUDE_DIRS}) # Not needed for CMake >= 2.8.11
# target_link_libraries(MY_TARGET_NAME ${InspireFace_LIBS})
#
#
#
# This file will define the following variables:
# - InspireFace_LIBS : The list of all imported targets for InspireFace modules.
# - InspireFace_INCLUDE_DIRS : The InspireFace include directories.
#
#
@PACKAGE_INIT@

set(InspireFace_LIBS "")
file(GLOB LIBS "@CMAKE_BINARY_DIR@/InspireFace/lib/*.*")

list(APPEND InspireFace_LIBS ${LIBS})
set(InspireFace_INCLUDE_DIRS "@CMAKE_BINARY_DIR@/InspireFace/include")

// clang-format on
15 changes: 8 additions & 7 deletions cpp/sample/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,13 @@ set_target_properties(MTFaceTrackSample PROPERTIES
)

if(NOT DISABLE_GUI)
# Examples of face detection and tracking
add_executable(FaceTrackVideoSample cpp/sample_face_track_video.cpp)
target_link_libraries(FaceTrackVideoSample InspireFace ${ext})
set_target_properties(FaceTrackVideoSample PROPERTIES
RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/sample/"
)
endif()
# Examples of face detection and tracking
add_executable(FaceTrackVideoSample cpp/sample_face_track_video.cpp)
target_link_libraries(FaceTrackVideoSample InspireFace ${ext})
set_target_properties(FaceTrackVideoSample PROPERTIES
RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/sample/"
)
endif ()



Expand Down Expand Up @@ -265,4 +265,5 @@ install(TARGETS MTFaceTrackSample RUNTIME DESTINATION ${CMAKE_INSTALL_PREFIX}/sa
install(TARGETS FaceRecognitionSample RUNTIME DESTINATION ${CMAKE_INSTALL_PREFIX}/sample)
install(TARGETS FaceSearchSample RUNTIME DESTINATION ${CMAKE_INSTALL_PREFIX}/sample)
install(TARGETS FaceComparisonSample RUNTIME DESTINATION ${CMAKE_INSTALL_PREFIX}/sample)
install(TARGETS FaceTrackVideoSample RUNTIME DESTINATION ${CMAKE_INSTALL_PREFIX}/sample)

6 changes: 3 additions & 3 deletions cpp/sample/cpp/face_detect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@ int main() {
auto img = cv::imread("/Users/tunm/Downloads/xtl.png");

double time;
time = (double) cv::getTickCount();
time = (double)cv::getTickCount();
std::vector<FaceLoc> results = detect(img);
time = ((double) cv::getTickCount() - time) / cv::getTickFrequency();
std::cout << "use time:" << time << "\n";
time = ((double)cv::getTickCount() - time) / cv::getTickFrequency();
std::cout << "use time:" << time << "s\n";

for (size_t i = 0; i < results.size(); i++) {
auto &item = results[i];
Expand Down
40 changes: 18 additions & 22 deletions cpp/sample/cpp/sample_face_track_video.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ cv::Scalar generateColor(int id) {
int maxID = 100;
id = id % maxID;

int hue = (id * 360 / maxID) % 360;
int saturation = 255;
int hue = (id * 360 / maxID) % 360;
int saturation = 255;
int value = 200;

cv::Mat hsv(1, 1, CV_8UC3, cv::Scalar(hue, saturation, value));
Expand All @@ -40,7 +40,6 @@ cv::Scalar generateColor(int id) {
return cv::Scalar(rgbColor[0], rgbColor[1], rgbColor[2]);
}


int main(int argc, char* argv[]) {
// Check whether the number of parameters is correct
if (argc != 3) {
Expand Down Expand Up @@ -107,11 +106,11 @@ int main(int argc, char* argv[]) {
while (cap.read(frame)) {
// Prepare an image parameter structure for configuration
HFImageData imageParam = {0};
imageParam.data = frame.data; // Data buffer
imageParam.width = frame.cols; // Target view width
imageParam.height = frame.rows; // Target view width
imageParam.rotation = HF_CAMERA_ROTATION_0; // Data source rotate
imageParam.format = HF_STREAM_BGR; // Data source format
imageParam.data = frame.data; // Data buffer
imageParam.width = frame.cols; // Target view width
imageParam.height = frame.rows; // Target view width
imageParam.rotation = HF_CAMERA_ROTATION_0; // Data source rotate
imageParam.format = HF_STREAM_BGR; // Data source format

// Create an image data stream
HFImageStream imageHandle = {0};
Expand All @@ -122,11 +121,11 @@ int main(int argc, char* argv[]) {
}

// Execute HF_FaceContextRunFaceTrack captures face information in an image
double time = (double) cv::getTickCount();
double time = (double)cv::getTickCount();
HFMultipleFaceData multipleFaceData = {0};
ret = HFExecuteFaceTrack(session, imageHandle, &multipleFaceData);
time = ((double) cv::getTickCount() - time) / cv::getTickFrequency();
std::cout << "use time:" << time << "\n";
time = ((double)cv::getTickCount() - time) / cv::getTickFrequency();
std::cout << "use time:" << time << "s\n";
if (ret != HSUCCEED) {
std::cout << "Execute HFExecuteFaceTrack error: " << ret << std::endl;
return ret;
Expand All @@ -143,32 +142,29 @@ int main(int argc, char* argv[]) {
drawMode(draw, detMode);
if (faceNum > 0) {
ret = HFMultipleFacePipelineProcessOptional(session, imageHandle, &multipleFaceData, option);
if (ret != HSUCCEED)
{
if (ret != HSUCCEED) {
std::cout << "HFMultipleFacePipelineProcessOptional error: " << ret << std::endl;
return ret;
}
HFFaceIntereactionState result;
ret = HFGetFaceIntereactionStateResult(session, &result);
if (ret != HSUCCEED)
{
if (ret != HSUCCEED) {
std::cout << "HFGetFaceIntereactionStateResult error: " << ret << std::endl;
return ret;
}
std::cout << "Left eye status: " << result.leftEyeStatusConfidence[0] << std::endl;
std::cout << "Righ eye status: " << result.rightEyeStatusConfidence[0] << std::endl;

}

for (int index = 0; index < faceNum; ++index) {
// std::cout << "========================================" << std::endl;
// std::cout << "Process face index: " << index << std::endl;
// Print FaceID, In VIDEO-MODE it is fixed, but it may be lost
auto trackId = multipleFaceData.trackIds[index];

// Use OpenCV's Rect to receive face bounding boxes
auto rect = cv::Rect(multipleFaceData.rects[index].x, multipleFaceData.rects[index].y,
multipleFaceData.rects[index].width, multipleFaceData.rects[index].height);
auto rect = cv::Rect(multipleFaceData.rects[index].x, multipleFaceData.rects[index].y, multipleFaceData.rects[index].width,
multipleFaceData.rects[index].height);
cv::rectangle(draw, rect, generateColor(trackId), 3);

// std::cout << "FaceID: " << trackId << std::endl;
Expand All @@ -179,8 +175,8 @@ int main(int argc, char* argv[]) {
// << ", Pitch: " << multipleFaceData.angles.pitch[index] << std::endl;

// Add TrackID to the drawing
cv::putText(draw, "ID: " + std::to_string(trackId), cv::Point(rect.x, rect.y - 10),
cv::FONT_HERSHEY_SIMPLEX, 0.5, generateColor(trackId), 2);
cv::putText(draw, "ID: " + std::to_string(trackId), cv::Point(rect.x, rect.y - 10), cv::FONT_HERSHEY_SIMPLEX, 0.5, generateColor(trackId),
2);

HInt32 numOfLmk;
HFGetNumOfFaceDenseLandmark(&numOfLmk);
Expand All @@ -195,7 +191,7 @@ int main(int argc, char* argv[]) {
cv::circle(draw, p, 0, generateColor(trackId), 2);
}
}

cv::imshow("w", draw);
cv::waitKey(1);

Expand Down

0 comments on commit 471387d

Please sign in to comment.