Home > other >  Python, SIFT image feature detection method, implementation process cannot find SIFT file, a great g
Python, SIFT image feature detection method, implementation process cannot find SIFT file, a great g

Time:09-23

Here are my sift. Py code
 
The from PIL import Image
The from numpy import *
The from numpy. Core. Multiarray import ndarray
The from pylab import *
The from scipy. Ndimage import filters
The import OS

Def process_image (imagename resultname, params="-- edge - thresh 10"
"-- peak - thresh 5") :
"" "processing an image, and then save the results in the file "" "

If imagename [- 3:]!='PGM:
# to create a PGM file
Im=Image. Open (imagename). The convert (' L ')
Im. Save (' TMP. PGM)
Imagename='TMP. PGM'

CMMD=STR (" C:/Users/qiy8/PycharmProjects/learning_computer_version "
"/VLFeat/win32/sift. Exe" + imagename +
"- the output=" + resultname
+ "" + params)
OS. The system (CMMD)
Print (" processed ", imagename, 'to', resultname)

Def read_features_from_file (filename) :
"" "read the feature attribute value, then returned in the form of matrix ", "
"
F=loadtxt (filename)
Return f [: : 4), f [:, 4:] # feature location, descriptor

Def write_features_to_file (filename, locs, desc) :
"" "to save feature location and description in the file "" "
Savetxt (filename, hstack ((locs, desc)))

Def plot_features (im, locs, circle=False) :
With the characteristics of the images displayed "" "
Input: im images (array), locs (characteristics of each row, column, direction and scale ", "
"
Def draw_circle (c, r) :
T=arange (0, 1.01,.01) * 2 * PI
X=r * cos (t) + c [0]
Y=r * sin (t) + c [1]
Plot (x, y, 'b', our linewidth=2)

Imshow (im)
If circle:
For p in locs:
Draw_circle (p [: 2], [2] p)
The else:
The plot (locs [: 0], locs [: 1], 'ob')
The axis (' off ')

Def match (desc1 desc2) :
"" "for the first image of each descriptor, select it in the second picture in the image matching
Input: desc1 (described in the first image), desc2 (described in the second image) ", "
"
Desc1=array ([d/linalg norm (d) for d in desc1])
Desc2=array ([d/linalg norm (d) for d in desc2])
Dist_ratio=0.6
Desc1_size=desc1. Shape

Matchscores=zeros ((desc1_size [0], 1), 'int')
Desc2t=desc2. T # pre-computed matrix transpose
For I in range (desc1_size [0]) :
Dotprods=dot (desc1 [I:], desc2t) # vector dot product
Dotprods=0.9999 * dotprods
# and the arccosine of sorting, return to the second image characteristics index
Indx=argsort (arccos (dotprods))

# check whether the adjacent Angle less than dist_radio multiplied by the Angle of the second neighbor
If arccos (dotprods) [indx [0]] Matchscores [I]=int (indx [0])

Return matchscores

Def match_twosided (desc1 desc2) :
Two-way symmetric version of the match "" "" ""

Matches_12=match (desc1 desc2)
Matches_21=match (desc2, desc1)

Ndx_12=matches_12. Nonzero () [0]

# remove the asymmetric matching
For n in ndx_12:
If matches_12 [int (matches_12 [n])]!=n:
Matches_12 [n]=0

Return matches_12

Def appendimages (im1, im2) :
"" "return to two images were joining together into a new image of "" "

# selected has a minimum number of lines of image, and then fill in enough empty rows
Rows1=im1. Shape [0]
Rows2=im2. Shape [0]

If rows1 & lt; Rows2:
Im1=concatenate ((im1, zeros ((rows2 - rows1 im1), shape [1]))), the axis=0)
The else:
Im2=concatenate ((im2, zeros ((rows1 - rows2, im2 shape [1]))), the axis=0)
# if these conditions are not, then they have the same number of rows, don't need to fill the

Return concatenate (im1, im2), axis=1)

Def plot_matches (im1, im2, locs1 locs2, matchscores, show_below=True) :
"" "shows a picture of connections between matching with attachment
Input: im1, im2 (array), locs1, locs2 characteristics (location), matchscores (match () output),
Show_below (if the image should be down to the bottom of the first in the match) ", "
"
Im3=appendimages (im1, im2)
If show_below:
Im3=vstack ((im3, im3))

Imshow (im3)

Cols1=im1. Shape [1]
For I, m in enumerate (matchscores) :
If m & gt; 0:
Plot ([locs1 [1], [I] locs2 + cols1] [m] [1], [locs1 [0], [I] locs2 [m] [
0]], 'c')
The axis (' off ')


The following is the code I used to do validation practice
 
The from PIL import Image
The from numpy import *
The from numpy. Core. Multiarray import ndarray
The from pylab import *
The from scipy. Ndimage import filters
The import sift
Imname='empire. JPG'
Im1=array (Image. Open (imname). The convert (' L '))
Sift. Process_image (imname, 'empire. Sift)
L1, d1=sift. Read_features_from_file (' empire. Sift)

Figure ()
Gray ()
Sift. Plot_featrues (im1, l1, circle=True)
Show ()

This is my code error screenshot
Have tried https://blog.csdn.net/lilai619/article/details/48523647 solution but finally mentioned in this post is really useless, look from the error, seemingly or CMMD that line didn't work, my computer is win764 system, and an intern in the company permission to this computer has a lot of restrictions, do not know the program implementation has any influence on me, hope your bosses to help overcome

CodePudding user response:

Please, help me ah really don't know how to return a responsibility!

CodePudding user response:

I also am this problem, can't find sift. Exe so couldn't generate empire. Sift, then I put the win64vlfeat inside of sift. Exe in and sift py the same directory, CMMD=STR (" sift. Exe "+ imagename +
"- the output=" + resultname
+ "" + params)

CodePudding user response:

Could you tell me how to generate the sift, I have been an error:
Traceback (the most recent call last) :
The File "/home/Aaron/python/procedure/ch02 p43 - sift. Py", line 17, in & lt; module>
L1, d1=sift. Read_features_from_file (' im0. Sift)
The File "/usr/local/lib/python3.5/dist - packages/PCV/localdescriptors/sift. Py", line 25, in read_features_from_file
nullnullnullnullnullnullnullnullnullnullnullnullnullnullnull