Ask Your Question
0

Unsupported format or combination of formats

asked 2017-07-06 06:19:50 -0600

opencvpython gravatar image

updated 2017-07-06 06:28:03 -0600

berak gravatar image

Hello, below is my whole python code. I am running opencv 2.4.13

import cv2
import numpy as np
MIN_MATCH_COUNT=30

detector=cv2.ORB()
FLANN_INDEX_KDITREE=0
flannParam=dict(algorithm=FLANN_INDEX_KDITREE,tree=5)
flann=cv2.FlannBasedMatcher(flannParam,{})

trainImg=cv2.imread("TrainingData/TrainImg.png",0)
trainKP,trainDesc=detector.detectAndCompute(trainImg,None)

cam=cv2.VideoCapture(1)
while True:
    ret, QueryImgBGR=cam.read()
    QueryImg=cv2.cvtColor(QueryImgBGR,cv2.COLOR_BGR2GRAY)
    queryKP,queryDesc=detector.detectAndCompute(QueryImg,None)
    matches=flann.knnMatch(queryDesc,trainDesc,k=2)

    goodMatch=[]
    for m,n in matches:
        if(m.distance<0.75*n.distance):
            goodMatch.append(m)
    if(len(goodMatch)>MIN_MATCH_COUNT):
        tp=[]
        qp=[]
        for m in goodMatch:
            tp.append(trainKP[m.trainIdx].pt)
            qp.append(queryKP[m.queryIdx].pt)
        tp,qp=np.float32((tp,qp))
        H,status=cv2.findHomography(tp,qp,cv2.RANSAC,3.0)
        h,w=trainImg.shape
        trainBorder=np.float32([[[0,0],[0,h-1],[w-1,h-1],[w-1,0]]])
        queryBorder=cv2.perspectiveTransform(trainBorder,H)
        cv2.polylines(QueryImgBGR,[np.int32(queryBorder)],True,(0,255,0),5)
    else:
        print "Not Enough match found- %d/%d"%(len(goodMatch),MIN_MATCH_COUNT)
    cv2.imshow('result',QueryImgBGR)
    if cv2.waitKey(10)==ord('q'):
        break
cam.release()
cv2.destroyAllWindows()

However, it turns out the error message:C:\fakepath\Selection_004.png I wonder if it is related to FLANN with ORB...but I dont have any idea to change the code so that it can be run smoothly. PLease help!!!

edit retag flag offensive close merge delete

Comments

please add a text version of your stacktrace to your question, not a useless image.

berak gravatar imageberak ( 2017-07-06 06:29:13 -0600 )edit

1 answer

Sort by ยป oldest newest most voted
0

answered 2017-07-06 20:31:54 -0600

berak gravatar image

updated 2017-07-07 03:12:57 -0600

your flannmatcher (which is using L2 distance) does not work with ORB features (which are binary)

please use a BFMatcher with HAMMING or HAMMING2 distance instead.

edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2017-07-06 06:19:50 -0600

Seen: 3,686 times

Last updated: Jul 07 '17