简体   繁体   English

使用opencv python检测SURF徽标

[英]SURF Logo detection with opencv python

I am trying to detect some logos of known software related things in pictures. 我试图在图片中检测一些已知软件相关事物的徽标。 I use Opencv 2.4.5 with python 2.7. 我使用Opencv 2.4.5和python 2.7。 I would like to use SURF detector implemented in opencv but the problem is that I don't obtain good results. 我想在opencv中使用SURF检测器,但问题是我没有获得好的结果。 There are lots of false negative and false positive. 有很多假阴性和假阳性。 My code is : 我的代码是:

import cv2
import numpy as np

def detectLogo(template, img):

    templateg = cv2.cvtColor(template, cv2.COLOR_BGR2GRAY)
    imgg = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)

    # SURF extraction
    hessian_threshold = 30
    surf = cv2.SURF(hessian_threshold)
    kp, desc = surf.detect(imgg, None, useProvidedKeypoints = False)

    # KNN
    samples = np.array(desc)
    responses = np.arange(len(kp), dtype = np.float32)
    knn = cv2.KNearest()
    knn.train(samples, responses)

    # Loading template and searching for similar kp
    kp2, desc2 = surf.detect(templateg, None, useProvidedKeypoints = False)

    matched = 0
    total = 0
    for h,des in enumerate(desc2):
        des = np.array(des,np.float32).reshape((1,128))
        retval, results, neigh_resp, dists = knn.find_nearest(des,1)
        res,dist =  int(results[0][0]),dists[0][0]
        total += 1
        if dist<0.1: # draw matched keypoints in red color
            color = (0,0,255)
            matched += 1
        else:
            color = (255,0,0)
        #Draw matched key points on original image
        x,y = kp[res].pt
        center = (int(x),int(y))
        cv2.circle(img,center,2,color,-1)

        #Draw matched key points on template image
        x,y = kp2[h].pt
        center = (int(x),int(y))
        cv2.circle(template,center,2,color,-1)

    cv2.imwrite("../resources/template.jpg", template)
    cv2.imwrite("../resources/image.jpg", img)
    return matched / float(total)

template = cv2.imread("../resources/pictures/appleLogo.jpg")
img = cv2.imread("../resources/pictures/pic2.jpg")
print detectLogo(template, img)

Below are results. 以下是结果。


(source: hostingpics.net ) (来源: hostingpics.net

Template url . 模板网址


(source: hostingpics.net ) (来源: hostingpics.net

Image url . 图片网址

Matched points don't correspond at all to the loho and I got same results for two completely different images. 匹配点与loho完全不对应,我得到两个完全不同的图像相同的结果。

I think it's the only solution to perform this task but where is the problem with this dectection ? 我认为这是执行此任务的唯一解决方案,但这次检测的问题在哪里? Thank you in advance. 先感谢您。

Alexandre 亚历山大

Interest points along edges get suppressed because they are not invariant in scale space. 沿着边缘的兴趣点被抑制,因为它们在尺度空间中不是不变的。 Since your logo is completely defined by edges, an intertest point detector that works like SURF (or SIFT) is not going to work very well. 由于您的徽标完全由边缘定义,因此像SURF(或SIFT)一样工作的中间点检测器不能很好地工作。 Probably training up a Haar classifier, like the Viola-Jones one in OpenCV, would work better. 可能训练一个哈尔分类器,就像OpenCV中的Viola-Jones一样,会更好。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM