Python-OpenCV extension and blur functions do not change anything

Given the code below, the cv2.dilate and cv2.erode functions in python return the same image that I send to it. What am I doing wrong? I am using OpenCV3.0.0. and numpy1.9.0 on iPython 2.7

im = np.zeros((100,100), dtype=np.uint8) im[50:,50:] = 255 dilated = cv2.dilate(im, (11,11)) print np.array_equal(im, dilated) 

What returns:

 True 

{} Edited Another extended post is a kernel type question. This message actually reflects a function call error.

+5
source share
4 answers

A function requires a kernel, not a kernel size. Thus, the correct function call will be lower.

 dilated = cv2.dilate(im, np.ones((11, 11))) 
+10
source

You need to specify the correct kernel. It can be rectangular, round, etc.

 kernel = cv2.getStructuringElement(cv2.MORPH_ELLIPSE, (5,5)) im = np.zeros((100,100), dtype=np.uint8) im[50:,50:] = 255 dilated = cv2.dilate(im, kernel, iterations = 1) 
+1
source

I think this is related to your second line where you are modifying the array. The data type is probably infected.

0
source

the function should be called as follows: cv2.dilate (img (input), kernel, iterations = number (how many times do you want to apply a filter)

0
source

Source: https://habr.com/ru/post/1215625/


All Articles