1

ive got a problem that i cant solve. Im trying to make a temporal median filter using the method sort(), but i simply cant do it. This is the simpliest test i tried:

import cv2

def sortExample():

    img = cv2.imread("guitar.jpg")
    cv2.sort(img, cv2.SORT_ASCENDING)

sortExample()

And the error:

cv2.sort(img, cv2.SORT_ASCENDING) cv2.error: ......\src\opencv\modules\core\src\matrix.cpp:2367: error: (-215) src.dims <= 2 && src.channels() == 1 && func != 0

What am i doing wrong? Thanks in advance

1 Answer 1

1

The error message is telling you that the checks src.dims <= 2 && src.channels() == 1 && func != 0 failed (maybe if it was less cluttered you would have no trouble seeing that ?). In special, it is telling you the number of channels is not 1.

So you can either consider one of the channels or convert the image to, for example, grayscale: x = cv2.cvtColor(x, cv2.COLOR_BGR2GRAY).

Sign up to request clarification or add additional context in comments.

2 Comments

yes mate you did that... now that i think about it, its really stupid having the image in RGB. Thanks (:
A little bit of a necropost, but if you wanted to sort the image by one of the colour channels, how would you do that?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.