Getting this black window instead of picture while using cv2.imshow

不想你离开。 提交于 2020-08-08 13:54:46

问题


I don't know what term I should use for the window I am getting so I am attaching a screenshot of the window for reference.

I am getting this window about 7 of the 10 times I am running this code:

import cv2
import numpy as np
import face_recognition


imgElon = face_recognition.load_image_file("BasicFaceRecImg/ElonMusk2.jpg")
imgElon = cv2.cvtColor(imgElon, cv2.COLOR_BGR2RGB)
imgElon_face_loc = face_recognition.face_locations(imgElon)[0]
print(imgElon_face_loc)

imgElon_encode = face_recognition.face_encodings(imgElon)[0]
cv2.rectangle(imgElon, (imgElon_face_loc[0], imgElon_face_loc[3]), (imgElon_face_loc[1], imgElon_face_loc[2]),(255, 0, 255), 2)
cv2.imshow('Elon Musk', imgElon)
cv2.waitKey(0)

And the funny thing is that I am not getting this problem every time. It runs perfectly sometimes.


回答1:


I installed opencv-python-4.2.0.32 and the problem seems to have went away. I was using version 4.3.0.36 when having the issues.




回答2:


I had the same problem, and was able to solve it using this code:

image = cv2.imread("./faces/test.jpg", cv2.IMREAD_COLOR)


来源:https://stackoverflow.com/questions/62775458/getting-this-black-window-instead-of-picture-while-using-cv2-imshow

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!