function [numGoodMatches,numBadMatches,precision,accuracy100] = evaluate_correspondence(imgA, imgB, ground_truth_correspondence_file, scale_factor, x1_est, y1_est, x2_est, y2_est, vis)
x1_est = x1_est ./ scale_factor;
y1_est = y1_est ./ scale_factor;
x2_est = x2_est ./ scale_factor;
y2_est = y2_est ./ scale_factor;
good_matches = zeros(length(x1_est),1); %indicator vector
% Loads `ground truth' positions x1, y1, x2, y2
load(ground_truth_correspondence_file)
%%%%%%%%%%%%%%%%%%%%%%
% Uniqueness test
%
x1_est_tmp = x1_est;
y1_est_tmp = y1_est;
x2_est_tmp = x2_est;
y2_est_tmp = y2_est;
uniquenessDist = 5;
% For each ground truth point
numPreMerge = length(x1_est);
for i=1:length(x1)
% Compute distance of each estimated point to
% the ground truth point
x_dists = x1(i) - x1_est_tmp;
y_dists = y1(i) - y1_est_tmp;
dists = sqrt( x_dists.^2 + y_dists.^2 );
toMerge = dists < uniquenessDist;
if sum(toMerge) > 1
avgX1 = mean( x1_est_tmp( toMerge ) );
avgY1 = mean( y1_est_tmp( toMerge ) );
avgX2 = mean( x2_est_tmp( toMerge ) );
avgY2 = mean( y2_est_tmp( toMerge ) );
x1_est_tmp( toMerge ) = [];
y1_est_tmp( toMerge ) = [];
x2_est_tmp( toMerge ) = [];
y2_est_tmp( toMerge ) = [];
% Add back point
x1_est_tmp(end+1) = avgX1;
y1_est_tmp(end+1) = avgY1;
x2_est_tmp(end+1) = avgX2;
y2_est_tmp(end+1) = avgY2;
end
end
x1_est = x1_est_tmp;
y1_est = y1_est_tmp;
x2_est = x2_est_tmp;
y2_est = y2_est_tmp;
numPostMerge = length(x1_est);
%
% Uniqueness test end
%%%%%%%%%%%%%%%%%%%%%%
if vis
figure;
Height = max(size(imgA,1),size(imgB,1));
Width = size(imgA,2)+size(imgB,2);
numColors = size(imgA, 3);
newImg = zeros(Height, Width,numColors);
newImg(1:size(imgA,1),1:size(imgA,2),:) = imgA;
newImg(1:size(imgB,1),1+size(imgA,2):end,:) = imgB;
imshow(newImg, 'Border', 'tight')
shiftX = size(imgA,2);
hold on;
end
% Distance test
for i = 1:length(x1_est)
fprintf('( %4.0f, %4.0f) to ( %4.0f, %4.0f)', x1_est(i), y1_est(i), x2_est(i), y2_est(i));
% For each x1_est, find nearest ground truth point in x1
x_dists = x1_est(i) - x1;
y_dists = y1_est(i) - y1;
dists = sqrt( x_dists.^2 + y_dists.^2 );
[dists, best_matches] = sort(dists);
current_offset = [x1_est(i) - x2_est(i), y1_est(i) - y2_est(i)];
most_similar_offset = [x1(best_matches(1)) - x2(best_matches(1)), y1(best_matches(1)) - y2(best_matches(1))];
match_dist = sqrt( sum((current_offset - most_similar_offset).^2));
fprintf(' g.t. point %4.0f px. Match error %4.0f px.', dists(1), match_dist);
if(dists(1) > 150 || match_dist > 40)
good_matches(i) = 0;
edgeColor = [1 0 0];
fprintf(' incorrect\n');
else
good_matches(i) = 1;
edgeColor = [0 1 0];
fprintf(' correct\n');
end
if vis
cur_color = rand(1,3);
plot(x1_est(i)*scale_factor,y1_est(i)*scale_factor, 'o', 'LineWidth',2, 'MarkerEdgeColor',edgeColor,...
'MarkerFaceColor', cur_color, 'MarkerSize',10)
plot(x2_est(i)*scale_factor+shiftX,y2_est(i)*scale_factor, 'o', 'LineWidth',2, 'MarkerEdgeColor',edgeColor,...
'MarkerFaceColor', cur_color, 'MarkerSize',10)
end
end
if vis
hold off;
end
title("x");
numGoodMatches = sum(good_matches);
numBadMatches = length(x1_est) - sum(good_matches);
precision = (sum(good_matches) / length(x1_est)) * 100;
accuracy100 = min(sum(good_matches),100); % / 100) * 100; % If we were testing more than the top 100, then this would be important.
fprintf('Uniqueness: Pre-merge: %d Post-merge: %d\n', numPreMerge, numPostMerge );
fprintf('%d total good matches, %d total bad matches.\n', numGoodMatches, numBadMatches)
fprintf(' %.2f%% precision\n', precision);
fprintf(' %.2f%% accuracy (top 100)\n', accuracy100);
% Visualize and save the result
if vis
fprintf('Saving visualization to eval.png\n')
saveas( gcf, 'eval.png' );
end


fpga和matlab
- 粉丝: 18w+
- 资源: 2657
最新资源
- 2023-04-06-项目笔记 - 第四百一十四阶段 - 4.4.2.412全局变量的作用域-412 -2025.02.19
- 基于STM32的智能环境系统设计20250211
- 基于元胞自动机法的枝晶生长模拟:任意角度偏心正方算法结合流体动力学LBM研究,基于元胞自动机法的枝晶生长模拟:任意角度偏心正方算法结合流体动力学LBM分析,C++程序,基于元胞自动机法模拟枝晶生长,能
- 单相全波可控整流电路:变压器中心抽头下的电流与波形特性研究,深入理解单相全波可控整流电路:原理、应用与参数计算,单相全波可控整流电路 此电路变压器是带中心抽头的,在u2正半周T1工作,变压器二次绕组
- terraform solace provider plugins
- MATLAB中蚁群算法在TSP问题上的应用研究,MATLAB实现蚁群算法求解旅行商TSP问题的优化策略,MATLAB 用蚁群算法解决旅行商TSP问题 ,MATLAB; 蚁群算法; 旅行商TSP问题
- 路径规划算法仿真:A星算法改进版,高效搜索与路径优化,带梯度下降及S-G滤波器处理,Matlab实现,可定量比较不同算法效果,改进A*算法:权重系数提升搜索效率、冗余拐角优化及路径平滑处理(Matla
- 基于C51单片机的花椒智能烘干设备的设计20250218
- 转速电流双闭环无传感器无刷直流电机Simulink模型解析:探究转速、转矩、反向电动势与三相电流之间的关系,转速电流双闭环无传感器无刷直流电机Simulink模型解析:探究转速、转矩、反向电动势与三相
- LaTeX-OCR-PRO图像识别项目实战
- Malab Simulink MW级直驱风机模型解析及参考文献资源分享,基于Malab Simulink构建的MW级直驱风机模型及其相关参考文献,Malab Simulink MW级直驱风机模型,附赠
- 风力永磁同步发电机设计及仿真分析:Maxwell电磁仿真在1.5兆瓦风力发电机中的应用与工况研究,基于Maxwell电磁仿真的1.5兆瓦风力永磁同步发电机设计与工况分析,1.5兆瓦风力发电机 maxw
- SCI计算复现系列:Pandat代算与自操作实践下的共晶成分设计-以Al-Cu-Si三元合金共晶点成分寻找为例,SCI计算复现:共晶成分设计实例-Al-Cu-Si三元合金共晶点成分的相图计算与Pa
- DeepSeek:本地搭建
- 基于双馈发电机与电池储能系统的频率调节控制策略Simulink模型研究,基于双馈发电机与电池储能系统的频率调节控制策略Simulink模型研究,风储调频 使用双馈发电机(DFIG)相关的电池储能系统
- 永磁同步电机PMSM模糊PI控制策略:详细搭建过程、仿真效果及与传统PI对比资料全套打包介绍,永磁同步电机PMSM模糊PI控制策略详解:搭建过程、参考资料、与传统PI对比及仿真效果展示,永磁同步电机P
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈


