Skip to content Skip to sidebar Skip to footer

Getting This Black Window Instead Of Picture While Using Cv2.imshow

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 r

Solution 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.

Solution 2:

This will help. You need to resize the image sometime the OpenCV messes with an image format this will work in all OpenCV versions hope this helps

import cv2
import numpy as np
import face_recognition

# cv2.namedWindow('image', cv2.WINDOW_NORMAL)
imgElon = face_recognition.load_image_file("elon.jpg")
print(type(imgElon.shape))
a,b,c=imgElon.shape


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)


imgElon=cv2.resize(imgElon, (a, b))

cv2.imshow('image', imgElon)
cv2.waitKey(0)
cv2.destroyAllWindows()

Solution 3:

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

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

Post a Comment for "Getting This Black Window Instead Of Picture While Using Cv2.imshow"