SIFT原理-C实现的sift

英文:

http://aishack.in/tutorials/sift-scale-invariant-feature-transform-introduction/

http://weitz.de/sift/

https://gitlab.com/hamim_aziz/skripsi

中文:

https://blog.csdn.net/jancis/article/details/80824793

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

https://www.cnblogs.com/jsxyhelu/p/7591497.html

https://blog.csdn.net/abcjennifer/article/details/7639681/

https://wenku.baidu.com/view/87270d2c2af90242a895e52e.html

https://www.cnblogs.com/wangguchangqing/p/9176103.html

 

代码:

https://codeload.github.com/vlfeat/vlfeat/zip/v0.9.21

http://www.vlfeat.org/overview/sift.html

vlfeat-0.9.21/toolbox/plotop/vl_plotframe.m

vlfeat-0.9.21/toolbox/sift/vl_plotsiftdescriptor.m

http://www.ipol.im/pub/art/2014/82/sift_anatomy_20141201.zip

Automatic Homographic Registration of a Pair of Images, with A Contrario Elimination of Outliers

http://demo.ipol.im/demo/mmm_orsa_homography/

https://www.ipol.im/pub/art/2012/mmm-oh/OrsaHomography_20120515.tar.gz

https://github.com/pmoulon/IPOL_AC_RANSAC/tree/master/src/third_party/sift_anatomy ***

./demo_orsa_homography ../../data/carc1.jpg ../../data/carc2.jpg all.txt in.txt in.jpg out.jpg pano.jpg

https://github.com/MISS3D/s2p/tree/master/3rdparty/sift_anatomy_20140911

 

修改:

    if(flagverb_keys == 1){
        sprintf(name,"extra_NES_%s.txt",label_keys);              sift_save_keypoints(kk[0], name, 0);
        sprintf(name,"extra_DoGSoftThresh_%s.txt",label_keys);    sift_save_keypoints(kk[1], name, 0);
        sprintf(name,"extra_ExtrInterp_%s.txt",label_keys);       sift_save_keypoints(kk[2], name, 0);
        sprintf(name,"extra_DoGThresh_%s.txt",label_keys);        sift_save_keypoints(kk[3], name, 0);
        sprintf(name,"extra_OnEdgeResp_%s.txt",label_keys);       sift_save_keypoints(kk[4], name, 0);
        sprintf(name,"extra_FarFromBorder_%s.txt",label_keys);    sift_save_keypoints(kk[5], name, 0);
        //extra_keypoints_[label].txt
        sprintf(name,"extra_keypoints_%s.txt",label_keys);    sift_save_keypoints(k, name, 2);
    }

关于这个flag取多少,是干嘛的,请看:

void fprintf_one_keypoint(FILE* f, const struct keypoint* k, int n_descr, int n_bins, int flag)
{
    // coordinates
    fprintf(f,"%f %f %f %f ", k->x
                            , k->y
                            , k->sigma
                            , k->theta);

    if (flag>0){
        // descriptor
        for(int n = 0; n < n_descr; n++){
            fprintf(f,"%i ", (int)k->descr[n]);
        }
    }
    if (flag>1){
        // orientation histogram
        for(int n = 0; n < n_bins; n++){
            fprintf(f,"%f ", k->orihist[n]);
        }

    }
}

如果是1,只输出x,y,s,t,128 = 132

19.462023 223.683273 1.063731 -3.128005 12 24 4 6 41 64 3 6 10 45 20 21 37 13 6 1 0 2 1 4 39 87 9 0 8 11 4 1 27 72 6 2 112 103 0 0 1 5 8 31 82 51 2 0 0 29 73 55 124 17 1 0 5 66 50 29 91 111 14 0 5 10 3 11 173 50 0 0 0 0 1 26 173 4 0 0 0 1 14 99 173 14 0 0 0 0 4 33 173 53 0 0 0 0 0 5 32 1 0 0 1 3 2 4 50 1 0 1 3 3 1 3 55 0 0 1 3 2 1 7 44 5 2 1 0 0 0 1 

如果是2,输出x,y,s,t,128,bin数目(36) = 168

19.462023 223.683273 1.063731 -3.128005 12 24 4 6 41 64 3 6 10 45 20 21 37 13 6 1 0 2 1 4 39 87 9 0 8 11 4 1 27 72 6 2 112 103 0 0 1 5 8 31 82 51 2 0 0 29 73 55 124 17 1 0 5 66 50 29 91 111 14 0 5 10 3 11 173 50 0 0 0 0 1 26 173 4 0 0 0 1 14 99 173 14 0 0 0 0 4 33 173 53 0 0 0 0 0 5 32 1 0 0 1 3 2 4 50 1 0 1 3 3 1 3 55 0 0 1 3 2 1 7 44 5 2 1 0 0 0 1 0.000267 0.000716 0.001806 0.004052 0.007860 0.013052 0.018560 0.022773 0.024490 0.023772 0.021965 0.021141 0.023900 0.033593 0.053764 0.084455 0.118877 0.143167 0.145112 0.122067 0.084632 0.047662 0.021810 0.008205 0.002882 0.001112 0.000508 0.000220 0.000098 0.000051 0.000033 0.000027 0.000027 0.000033 0.000051 0.000105 

所以等会儿的可视化,对于两种不同的情况,记得用python对OUTmatches.txt,进行正确的切分

输出金字塔图像

./sift_cli img2.png -verb_ss img2

输出txt

./sift_cli img1.png -verb_keys img1

./sift_cli img2.png -verb_keys img2 

输出匹配txt

./match_cli extra_keypoints_img1.txt extra_keypoints_img2.txt -verb output

可视化:画出点

 
# -*- coding:utf-8 -*-
import os
import cv2
import sys
import numpy as np
 
 
# img = cv2.imread("/home/spple/CLionProjects/SIFT_C/sift_anatomy_20141201/bin/P1000966.JPG", -1)
# cv2.imwrite("/home/spple/CLionProjects/SIFT_C/sift_anatomy_20141201/bin/img2.png",img)
 
#x1  y1  sigma1  theta1   x2  y2  sigma2  theta 2
#save_pairs_extra("OUTmatches.txt", out_k1, out_k2A, out_k2B);
#
# with open("extra_keypoints_img1.txt", "r") as data:
#     for line in data:
#         line = line.replace("\n", "").replace("\r", "")
#         lines = line.split(' ')
#         num = len(lines)
#         print(line)
 
'''
10) extra_keypoints_[label].txt           keypoints with descriptors
        Each line of this file follows the data formatting
            x  y  sigma  theta  octa  sca fv[1] fv[2] ... fv[d] ...
                                         ... orihist[1] ... orihist[n_bins]
        where (fv) is the feature vector of dimension d=n_hist*n_hist*n_ori
        and (orihist) is the orientation histogram of n_bins bins.
        
        
File 1) has the following formatting:
      key1  key2a  key2b
where (key1) designates a keypoint in image1, (key2a) and (key2b) designate
respectively the nearest and the second nearest neighbors in image 2.
The data relative to each keypoint is formatted as follows
      x  y  sigma  theta  fv[1] fv[2] ... fv[d]
                        octa sca   orihist[1] ... orihist[n_bins]
where (fv) is the feature vector of dimension d=n_hist*n_hist*n_ori  and
(orihist) is the orientation histogram of n_bins bins.
Files 3) 4) and 5) have the same formatting:
      x  y  sigma  theta  fv[1] fv[2] ... fv[d]
                        octa sca   orihist[1] ... orihist[n_bins]
'''
 
one = []
two = []
with open("OUTmatches.txt", "r") as data:
    for line in data:
        #print(len(line.split(' ')))
        mline = line.replace("\n", "").replace("\r", "").replace("\r", "")
        lines = mline.split(' ')
        num = len(lines)
        #print(lines[-2])
        c = lines[-1]
        # 最后一个为‘’ 504/3=168  128 + 36
        mlines = lines[:-1]
        one.append( ( float(mlines[0]), float(mlines[1]) ) )
        two.append( ( float(mlines[168]), float(mlines[169]) ) )
        b = 1
 
debug = 1
if debug == 0:
    fn1 = './img1.png'
    fn2 = './img2.png'
else:
    fn1 = './input_0.png'
    fn2 = './input_1.png'
img1 = cv2.imread(fn1, cv2.IMREAD_GRAYSCALE)
img2 = cv2.imread(fn2, cv2.IMREAD_GRAYSCALE)
if img1 is None:
    print('Failed to load fn1:', fn1)
    sys.exit(1)
if img2 is None:
    print('Failed to load fn2:', fn2)
    sys.exit(1)
 
h1, w1 = img1.shape[:2]
h2, w2 = img2.shape[:2]
vis = np.zeros((max(h1, h2), w1+w2), np.uint8)
vis[:h1, :w1] = img1
vis[:h2, w1:w1+w2] = img2
vis = cv2.cvtColor(vis, cv2.COLOR_GRAY2BGR)
 
vis1 = vis.copy()
vis2 = vis.copy()
 
green = (0, 255, 0)
red = (0, 0, 255)
for (x1, y1), (x2, y2) in zip(one, two):
    col = green
    thickness = 1
    cv2.line(vis1, (int(y1), int(x1)), (int(y2), int(x2)), col, thickness)
cv2.imwrite("./result1.png", vis1)
 
for (x1, y1), (x2, y2) in zip(one, two):
    col = green
    thickness = 1
    cv2.line(vis2, (int(y1), int(x1)), (int(y2)+w1, int(x2)), col, thickness)
cv2.imwrite("./result2.png", vis2)

http://robwhess.github.io/opensift/ 

---Rob Hess http://robwhess.github.io/opensift/siftlib-acmmm10.pdf

---lowe          https://www.cs.ubc.ca/~lowe/papers/ijcv04.pdf

https://download.csdn.net/download/zddmail/4264810

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值