Я пытаюсь изменить размер 1920X1080 и скопировать оттенки серого на белый фон размером 128X32. Но я получаю эту ошибку:
Traceback (most recent call last):
File "C:/Users/bnsid/Desktop/SimpleHTR-master - Copy/src/SamplePreprocessor.py", line 39, in <module>
main()
File "C:/Users/bnsid/Desktop/SimpleHTR-master - Copy/src/SamplePreprocessor.py", line 32, in main
cv2.imshow('Greyscale_Stretched', target('float32'))
TypeError: 'numpy.ndarray' object is not callable
Мой код:
from __future__ import division
from __future__ import print_function
import random
import numpy as np
import cv2
def main():
"put img into target img of size imgSize, transpose for TF and normalize gray-values"
img=cv2.imread("C:\\Users\\bnsid\\OneDrive\\Pictures\\Windows Spotlight Images\\fe22f9acd3313c5e21f8a78dc61a7875a42b489d2f3168336d360c050e85dee0.jpg", cv2.IMREAD_GRAYSCALE)
imgSize=(128,32)
if img is None:
img = np.zeros([imgSize[1], imgSize[0]])
# dataaugmentation
stretch = (random.random() - 0.5) # -0.5 .. +0.5
wStretched = max(int(img.shape[1] * (1 + stretch)), 1) # random width, but at least 1
img = cv2.resize(img, (wStretched, img.shape[0])) # stretch horizontally by factor 0.5 .. 1.5
# create target image and copy sample image into it
(wt, ht) = imgSize
(h, w) = img.shape
fx = w / wt
fy = h / ht
f = max(fx, fy)
newSize = (max(min(wt, int(w / f)), 1), max(min(ht, int(h / f)), 1)) # scale according to f (result at least 1 and at most wt or ht)
img = cv2.resize(img, newSize)
target = np.ones([ht, wt]) * 255
target[0:newSize[1], 0:newSize[0]] = img
cv2.imshow('Greyscale_Stretched', target('float32'))
k= cv2.waitKey(0) & 0xFF
if k == 27: # wait for ESC key to exit
cv2.destroyAllWindows()
elif k == ord('s'): # wait for 's' key to save and exit
cv2.imwrite('grey.png', target('float32'))
cv2.destroyAllWindows()
main()
Я ожидаю черно-белое изображение на белом фоне.