Ask Your Question
0

How to use cv.boxFilter() in python

asked 2013-03-18 14:18:30 -0600

shobhitpuri gravatar image

I am having following error when I use the boxFilter function:

SystemError: new style getargs format but argument is not a tuple

Here is the code sniplet:

//After downloading image from url, I process it as follows
imgcv = cv2.cvtColor(np.asarray(im), cv.CV_RGB2YCrCb)
#Get the channel 0 
imgcv1 = cv2.split(imgcv)[0] 
cv2.boxFilter(imgcv1, 1, 7, data, (1,1), 0, cv2.BORDER_DEFAULT)

It says the argument is not a tuple. How to make it into tuples? I tried to search a lot but no helpful results. I am a beginner in openCV and in python. Here is the definition of the filter:

cv2.boxFilter(src, ddepth, ksize[, dst[, anchor[, normalize[, borderType]]]]) → dst
Parameters: 
    src – Source image.
    dst – Destination image of the same size and type as src .
    ksize – Smoothing kernel size.
    anchor – Anchor point. The default value Point(-1,-1) means that the anchor is at the kernel center.
    normalize – Flag specifying whether the kernel is normalized by its area or not.
    borderType – Border mode used to extrapolate pixels outside of the image.
edit retag flag offensive close merge delete

2 answers

Sort by » oldest newest most voted
2

answered 2013-03-19 12:12:50 -0600

Guanta gravatar image

I guess: The kernel-size should be not just 7, but (7,7) . I often struggle with using the Python interface, too. Additionally it may be that the anchor-point has to be ((1,1)). For 'normalize' you probably should also use 'False'. Good luck!

edit flag offensive delete link more

Comments

Thanks for the reply @Guanta. You are extremely right. Finally, I did the same and got that working.

shobhitpuri gravatar imageshobhitpuri ( 2013-03-21 08:33:09 -0600 )edit
1

When I used 'False' in Normalized, I was receiving and empty white image. Then I used 'True' after reading the wiki article here: http://en.wikipedia.org/wiki/Kernel_%28image_processing%29 It says: For Blur, you need to Normalize the image. Normalization ensures that the pixel values in the output image are of the same relative magnitude as those in the input image.

I was able to see the image saved after the boxFilter.

shobhitpuri gravatar imageshobhitpuri ( 2013-03-22 11:17:39 -0600 )edit
0

answered 2013-03-21 08:35:56 -0600

shobhitpuri gravatar image

@Guanta is extremely right. I got that working as follows:

cv2.boxFilter(imgcv1, 0, (7,7), imgcv1, (-1,-1), False, cv2.BORDER_DEFAULT)
edit flag offensive delete link more

Question Tools

Stats

Asked: 2013-03-18 14:18:30 -0600

Seen: 6,106 times

Last updated: Mar 21 '13