Opencv+Python cv2.imshow闪退

Opencv+Python cv2.imshow闪退

  • Opencv+Python cv2.imshow闪退
  • waitKey()的作用

Opencv+Python cv2.imshow闪退


 # 读入原始图像
    origineImage = cv2.imread('./pic/6.jpeg')
    # 图像灰度化
    # image = cv2.imread('test.jpg',0)
    image = cv2.cvtColor(origineImage, cv2.COLOR_BGR2GRAY)
    #image.save('./pic/gray.jpg')
    cv2.imshow('gray', image)
    # 将图片二值化
    retval, img = cv2.threshold(image, 127, 255, cv2.THRESH_BINARY_INV)
    cv2.imshow('binary', img)
   

程序运行到这,图片闪退,在cv.imshow()后加入cv2.waitKey()即可

 origineImage = cv2.imread('./pic/6.jpeg')
    # 图像灰度化
    # image = cv2.imread('test.jpg',0)
    image = cv2.cvtColor(origineImage, cv2.COLOR_BGR2GRAY)
    #image.save('./pic/gray.jpg')

    cv2.imshow('gray', image)
    cv2.waitKey()
    # 将图片二值化
    retval, img = cv2.threshold(image, 127, 255, cv2.THRESH_BINARY_INV)
    cv2.imshow('binary', img)
    cv2.waitKey()

waitKey()的作用

1、waitKey()–这个函数是在一个给定的时间内(单位ms)等待用户按键触发;如果用户没有按下 键,则接续等待(循环)
2、如果设置waitKey(0),则表示程序会无限制的等待用户的按键事件

你可能感兴趣的:(tensorflow)