飄逸的python,飄逸python

來源:互聯網
上載者:User

飄逸的python,飄逸python

先上.


其中是logo標識,

是待檢測圖片.


代碼如下.

#coding=utf-8import cv2import scipy as spimg1 = cv2.imread('x1.jpg',0) # queryImageimg2 = cv2.imread('x2.jpg',0) # trainImage# Initiate SIFT detectorsift = cv2.SIFT()# find the keypoints and descriptors with SIFTkp1, des1 = sift.detectAndCompute(img1,None)kp2, des2 = sift.detectAndCompute(img2,None)# FLANN parametersFLANN_INDEX_KDTREE = 0index_params = dict(algorithm = FLANN_INDEX_KDTREE, trees = 5)search_params = dict(checks=50)   # or pass empty dictionaryflann = cv2.FlannBasedMatcher(index_params,search_params)matches = flann.knnMatch(des1,des2,k=2)print 'matches...',len(matches)# Apply ratio testgood = []for m,n in matches:    if m.distance < 0.75*n.distance:        good.append(m)print 'good',len(good)# ###################################### visualizationh1, w1 = img1.shape[:2]h2, w2 = img2.shape[:2]view = sp.zeros((max(h1, h2), w1 + w2, 3), sp.uint8)view[:h1, :w1, 0] = img1view[:h2, w1:, 0] = img2view[:, :, 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.randint(0, 255) for _ in xrange(3)])    #print 'kp1,kp2',kp1,kp2    cv2.line(view, (int(kp1[m.queryIdx].pt[0]), int(kp1[m.queryIdx].pt[1])) , (int(kp2[m.trainIdx].pt[0] + w1), int(kp2[m.trainIdx].pt[1])), color)cv2.imshow("view", view)cv2.waitKey()


聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.