OpenCV 3.0.0-dev

asked 2014-06-25 23:41:26 -0600

Drakko gravatar image

updated 2017-12-24 11:02:16 -0600

Hi! I'm using opencv3.0.0-dev because I have some problems with drawMatching functions. I see always fine but when I'm trying to run this Code that is feature2D example with a videocapture I got Segmentation Fault in different parts of the Code like waitKey and I don't know how to solve it's to rare for me Thanks!.

`

import numpy as np import cv2

MIN_MATCH_COUNT = 10

cap = cv2.VideoCapture(1)

while(cap.isOpened()): # Capture frame-by-frame

ret, frame = cap.read()

frame = frame.copy()

# Our operations on the frame come here
img1 = cv2.imread('dog.jpg',0)
img2 = frame

# Display the resulting frame
if cv2.waitKey(1) & 0xFF == ord('q'):
    break

sift = cv2.SIFT()
# find the keypoints and descriptors with SIFT
kp1, des1 = sift.detectAndCompute(img1,None)

if des1 is None:
    des1 = []

kp2, des2 = sift.detectAndCompute(img2,None)
if des2 is None:
    des2 = []

FLANN_INDEX_KDTREE = 0
index_params = dict(algorithm = FLANN_INDEX_KDTREE, trees = 5)
search_params = dict(checks = 10)

flann = cv2.FlannBasedMatcher(index_params, search_params)


matches = flann.knnMatch(des1,des2,k = 2)

# store all the good matches as per Lowe's ratio test.
good = []
if matches is None:
    matches = []
for m,n in matches:
    if m.distance < 0.7*n.distance:
        good.append(m)

if len(good) > MIN_MATCH_COUNT:
    src_pts = np.float32([ kp1[m.queryIdx].pt for m in good ]).reshape(-1,1,2)
    dst_pts = np.float32([ kp2[m.trainIdx].pt for m in good ]).reshape(-1,1,2)

    M, mask = cv2.findHomography(src_pts, dst_pts, cv2.RANSAC,5.0)
    matchesMask = mask.ravel().tolist()

    h,w = img1.shape
    pts = np.float32([ [0,0],[0,h-1],[w-1,h-1],[w-1,0] ]).reshape(-1,1,2)
    dst = cv2.perspectiveTransform(pts,M)

    img2 = cv2.polylines(img2,[np.int32(dst)],True,255,3, cv2.LINE_AA)

else:
    print "Not enough matches are found - %d/%d" % (len(good),MIN_MATCH_COUNT)
    matchesMask = None

draw_params = dict(matchColor = (0,255,0), # draw matches in green color
                       singlePointColor = None,
                       matchesMask = matchesMask, # draw only inliers
                       flags = 2)

#img3 = cv2.drawMatches(img1,kp1,img2,kp2,good,None,**draw_params)

#plt.imshow(img2, 'gray'),plt.show()
cv2.imshow('frame',img2)
cv2.waitKey(1)

When everything done, release the capture

cap.release() cv2.destroyAllWindows()`

edit retag flag offensive close merge delete