1
I have a function that opens an image and sums with a random matrix but the function cv2.addWeighted
generates the following error even though the types of the two matrices are equal :
Traceback (most recent call last):
File "/home/user/Área de Trabalho/Pasta/test.py", line 17, in <module>
Noise()
File "/home/user/Área de Trabalho/Pasta/test.py", line 10, in Noise
gaussian_noise = cv2.addWeighted(img,0.5,gaussian, 0.25, 0)
cv2.error: OpenCV(4.0.0) /io/opencv/modules/core/src/arithm.cpp:687: error: (-5:Bad argument) When the input arrays in add/subtract/multiply/divide functions have different types, the output array type must be explicitly specified in function 'arithm_op'
So I decided to add in the same hand( what worked) but at the time of showing, the result is all dark, which does not match the reality. Follow the code :
# -*- coding: utf-8 -*-
import cv2
import numpy as np
def Noise():
img = cv2.imread('Imagen.jpg')
# print(img)
l,c,x=img.shape
gaussian = np.int_(np.random.random((l, c, 3))*10)
#gaussian_noise = cv2.addWeighted(img,0.5,gaussian, 0.25, 0)
gaussian_noise=gaussian+img
print(gaussian_noise)
cv2.imshow("Original",img)
cv2.imshow("Noise",gaussian_noise)
cv2.waitKey(0)
Noise()
Does anyone know why the cv2.imshow("Noise",gaussian_noise)
everything is appearing dark if the matrix has correct values ?
Thanks for the answer. I found interesting the way in which it generated the random numbers and especially the one of showing the 2 images with np.hstack.
– Beto