I am using the cv2 library to detect key points of 2 stereo images and converted the resulting dmatches objects to a numpy array:
我正在使用cv2库来检测2个立体图像的关键点,并将生成的dmatches对象转换为numpy数组:
kp_left, des_left = sift.detectAndCompute(im_left, mask_left)
matches = bf.match(des_left, des_right) # according to assignment pdf
np_matches = dmatch2np(matches)
Then I want to filter matches if the key points are filtering, after y-direction, which should not differ bigger than 3 pixels:
然后我想过滤匹配点,如果关键点在y方向后过滤,不应该大于3个像素:
ind = np.where(np.abs(kp_left[np_matches[:, 0], 1] - kp_right[np_matches[:, 1], 1]) < 4)
AND those key points should also not have a difference smaller than < 0. Then it means the key point is behind the camera.
并且那些关键点也应该没有小于<0的差异。然后它意味着关键点在摄像机后面。
ind = np.where((kp_left[np_matches[ind[0], 0], 0] - kp_right[np_matches[ind[0], 1], 0]) >= 0)
How to combine those 2 conditions?
如何结合这两个条件?
1 个解决方案
#1
1
The general form is this:
一般形式是这样的:
condition1 = x < 4
condition2 = y >= 100
result = np.where(condition1 & condition2)
The even more general form:
更一般的形式:
conditions = [...] # list of bool arrays
result = np.where(np.logical_and.reduce(conditions))
#1
1
The general form is this:
一般形式是这样的:
condition1 = x < 4
condition2 = y >= 100
result = np.where(condition1 & condition2)
The even more general form:
更一般的形式:
conditions = [...] # list of bool arrays
result = np.where(np.logical_and.reduce(conditions))