飘逸的python - 使用图像匹配SIFT算法进行LOGO检测
2014-11-24 18:11
906 查看
先上效果图.
其中
是logo标识,
是待检测图片.
代码如下.
其中
是logo标识,
是待检测图片.
代码如下.
#coding=utf-8 import cv2 import scipy as sp img1 = cv2.imread('x1.jpg',0) # queryImage img2 = cv2.imread('x2.jpg',0) # trainImage # Initiate SIFT detector sift = cv2.SIFT() # find the keypoints and descriptors with SIFT kp1, des1 = sift.detectAndCompute(img1,None) kp2, des2 = sift.detectAndCompute(img2,None) # FLANN parameters FLANN_INDEX_KDTREE = 0 index_params = dict(algorithm = FLANN_INDEX_KDTREE, trees = 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] view = 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.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()
相关文章推荐
- 使用python进行图像目标检测需要配置的环境
- Feature Matching by using opencv(Python)-使用opencv进行图像特征匹配
- Python图像特征检测算法(1):Python实现SIFT和Harris
- SIFT特征点匹配中KD-tree与Ransac算法的使用
- SIFT特征点匹配中KD-tree与Ransac算法的使用
- 在Python中使用正则表达式同时匹配邮箱和电话并进行简单的分类
- 使用EMGU.CV对图像进行SIFT和SURF特征提取
- 图像匹配算法之初探尺度不变特征变换(SIFT)算法
- 数据结构-使用栈进行括号匹配算法
- opencv图像边缘检测使用,先做平滑处理在进行边缘检测
- 新手从零开始,相似图像匹配SIFT算法(二)
- sift是图像匹配的非常经典的算法
- 图像匹配之:经典sift算法(二)
- 用SIFT特征和RANSAC算法进行两幅图片的匹配
- 在Python中使用正则表达式同时匹配邮箱和电话并进行简单的分类
- 图像处理常用算法GPU实现三:基于模板匹配的边缘检测
- windows下配置eclipse + Python + PyDev + tornado,并使用pylint进行静态检测
- 利用特征点(Brief,ORB,SIFT)进行图像匹配,模板匹配
- python中使用OpenCV进行人脸检测的例子
- sift是图像匹配的非常经典的算法