scipy
The SCIPY package contains various toolkits dedicated to common problems in scientific computing. Its different sub-modules correspond to different applications. Like interpolation, integration, optimization, image processing, special functions and so on.
SciPy can be compared with other standard scientific computing libraries, such as the GSL (GNU C or C + + Scientific Computing Library), or the MATLAB toolbox. SCIPY is the core package of the scientific computing program in Python, which is used to efficiently compute the numpy matrix to allow NumPy and scipy to work together.
Before implementing a program, it is worthwhile to check whether the required data processing method has already existed in scipy. As a non-professional programmer, scientists always like to reinvent the wheel, leading to loopholes, optimizations, and hard-to-share and maintainable code. Instead, the SCIPY program is optimized and tested so that it should be used whenever possible.
SCIPY consists of a number of sub-modules with specific functions, all of which depend on NumPy, but each is essentially independent.
As an example of a Debian Linux installation (although I use it on Windows):
Copy the Code code as follows:
sudo apt-get install python-numpy python-scipy python-matplotlib ipython ipython-notebook python-pandas python-sympy Python-nose
The standard way to import NumPy and these scipy modules is to:
Import NumPy as Npfrom scipy Import Stats # Other sub-modules are the same
The main scipy namespaces mostly contain real numpy functions (try Scipy.cos is Np.cos). These are only for historical reasons and there is usually no reason to use import scipy in your code.
Logo detection using image matching sift algorithm
First on:
Which is the logo mark,
The code is as follows.
#coding =utf-8 Import cv2 import scipy as sp IMG1 = Cv2.imread (' x1.jpg ', 0) # Queryimage img2 = cv2.imread (' x2.jpg ', 0) # TR Ainimage # Initiate SIFT Detector SIFT = Cv2. SIFT () # Find the keypoints and descriptors with SIFT kp1, des1 = Sift.detectandcompute (img1,none) kp2, des2 = Sift.detec Tandcompute (img2,none) # FLANN Parameters flann_index_kdtree = 0 Index_params = dict (algorithm = Flann_index_kdtree, tree s = 5) Search_params = Dict (checks=50) # or pass empty dictionary Flann = cv2. Flannbasedmatcher (index_params,search_params) matches = Flann.knnmatch (des1,des2,k=2) print ' matches ... ', Len ( Matches) # Apply ratio Test good = [] for m,n in Matches:if m.distance < 0.75*n.distance:good.append (m) print ' Good ', Len (good) # ##################################### # visualization h1, w1 = Img1.shape[:2] H2, W2 = Img2.shape[:2] VI ew = Sp.zeros ((max (H1, H2), W1 + W2, 3), sp.uint8) view[:h1,: w1, 0] = Img1 view[:h2, W1:, 0] = Img2 view[:,:, 1] = view[ :,:, 0] view[:,:, 2] = view[:,:, 0] for M in good: # draw the Keypoints # print M.queryidx, m.trainidx, m.distance color = tuple ([Sp.random.randi NT (0, 255) for _ in Xrange (3)]) #print ' kp1,kp2 ', Kp1,kp2 cv2.line (view, (int (kp1[m.queryidx].pt[0)), int (Kp1[m.queryid X].pt[1]), (int (kp2[m.trainidx].pt[0] + w1), int (kp2[m.trainidx].pt[1])), color) cv2.imshow ("View", view) Cv2.waitkey ()