saint_burrito
saint_burrito

Reputation: 48

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

I'm currently working on implementation in python the algorithm presented in 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. I tried to find a solution that would get me a part of the image between those lines (with some set width) but I couldn't find any. I know that I could manually take values from pixels via calculating if they are under/above lines but maybe there is a more elegant solution to this problem? Do you guys have any idea or maybe experienced similar problem in the past?

Upvotes: 1

Views: 309

Answers (1)

balu
balu

Reputation: 1143

you can do like this

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)

enter image description here

Upvotes: 2

Related Questions