I share my code where I'm trying to use the image 'img' in PIL.ImageTk.PhotoImage(img) but it does not work.
while(True):
imgResp=urllib.request.urlopen(self.ip)
imgNp=np.array(bytearray(imgResp.read()),dtype=np.uint8)
img=cv2.imdecode(imgNp,-1)
img = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
bodies = body_classifier.detectMultiScale(img, 1.04, 3)
for (x,y,w,h) in bodies:
print("X", x)
print("Y", y)
print("W", w)
print("H", h)
cv2.imshow("CAMARA 1",img)
self.canv = Canvas(self.window, bg='white')
self.canv.grid(row=5, column=0)
#self.imgLoad = PIL.ImageTk.PhotoImage(PIL.Image.open ("C:\......jpg")) # works
self.imgLoad = PIL.ImageTk.PhotoImage(img) # does not work
self.canv.create_image(20,20, anchor=NW, image=self.imgLoad)
question from:
https://stackoverflow.com/questions/65602917/how-can-i-use-imagetk-photoimage-to-load-image-from-ip-webcam 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…