Opencv imshow() freezes when updating

后端 未结 9 2350
Happy的楠姐
Happy的楠姐 2020-12-09 05:18

For my image processing algorithm I\'m using python / OpenCV. The output of my algorithm shall be updated im the same window over and over again.

However sometimes

9条回答
  •  一个人的身影
    2020-12-09 06:00

    If your window is going grey then it might be take more processing power. So try to resize image into smaller size image and execute. Sometimes times it freezes while running in ipython notebooks due to pressing any key while performing operation. I had personally executed your problem but I didn't get grey screen while doing it. I did executing directly using terminal. Code and steps are shown below.

    import argparse
    import cv2
    import numpy as np 
    
    # construct the argument parser and parse the arguments
    ap = argparse.ArgumentParser()
    ap.add_argument("-i", "--image", required=True, help="Path to the image")
    args = vars(ap.parse_args())
    
    # load the image, grab its dimensions, and show it
    image = cv2.imread(args["image"])
    (h, w) = image.shape[:2]
    cv2.imshow("Original", image)
    cv2.waitKey(0)
    
    for i in range(0,1000):
        image = cv2.imread(args["image"])
        cv2.imshow("The result",image);
        cv2.waitKey(0)
    

    Run it in terminal:

    1. source activate env_name
    2. python Filename.py --image Imagename.png

    This will get to your result in one window only(updating each time) without freezing and if you want seperate image in every new window then add .format(i) as given below. But Remember to run in terminal only not in jupyter notebooks.

    You can check using terminal commands in this video link https://www.youtube.com/watch?v=8O-FW4Wm10s

    for i in range(0,1000):
        image = cv2.imread(args["image"])
        cv2.imshow("The result{}".format(i),image);
        cv2.waitKey(0)
    

    This may help to get you 1000 images separately.

提交回复
热议问题