Raspberry pi 3代码无效

时间:2018-05-21 07:49:24

标签: raspberry-pi3

这是编码没有产生任何错误,但它不能正常工作,我不知道。我正在使用覆盆子pi 3进行物体检测。

min_match_count =30

detector = cv2.xfeatures2d.SIFT_create()

FLANN_INDEX_KDTREE=0

flannparam=dict(algorithm=FLANN_INDEX_KDTREE,tree=5)

search=dict(checks=50)

flann=cv2.FlannBasedMatcher(flannparam,search)

trainimg=cv2.imread('/home/pi/Downloads/img1.jpg',0)

trainkp,traindecs=detector.detectAndCompute(trainimg,None)

cam=PiCamera()

cam.resolution=(480,480)

cam.framerate = 40

r_cap =PiRGBArray(cam)

for frm in cam.capture_continuous(r_cap,format = 'bgr', use_video_port = True):

    QueImg = frm.array

    gry=cv2.cvtColor(QueImg,cv2.COLOR_BGR2GRAY)

    quekp,quedecs=detector.detectAndCompute(gry,None)

    matches= flann.knnMatch(quedecs,traindecs,k=2)

    goodmatch=[]

    for (m,n) in matches:
        print('after whi')
        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(quekp[m.queIdx].pt)
        tp,qp=np.float32((tp,qp))
        H,status=cv2.findHomography(tp,qp,cv2.RANSAC,3.0)
        h,w=trainimg.shape
        trainingborder=np.float32([[[0,0],[0,h-1],[w-1,h-1],[0,h-1]]])
        queborder=cv2.perspectiveTransform(trainingborder,H)
        cv2.polylines(QueImg,[np.int32(queborder)],True,(0,255,0),5)    
    else:
        print('Not enough matches - %d/%d'%(len(goodmatch),min_match_count))

    cv2.imshow('result',QueImg)
    r_cap.truncate(0)



cam.release()
cv2.destroyAllWindows()

任何资源都受到高度赞赏 提前致谢

0 个答案:

没有答案