Go to the documentation of this file.00001
00002
00003 """
00004
00005 Copyright (c) 2015 PAL Robotics SL.
00006 Released under the BSD License.
00007
00008 Created on 7/14/15
00009
00010 @author: Sammy Pfeiffer
00011
00012 test_video_resource.py contains
00013 a testing code to see if opencv can open a video stream
00014 useful to debug if video_stream does not work
00015 """
00016
00017 import cv2
00018 import sys
00019
00020 if __name__ == '__main__':
00021 if len(sys.argv) < 2:
00022 print "You must give an argument to open a video stream."
00023 print " It can be a number as video device, e.g.: 0 would be /dev/video0"
00024 print " It can be a url of a stream, e.g.: rtsp://wowzaec2demo.streamlock.net/vod/mp4:BigBuckBunny_115k.mov"
00025 print " It can be a video file, e.g.: myvideo.mkv"
00026 exit(0)
00027
00028 resource = sys.argv[1]
00029
00030 if len(resource) < 3:
00031 resource_name = "/dev/video" + resource
00032 resource = int(resource)
00033 else:
00034 resource_name = resource
00035 print "Trying to open resource: " + resource_name
00036 cap = cv2.VideoCapture(resource)
00037 if not cap.isOpened():
00038 print "Error opening resource: " + str(resource)
00039 print "Maybe opencv VideoCapture can't open it"
00040 exit(0)
00041
00042 print "Correctly opened resource, starting to show feed."
00043 rval, frame = cap.read()
00044 while rval:
00045 cv2.imshow("Stream: " + resource_name, frame)
00046 rval, frame = cap.read()
00047 key = cv2.waitKey(20)
00048
00049
00050 if key == 27 or key == 1048603:
00051 break
00052 cv2.destroyWindow("preview")
00053