geniant
geniant

Reputation: 123

Apply a filter on some specific points in openCV

In OpenCV Library, filers are applied on all the image which costs time and CPU load when you need a specific result on a high resolution image.

Is there a method to apply it only on some specific points (contours for example)

Upvotes: 1

Views: 1813

Answers (1)

Humam Helfawi
Humam Helfawi

Reputation: 20264

You can apply it on rectangular region like this:

img = cv2.imread('some_image.jpg')
roi_of_img = img[col:col+width,row:row+height]

then apply what you want on roi_of_img

if you want to apply it on contour, you have two options:

  1. deal with it as rectangle (found the bounding rect of the contour as follow:

    col, row, width, height = cv2.boundingRect(contours[i])

  2. Deal with the rectangle bounding box and then apply bitwise and mask between the area inside the contour and the result of the ROI

Upvotes: 1

Related Questions