Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Opencv-python: Type of input image should be CV_8UC3 or CV_8UC4! in function fastNlMeansDenoisingColored

I wrote a simple opencv program, which reduce the noise of images.

import cv2
import numpy as np
from matplotlib import pyplot as plt

img = cv2.imread('stream/horse.png')

dst = cv2.fastNlMeansDenoisingColored(img, None, 10, 10, 7, 21)

cv2.imshow(dst)
plt.subplot(121), plt.imshow(img)
plt.subplot(122), plt.imshow(dst)
plt.show()

horse.png

When I ran the program it gave an error. Which is...

OpenCV Error: Bad argument (Type of input image should be CV_8UC3 or CV_8UC4!) in fastNlMeansDenoisingColored, file /home/govinda/github_repos/opencv/modules/photo/src/denoising.cpp, line 176
Traceback (most recent call last):
  File "/home/govinda/workspace-python/opencv/src/Smle.py", line 7, in <module>
    dst = cv2.fastNlMeansDenoisingColored(img, None, 10, 10, 7, 21)
cv2.error: /home/govinda/github_repos/opencv/modules/photo/src/denoising.cpp:176: error: (-5) Type of input image should be CV_8UC3 or CV_8UC4! in function fastNlMeansDenoisingColored

How should I over come this?

like image 536
Govinda Malavipathirana Avatar asked Jun 17 '17 06:06

Govinda Malavipathirana


1 Answers

you need to convert the image like this:

converted_img = cv2.cvtColor(img, cv2.COLOR_GRAY2BGR)

A little late to help you, but I hope it helps someone.

Cheers!

like image 55
Gleidson Cardoso da Silva Avatar answered Sep 19 '22 03:09

Gleidson Cardoso da Silva