如何在opencv中的指定行之间裁剪部分图像

How to crop part of the image between specified lines in opencv

我目前正在 python 中实现 https://arxiv.org/abs/1611.03270. In the following paper there is a part when we create epipolar lines and we want to take part of the image between those lines. Creation of the lines is fairly easy and it can be done with approach presented for instance here https://docs.opencv.org/3.4/da/de9/tutorial_py_epipolar_geometry.html 中提出的算法。我试图找到一个解决方案,让我在这些线之间(具有一些设定宽度)获得图像的一部分,但我找不到任何。我知道我可以通过计算像素是否为 under/above 行来手动从像素中获取值,但也许有更优雅的解决方案来解决这个问题?你们有什么想法或者过去可能遇到过类似的问题吗?

你可以这样做

import numpy as np
import cv2

# lets say this is our image
np.random.seed(42)
img =  np.random.randint(0, high=256, size=(400,400), dtype=np.uint8)
cv2.imshow('random image', img)


# we can create a mask with epipolar points and AND with the original image
mask = np.zeros([400, 400],dtype=np.uint8)
pts = np.array([[20,20],[100,350],[165,240],[30,30]], np.int32)
cv2.fillPoly(mask, [pts], 255)
cv2.imshow('mask', mask)


filt_img = img&mask
cv2.imshow('filtered image', filt_img)
cv2.waitKey(0)