如何在python openCV中的窗口上显示图像结果

时间:2016-06-18 12:33:25

标签: python opencv

我打算在每对图像之间显示光流结果和差异图像,但图像窗口始终显示最后一对图像的结果,即使我可以看到图像已正确写入。
    cv2.imshow( '流',BGR)     cv2.imshow( '差异',差异) 有人可以对此有所了解,谢谢!

import numpy as np   
import cv2


dirOC = 'ImgDir_OriC\\'
dirTC = 'ImgDir_TransC\\'
suffix = '.bmp'
fCount = 11
count = 0
MAX = 10
while(count < MAX ):
    fNameO = dirOC + str(fCount) + suffix
    fNameT = dirTC + str(fCount) + suffix
    print fNameO
    print fNameT

    imgO = cv2.imread(fNameO, cv2.IMREAD_COLOR)
    prvs = cv2.cvtColor(imgO,cv2.COLOR_BGR2GRAY)

    imgT = cv2.imread(fNameT, cv2.IMREAD_COLOR)
    next = cv2.cvtColor(imgT,cv2.COLOR_BGR2GRAY)   

    flow = cv2.calcOpticalFlowFarneback(prvs,next, 0.5,3,15,15,3,5,1)
    mag, ang = cv2.cartToPolar(flow[...,0], flow[...,1])    

    hsv = np.zeros_like(imgO)    
    hsv[...,1] = 255
    hsv[...,0] = ang*180/np.pi/2     
    hsv[...,2] = cv2.normalize(mag,None,0,255,cv2.NORM_MINMAX)           
    bgr = cv2.cvtColor(hsv,cv2.COLOR_HSV2BGR)
    cv2.imshow('flow',bgr)

    diff = np.zeros_like(prvs)    
    cv2.subtract(prvs,next,diff)
    cv2.imshow('diff',diff)

    cv2.imwrite('flow'+str(fCount) + '.png',bgr)    
    cv2.imwrite('diff'+str(fCount) + '.png',diff)

    fCount = fCount +1
    count = count +1    


cv2.waitKey(0)
cv2.destroyAllWindows()

1 个答案:

答案 0 :(得分:1)

您需要将i放在waitKey()循环中:

while