特征匹配之:Sift/Surf描述子由float型转为Char类型

本文分享了将128维float类型SIFT描述子转为char类型的方法,旨在降低计算成本并加速匹配过程。文章提供了实现代码,并指出在vlSIFT中已进行归一化处理,直接转换类型即可。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

摘要:最近在做基于特征的倾斜影像匹配,为了降低计算代价加速匹配的目的,我将128维float类型的Sift描述子转为char类型,下面分享代码。

void float2BYTE(float* pVector, unsigned char* pDescriptor, int len, float topThreshold)
{
	float sum = 0;
	float aValue;
	// 1. 首先对float类型的描述子进行归一化计算
	for (int k = 0; k < len; k++)
	{
		aValue = abs(pVector[k]);
		aValue = min(aValue, topThreshold);
		pVector[k] = aValue;
		sum += aValue*aValue;
	}
	sum = sqrt(sum);
	sum = 1.0/sum*512;  
	
	// 2. 转为char类型的描述子
	for (int k = 0; k < len; k++)
	{
		aValue = pVector[k];
		pDescriptor[k] = cv::saturate_cast<uchar>(aValue*sum);
		//pDescriptor[k] =  (vl_uint8) (aValue*sum);
	}
}

即,描述子类型转换的思路为:先归一化处理(描述子为向量),再进行类型转换
上边为了告诉大家将描述子做类型转换的思路,我将float类型的描述子首先做了归一化,其实在vlSIft中已将将float的描述子进行了归一化计算,实际处理中不需要做归一化只需进行类型转换(看了vlSift的源码,具体我还未实验)。另外,个人实验发现vlSIFT提点效果优于OpenCV中的sift提取特征点,vlSIft的实现在层数和阶数上更科学。

希望可以帮到你!

好的,我来为您解答。 SURF(Speeded Up Robust Features)是一种基于尺度不变特征变换(Scale-Invariant Feature Transform,SIFT)算法的改进,它可以在不同的尺度和旋转下对图像进行特征提取和匹配。 以下是一个用C语言实现SURF特征匹配程序的基本步骤: 1. 读取输入图像,并将其转换为灰度图像。 2. 对灰度图像进行尺度空间构建,生成一组高斯差分金字塔,然后在每个图像中检测局部极值点。 3. 对每个检测到的局部极值点,生成尺度不变描述符。 4. 对两幅图像中的描述符进行匹配,计算它们之间的距离,并找到最近邻的描述符。 5. 根据最近邻描述符之间的距离,确定它们是否匹配。 下面是一个基本的SURF特征匹配程序的代码示例: ``` #include <stdio.h> #include <stdlib.h> #include <math.h> #define MAX_POINTS 1000 #define MAX_DIM 128 typedef struct { float x, y; } point_t; typedef struct { float desc[MAX_DIM]; } feature_t; typedef struct { point_t point; feature_t feature; } keypoint_t; int num_points1, num_points2; keypoint_t keypoints1[MAX_POINTS], keypoints2[MAX_POINTS]; void load_image(const char *filename, int *width, int *height, unsigned char **data) { // Load image data from file } void detect_keypoints(unsigned char *image_data, int width, int height, keypoint_t *keypoints, int *num_points) { // Detect keypoints using SURF algorithm } void compute_descriptors(unsigned char *image_data, int width, int height, keypoint_t *keypoints, int num_points) { // Compute descriptors for keypoints using SURF algorithm } int match_descriptors(keypoint_t *keypoints1, int num_points1, keypoint_t *keypoints2, int num_points2, int *matches) { // Match descriptors between two sets of keypoints } int main(int argc, char **argv) { unsigned char *image_data1, *image_data2; int width1, height1, width2, height2; // Load input images load_image(argv[1], &width1, &height1, &image_data1); load_image(argv[2], &width2, &height2, &image_data2); // Detect keypoints and compute descriptors for both images detect_keypoints(image_data1, width1, height1, keypoints1, &num_points1); compute_descriptors(image_data1, width1, height1, keypoints1, num_points1); detect_keypoints(image_data2, width2, height2, keypoints2, &num_points2); compute_descriptors(image_data2, width2, height2, keypoints2, num_points2); // Match descriptors between the two sets of keypoints int num_matches = match_descriptors(keypoints1, num_points1, keypoints2, num_points2, matches); // Print out the number of matches found printf("Found %d matches\n", num_matches); // Cleanup free(image_data1); free(image_data2); return 0; } ``` 注意,这只是一个简单的示例代码,实际上SURF特征匹配算法还有很多细节需要处理,比如如何选择关键点、如何计算特征描述符等。如果您想要实现更加完整和高效的SURF特征匹配程序,建议参考相关的研究论文或者开源代码。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值