简体   繁体   中英

Can't figure out what 'outImg' in opencv

here is my feature matching code from an Opencv tutorial

import numpy as np
import cv2 as cv
import matplotlib.pyplot as plt
img1 = cv.imread('roblox.jpg',0)          # queryImage
img2 = cv.imread('bloxro.jpg',0) # trainImage
orb = cv.ORB_create()
kp1, des1 = orb.detectAndCompute(img1,None)
kp2, des2 = orb.detectAndCompute(img2,None)
bf = cv.BFMatcher(cv.NORM_HAMMING, crossCheck=True)
matches = bf.match(des1,des2)
matches = sorted(matches, key = lambda x:x.distance)
img3 = cv.drawMatches(img1,kp1,img2,kp2,matches[:10], flags=2)
plt.imshow(img3),plt.show()

when it is run i get this error message

Traceback (most recent call last):
File "C:\Users\Blake\Desktop\Python3.7\opencvtests.py", line 19, in <module>
img3 = cv.drawMatches(img1,kp1,img2,kp2,matches[:10], flags=2)

TypeError: drawMatches() missing required argument 'outImg' (pos 6)

I'm not sure why the tutorial wrote the line that way, but the function drawMatches needs an output image to draw into as an argument after the matches.

You're missing that in your code, depending on what you want to do you can pass an empty image or an existing one (outImg in the following).

cv.drawMatches( img1, keypoints1, img2, keypoints2, matches1to2, outImg, matchColor, singlePointColor, matchesMask, flags   )

You can take look at the documentation of the function here . The following example after that one in the tutorial includes that as well.

The problem persisted on OpenCV python-opencv 4.0.0. I managed to solve it by creating empty ndarray as follows: outImg = np.empty((1,1)) . NumPy ndarray can grow on demand so it satisfies the requirement and creates correct preview.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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