cant play video file [closed]
I can display an image file fine after setting the DISPLAY variable but when I try to run the following video code from the opencv site , I get nothing , no video window is opened ? the demo I am following is :
http://opencv-python-tutroals.readthe...
please see the code and the output below :
[root@hadoop1 basic-motion-detection]# more demo1.py
import numpy as np
import cv2
cap = cv2.VideoCapture('/home/admin/example_02.mp4')
print cap.get(5) #to display frame rate of video
#print cap.get(cv2.cv.CV_CAP_PROP_FPS)
while(cap.isOpened()):
ret, frame = cap.read()
gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY) #convert to grayscale
cv2.imshow('frame',gray)
waitKey(50)
if cv2.waitKey(25) & 0xFF == ord('q'):
break
cap.release()
cv2.destroyAllWindows()
[root@hadoop1 basic-motion-detection]# python demo1.py
0.0
[root@hadoop1 basic-motion-detection]#
I modified the above code and added the creation of window (as its used in the display image example) , but to no use.
[root@hadoop1 basic-motion-detection]# more demo1.py
import numpy as np
import cv2
cap = cv2.VideoCapture('/home/admin/example_02.mp4')
while(cap.isOpened()):
ret, frame = cap.read()
gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
cv2.startWindowThread()
cv2.namedWindow("preview")
cv2.imshow('preview',gray)
if cv2.waitKey(1) & 0xFF == ord('q'):
break
cap.release()
cv2.destroyAllWindows()
make sure to have opencv_ffmpeg310.so on the path