OpenCV Python: normalize image

I am new to OpenCV. I want to do some preprocessing related to normalization. I want to normalize the image to a certain size. The result of the following code gives me a black image. Can someone tell me what exactly am I doing wrong? The image I entered is a black and white image

import cv2 as cv import numpy as np img = cv.imread(path) normalizedImg = np.zeros((800, 800)) cv.normalize(img, normalizedImg, 0, 255, cv.NORM_MINMAX) cv.imshow('dst_rt', self.normalizedImg) cv.waitKey(0) cv.destroyAllWindows() 
+6
source share
3 answers

as can be seen at: http://docs.opencv.org/2.4/modules/core/doc/operations_on_arrays.html#cv2.normalize , there are → dst , which say that the result of the normalize function is returned as an output parameter. The function does not change the dst input parameter in place. (The line self. In cv.imshow('dst_rt', self.normalizedImg) is a typo)

 import cv2 as cv import numpy as np path = r"C:\Users\Public\Pictures\Sample Pictures\Hydrangeas.jpg" img = cv.imread(path) normalizedImg = np.zeros((800, 800)) normalizedImg = cv.normalize(img, normalizedImg, 0, 255, cv.NORM_MINMAX) cv.imshow('dst_rt', normalizedImg) cv.waitKey(0) cv.destroyAllWindows() 
+1
source

This gives you a black image because you are probably using different sizes in img and normalizedImg.

 import cv2 as cv img = cv.imread(path) img = cv.resize(img, (800, 800)) cv.normalize(img, img, 0, 255, cv.NORM_MINMAX) cv.imshow('dst_rt', img) cv.waitKey(0) cv.destroyAllWindows() 
0
source

When you call cv.imshow() , you use self.normalizedImg instead of normalizedImg .

I. is used to identify members of the class, and its use in the code you wrote is not suitable. It should not even start as it is written. However, I assume that this code was extracted from the class definition, but you must be consistent in the variable names and self.normalizedImg is different from normalizedImg .

0
source

Source: https://habr.com/ru/post/1012394/


All Articles