[Computer Vision] Homework and network knowledge-3

Write in front

The code or pseudo-code in the article is an online excerpt, and my code is private!

hw2

1. Harris corner detection
Feature point calculation
Insert picture description here
Insert picture description here
Insert picture description here
Affine: (essential coordinate transformation)
Insert picture description here
Insert picture description here
Insert picture description here
non-maximum suppression (NMS)

When performing target detection, a window sliding method is generally adopted to generate many candidate frames on the image, and then these candidate frames are subjected to feature extraction and then sent to the classifier. Generally, a score is obtained, such as face detection , There will be scores on many boxes, and then all these scores are sorted. Select the box with the highest score, and then calculate the degree of overlap (iou) of the other boxes with the current box. If the degree of overlap is greater than a certain threshold, delete it, because there may be several boxes with high scores on the same face It ’s a human face but it does n’t need to be framed. We only need one.

Traverse the rest of the boxes, if the overlap area (IOU) with the current highest sub-frame is greater than a certain threshold, we will delete the box

MATLAB code found online

%% NMS:non maximum suppression
function pick = nms(boxes,threshold,type)
% boxes: m x 5,表示有m个框,5列分别是[x1 y1 x2 y2 score]
% threshold: IOU阈值
% type:IOU阈值的定义类型

    % 输入为空,则直接返回
    if isempty(boxes)
      pick = [];
      return;
    end

    % 依次取出左上角和右下角坐标以及分类器得分(置信度)
    x1 = boxes(:,1);
    y1 = boxes(:,2);
    x2 = boxes(:,3);
    y2 = boxes(:,4);
    s = boxes(:,5);

    % 计算每一个框的面积
    area = (x2-x1+1) .* (y2-y1+1);

    %将得分升序排列
    [vals, I] = sort(s);

    %初始化
    pick = s*0;
    counter = 1;

    % 循环直至所有框处理完成
    while ~isempty(I)
        last = length(I); %当前剩余框的数量
        i = I(last);%选中最后一个,即得分最高的框
        pick(counter) = i;
        counter = counter + 1;  

        %计算相交面积
        xx1 = max(x1(i), x1(I(1:last-1)));
        yy1 = max(y1(i), y1(I(1:last-1)));
        xx2 = min(x2(i), x2(I(1:last-1)));
        yy2 = min(y2(i), y2(I(1:last-1)));  
        w = max(0.0, xx2-xx1+1);
        h = max(0.0, yy2-yy1+1); 
        inter = w.*h;

        %不同定义下的IOU
        if strcmp(type,'Min')
            %重叠面积与最小框面积的比值
            o = inter ./ min(area(i),area(I(1:last-1)));
        else
            %交集/并集
            o = inter ./ (area(i) + area(I(1:last-1)) - inter);
        end

        %保留所有重叠面积小于阈值的框,留作下次处理
        I = I(find(o<=threshold));
    end
    pick = pick(1:(counter-1));
end

2. Patch matching

Distance measurement:

Σx, y (I (x, y)-J (x, y)) 2
Insert picture description here
find the best match

Random sample consensus algorithm (RANSAC)

Iteratively estimate the parameters of the mathematical model from a set of observed data containing outliers.

① Consider a model with a minimum sampling set potential of n (n is the minimum number of samples required to initialize the model parameters) and a sample set P, the number of samples in the set P # §> n, randomly select n samples from P The subset S of P initializes the model M;
② The sample set whose error in the residual set SC = P \ S is less than a certain set threshold t and S constitutes S *. S is considered to be an interior point set, and they constitute a consistent set of S (Consensus Set);
③If # (S
) ≥N, it is considered that the correct model parameters are obtained, and the least squares method is used by using the set S * (inliers) Recalculate the new model M *; re-randomly extract a new S and repeat the above process.
④ After completing a certain number of samplings, if the consistent set is not found, the algorithm fails. Otherwise, the largest consistent set obtained after sampling is used to judge the internal and external points, and the algorithm ends.

The pseudocode algorithm is as follows: (online)

输入:

Data       一组观测数据
Model     适应于数据的模型
 n        适应于模型的最小数据个数
 k        算法的迭代次数
 t         用于决定数据是否适应于模型的阈值
 d         判定模型是否适用于数据集的数据数目
参考链接:http://blog.csdn.net/pi9nc/article/details/26596519

Best_model  与数据最匹配的模型参数(没有返回null)

Best_consensus_set 估计出模型的数据点

Best_error   跟数据相关的估计出的模型错误

iterations = 0
best_model = null
best_consensus_set = null
best_error = 无穷大
while ( iterations < k )
maybe_inliers = 从数据集中随机选择n个点
maybe_model = 适合于maybe_inliers的模型参数
consensus_set = maybe_inliers

for ( 每个数据集中不属于maybe_inliers的点 )
if ( 如果点适合于maybe_model,且错误小于t )
将点添加到consensus_set
if ( consensus_set中的元素数目大于d )
已经找到了好的模型,现在测试该模型到底有多好
better_model = 适合于consensus_set中所有点的模型参数
this_error = better_model究竟如何适合这些点的度量
if ( this_error < best_error )
我们发现了比以前好的模型,保存该模型直到更好的模型出现
best_model =  better_model
best_consensus_set = consensus_set
best_error =  this_error
增加迭代次数
返回 best_model, best_consensus_set, best_error

Detailed SIFT algorithm

https://blog.csdn.net/zddblog/article/details/7521424

Published 29 original articles · praised 0 · visits 499

Guess you like

Origin blog.csdn.net/qq_43771959/article/details/104309183