No output from denoise_TVL1 in python

Hi all, I have tried simple code like below. But sadly i got no output from denoise_TVL1.

I have searched but it seems no one have ever found this. I have also tried in google colab and result is the same.

Is it a bug of OpenCV?

import cv2

color=cv2.imread('lena.png')

gray=cv2.cvtColor(color, cv2.COLOR_BGR2GRAY)

denoised=0

gray=[gray]

result=cv2.denoise_TVL1(gray, denoised)

print(denoised)

print(result)
1 Like

You pass an integer for the denoised parameter, not a Mat

please look at docs for this

(it returns None, but passing a result array is mandatory !)

{edit]

that said, i’m almost sure, that the python signature, generated from this:

https://github.com/opencv/opencv/blame/4.x/modules/photo/include/opencv2/photo.hpp#L325
is wrong ! result should be either an OutputArray or be annotated CV_OUT

in other words, @Fengyu_Guo , if you cant get it to work at all, it’s probably not your fault, but a bug.

ok, solution might be simple:

add a CV_OUT to the declaration here :

CV_EXPORTS_W void denoise_TVL1(const std::vector<Mat>& observations, CV_OUT Mat& result, double lambda=1.0, int niters=30);

then rerun cmake / make install

resulting cv2 should have this:

>>> help(cv2.denoise_TVL1)
denoise_TVL1(observations[, result[, lambda_[, niters]]]) -> result

so you can use:

>>> i = cv2.imread("7WoTn.png",0)
>>> cv2.denoise_TVL1([i])
array([[ 61,  59,  64, ..., 139, 139, 130],
       [ 61,  55,  61, ..., 139, 139, 128],
       [ 68,  65,  70, ..., 141, 141, 130],
       ...,
       [145, 146, 145, ..., 101, 102, 100],
       [143, 143, 143, ..., 102, 104,  99],
       [147, 148, 147, ..., 100,  99,  95]], dtype=uint8)

@Fengyu_Guo , since you found it, are you interested in committing ?

Hi Berak,

Thanks for your solution. I would be glad to submit a commit.

B.R.

Guo Fengyu