opencv resize window for a live cam

三世轮回 提交于 2020-05-28 04:13:10

问题


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

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