Skip to content

Commit f7969d3

Browse files
committed
chore: improve docs on sigfm and cleanup
1 parent 6153161 commit f7969d3

File tree

2 files changed

+57
-39
lines changed

2 files changed

+57
-39
lines changed

libfprint/sigfm/sigfm.cpp

Lines changed: 0 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,6 @@
3737
#include <opencv2/opencv.hpp>
3838
#include <vector>
3939

40-
namespace fs = std::filesystem;
41-
42-
struct SfmEnrollData {
43-
fs::path img_path_base;
44-
};
45-
4640
namespace bin {
4741

4842
template<>
@@ -93,21 +87,8 @@ struct angle {
9387
{
9488
}
9589
};
96-
// namespace bin
9790
} // namespace
9891

99-
SfmEnrollData* sfm_begin_enroll(const char* username, int finger)
100-
{
101-
const auto img_path = fs::path{"~/goodixtls-store-dev-remove-later"} /
102-
"prints" / username / std::to_string(finger);
103-
auto* enroll_data = new SfmEnrollData{img_path};
104-
if (!fs::exists(img_path)) {
105-
fs::create_directories(img_path);
106-
}
107-
cv::KeyPoint kp;
108-
return enroll_data;
109-
}
110-
11192
SfmImgInfo* sfm_copy_info(SfmImgInfo* info) { return new SfmImgInfo{*info}; }
11293

11394
int sfm_keypoints_count(SfmImgInfo* info) { return info->keypoints.size(); }
@@ -132,7 +113,6 @@ SfmImgInfo* sfm_deserialize_binary(const unsigned char* bytes, int len)
132113
}
133114
}
134115

135-
//int sfm_info_equal(SfmImgInfo* lhs, SfmImgInfo* rhs) { return std::equal(lhs->descriptors.databegin, lhs->descriptors.dataend, rhs->descriptors.datastart, rhs->descriptors.dataend) && lhs->keypoints == rhs->keypoints; }
136116
SfmImgInfo* sfm_extract(const SfmPix* pix, int width, int height)
137117
{
138118
cv::Mat img;
@@ -143,10 +123,8 @@ SfmImgInfo* sfm_extract(const SfmPix* pix, int width, int height)
143123

144124
cv::Mat descs;
145125
cv::SIFT::create()->detectAndCompute(img, roi, pts, descs);
146-
//cv::imwrite("./finger-extract.png", img);
147126

148127
auto* info = new SfmImgInfo{pts, descs};
149-
//*minutae = keypoints_to_fp_minutiae(pts);
150128
return info;
151129
}
152130

@@ -235,12 +213,3 @@ int sfm_match_score(SfmImgInfo* frame, SfmImgInfo* enrolled)
235213
}
236214

237215
void sfm_free_info(SfmImgInfo* info) { delete info; }
238-
239-
void sfm_add_enroll_frame(SfmEnrollData* data, unsigned char* pix, int width,
240-
int height)
241-
{
242-
cv::Mat img{height, width, CV_8UC1, pix};
243-
cv::imwrite(data->img_path_base / "img.pgm", img);
244-
}
245-
246-
void sfm_end_enroll(SfmEnrollData* data) { delete data; }

libfprint/sigfm/sigfm.hpp

Lines changed: 57 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,25 +23,74 @@
2323
#ifdef __cplusplus
2424
extern "C" {
2525
#endif
26-
struct SfmEnrollData;
27-
typedef struct SfmEnrollData SfmEnrollData;
2826
typedef unsigned char SfmPix;
27+
/**
28+
* @brief Contains information used by the sigfm algorithm for matching
29+
* @details Get one from sfm_extract() and make sure to clean it up with sfm_free_info()
30+
* @struct SfmImgInfo
31+
*/
2932
typedef struct SfmImgInfo SfmImgInfo;
3033

31-
SfmEnrollData* sfm_begin_enroll(const char* username, int finger);
32-
void sfm_add_enroll_frame(SfmEnrollData* data, unsigned char* pix, int width,
33-
int height);
34+
/**
35+
* @brief Extracts information from an image for later use sfm_match_score
36+
*
37+
* @param pix Pixels of the image must be width * height in length
38+
* @param width Width of the image
39+
* @param height Height of the image
40+
* @return SfmImgInfo* Info that can be used with the API
41+
*/
3442
SfmImgInfo* sfm_extract(const SfmPix* pix, int width, int height);
3543

36-
void sfm_end_enroll(SfmEnrollData* data);
44+
/**
45+
* @brief Destroy an SfmImgInfo
46+
* @warning Call this instead of free() or you will get UB!
47+
* @param info SfmImgInfo to destroy
48+
*/
3749
void sfm_free_info(SfmImgInfo* info);
50+
51+
/**
52+
* @brief Score how closely a frame matches another
53+
*
54+
* @param frame Print to be checked
55+
* @param enrolled Canonical print to verify against
56+
* @return int Score of how closely they match, values <0 indicate error, 0 means always reject
57+
*/
3858
int sfm_match_score(SfmImgInfo* frame, SfmImgInfo* enrolled);
59+
60+
/**
61+
* @brief Serialize an image info for storage
62+
*
63+
* @param info SfmImgInfo to store
64+
* @param outlen output: Length of the returned byte array
65+
* @return unsigned* char byte array for storage, should be free'd by the callee
66+
*/
3967
unsigned char* sfm_serialize_binary(SfmImgInfo* info, int* outlen);
68+
/**
69+
* @brief Deserialize an SfmImgInfo from storage
70+
*
71+
* @param bytes Byte array to deserialize from
72+
* @param len Length of the byte array
73+
* @return SfmImgInfo* Deserialized info, or NULL if deserialization failed
74+
*/
4075
SfmImgInfo* sfm_deserialize_binary(const unsigned char* bytes, int len);
76+
77+
/**
78+
* @brief Keypoints for an image. Low keypoints generally means the image is
79+
* low quality for matching
80+
*
81+
* @param info
82+
* @return int
83+
*/
84+
4185
int sfm_keypoints_count(SfmImgInfo* info);
42-
SfmImgInfo* sfm_copy_info(SfmImgInfo* info);
4386

44-
//int sfm_info_equal(SfmImgInfo* lhs, SfmImgInfo* rhs);
87+
/**
88+
* @brief Copy an SfmImgInfo
89+
*
90+
* @param info Source of copy
91+
* @return SfmImgInfo* Newly allocated and copied version of info
92+
*/
93+
SfmImgInfo* sfm_copy_info(SfmImgInfo* info);
4594

4695
#ifdef __cplusplus
4796
}

0 commit comments

Comments
 (0)