问题
I've followed this tutorial and managed to make a face detection,age+gender like in this video
Now the problem I'm facing is that the window size of the application is very small and I don't know and can't find a way to resize it (in this image bottom right you can see the window).
The code of the applciation can be found here
回答1:
Solution whatever you set the size,,,opencv resize window for a live cam
import cv2
def main():
windowName = "Main"
cv2.namedWindow(windowName)
cap = cv2.VideoCapture(0)
print('Width :' + str(cap.get(3)))
print('Height :' + str(cap.get(4)))
cap.set(3, 620)
cap.set(4, 720)
if cap.isOpened():
ret, frame = cap.read()
else:
ret = False
while ret:
ret, frame = cap.read()
output = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
cv2.imshow(windowName, frame)
if cv2.waitKey(1) == 27:
break
cv2.destroyAllWindow()
cap.release()
if __name__== "__main__":
main()
回答2:
import cv2
def main():
windowName = "Main"
cv2.namedWindow(windowName)
cap = cv2.VideoCapture(0)
print('Width :' + str(cap.get(3)))
print('Height :' + str(cap.get(4)))
cap.set(3, 620)
cap.set(4, 720)
if cap.isOpened():
ret, frame = cap.read()
else:
ret = False
while ret:
ret, frame = cap.read()
output = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
cv2.imshow(windowName, frame)
if cv2.waitKey(1) == 27:
break
cv2.destroyAllWindow()
cap.release()
if __name__== "__main__":
main()
来源:https://stackoverflow.com/questions/57934288/opencv-resize-window-for-a-live-cam