Esempio n. 1
0
    def process(self, videofile, progress):
        progress(0, _("Extracting histogram"))
        video = hg.cvCreateFileCapture(str(videofile).encode(sys.getfilesystemencoding()))
        if not video:
            raise Exception("Could not open video file")
        histo = cv.cvCreateHist([256],cv.CV_HIST_ARRAY,[[0,256]], 1)
        frame = hg.cvQueryFrame(video)
        frame_gray  = cv.cvCreateImage(cv.cvGetSize(frame), frame.depth, 1);
        hists    = []
        nbframes = 0

        fps = hg.cvGetCaptureProperty(video, hg.CV_CAP_PROP_FPS)
        while frame :
            if not progress(hg.cvGetCaptureProperty(video, hg.CV_CAP_PROP_POS_AVI_RATIO)):
                break
            hg.cvConvertImage(frame,frame_gray)
            cv.cvCalcHist(frame_gray,histo,0,None)
            h = [cv.cvGetReal1D(histo.bins,i) for i in range(255) ]
            h = numpy.array(h,dtype='int32')
            hists.append(h)
            frame = hg.cvQueryFrame(video)
            nbframes += 1

        hists = numpy.array(hists)
        return hists.reshape(nbframes, -1), fps
Esempio n. 2
0
 def __init__(self, fname, format=FORMAT_RGB):
     self.create_capture = hg.cvCreateFileCapture
     super(video_file, self).__init__(format, fname)
     
     self.fps    =     hg.cvGetCaptureProperty(self.cap,
                                               hg.CV_CAP_PROP_FPS)
     self.nframes= int(hg.cvGetCaptureProperty(self.cap,
                                               hg.CV_CAP_PROP_FRAME_COUNT))
Esempio n. 3
0
    def __init__(self, format, *args):
        self._init_cap(args)
        self.set_format(format)

        self.own_data = True # set to false if you want to do less copying
        
        self.width   = int(hg.cvGetCaptureProperty(self.cap,
                                                   hg.CV_CAP_PROP_FRAME_WIDTH))
        self.height  = int(hg.cvGetCaptureProperty(self.cap,
                                                   hg.CV_CAP_PROP_FRAME_HEIGHT))
        self.fps     = -1.0
        self.nframes = -1
Esempio n. 4
0
 def shotDetect(self, queue, capture, sensitivity, number_frame,
                frames_bloc, file_name, file_name_save, file_video_save,
                file_atual, ncpu, ncpus):
     self.number_frame = number_frame
     self.fps = cvGetCaptureProperty(capture, CV_CAP_PROP_FPS)
     histogramPolitic = HistogramPolitic()
     imageManipulation = ImageManipulation()
     frameA, frameB, frameC = self.passFrame(capture)
     vetImg = self.initLoadFrames(frameA, frameB)
     frameAHistogram = imageManipulation.createHistogramBoxes(vetImg, 0)
     frameBHistogram = imageManipulation.createHistogramBoxes(vetImg, 1)
     limiar = histogramPolitic.calculateSensitivity(sensitivity, vetImg[0])
     while not (frameC is None) and (self.number_frame <= frames_bloc):
         vetImg = self.atualizeVetImg(vetImg, Ipl2PIL(frameC))
         frameCHistogram = imageManipulation.createHistogramBoxes(vetImg, 2)
         if histogramPolitic.verifyTransition(
                 frameAHistogram, frameBHistogram, frameCHistogram,
                 limiar) and (self.number_frame - self.lastSaved) > 20:
             self.saveTransition(file_name_save, frames_bloc, vetImg)
         frameA, frameB, frameC = self.atualizeVar(frameA, frameB, frameC,
                                                   capture)
         frameAHistogram = frameBHistogram
         frameBHistogram = frameCHistogram
         self.number_frame += 1
     if (ncpu == ncpus):
         self._list.append(frames_bloc / self.fps)
     elif (ncpu == 1):
         self._list.insert(0, 0)
     queue.put(self._list)
Esempio n. 5
0
def video_shot(args):
    start_time = time.time()
    captures = {}
    cut_list = []
    cut_video = CutVideo()
    init_extract = InitExtract()
    ncpus = cpu_count()
    queue_list = []
    sensitivity = 0.35
    temporary = Temporary()
    video_process = VideoProcess()
    try:
        file_input_name = args[args.index("-i") + 1]
        output_directory = args[args.index("-o") + 1]
    except ValueError:
        sys.exit("Usage: videoShot -i <inputFile> -o <outputDirectory>")
    temporary_directory = temporary.createDirectory()
    print "Converting video to ogg..."
    start_time2 = time.time()
    convert_video_to_ogg(file_input_name, temporary_directory)
    start_time3 = time.time()
    ogg_video_path = os.path.join(temporary_directory, "video_converted.ogg")
    output_segmentation_directory = output_directory + "/segmentation_video/"
    file_name_save = output_segmentation_directory + "/transitions_video/"
    file_video_save = output_segmentation_directory + "/parts_videos/"
    file_audio_save = output_segmentation_directory + "/video_audio/"
    thumbnails_save_path = output_segmentation_directory + "/thumbnails/"
    create_directory(
        [output_segmentation_directory, file_name_save, file_video_save, file_audio_save, thumbnails_save_path]
    )
    file_input_name = ogg_video_path
    capture = init_extract.createCapture(file_input_name)
    video_duration = get_video_duration(ogg_video_path)
    fps = cvGetCaptureProperty(capture, CV_CAP_PROP_FPS)
    total_frames = round(video_duration * fps, 0)
    frames_bloc = int(total_frames / ncpus)
    split_video(temporary_directory, ncpus, video_duration, ogg_video_path)
    list_videos_path = get_videos_path(temporary_directory)
    captures[1] = init_extract.createCapture(list_videos_path[0])
    cvSaveImage(file_name_save + "trans_time_1.jpg", init_extract.initFrameCapture(captures[1]))
    for i in range(2, ncpus + 1):
        captures[i] = init_extract.createCapture(list_videos_path[i - 1])
    print "Finding transitions..."
    video_process.create_video_process(
        captures, sensitivity, frames_bloc, file_input_name, file_name_save, file_video_save, ncpus, queue_list
    )
    for i in range(ncpus):
        cut_list.extend(queue_list[i].get())
    cut_list = [round(x, 6) for x in cut_list]
    time_cut_list = cut_video.position_cut_list(cut_list, ncpus)
    print "Generating Segments..."
    video_process.create_cut_process(file_input_name, file_video_save, time_cut_list, ncpus)
    get_output_audio(file_audio_save, ogg_video_path)
    get_video_thumbnails(file_video_save, thumbnails_save_path)
    temporary.removeDirectory(temporary_directory)
    print
    print "Conversion Time: %.2f s" % (start_time3 - start_time2)
    print "Segmentation Time: %.2f s" % ((time.time() - start_time) - (start_time3 - start_time2))
    print "Segmentation completed in : %.2f s" % (time.time() - start_time)
Esempio n. 6
0
def video_shot(args):
    start_time = time.time()
    captures = {}
    cut_list = []
    cut_video = CutVideo()
    init_extract = InitExtract()
    ncpus = cpu_count()
    queue_list = []
    sensitivity = 0.35
    temporary = Temporary()
    video_process = VideoProcess()
    try:
        file_input_name = args[args.index('-i') + 1]
        output_directory = args[args.index('-o') + 1]
    except ValueError:
        sys.exit('Usage: videoShot -i <inputFile> -o <outputDirectory>')
    temporary_directory = temporary.createDirectory()
    print "Converting video to ogg..."
    start_time2 = time.time()
    convert_video_to_ogg(file_input_name, temporary_directory)
    start_time3 = time.time()
    ogg_video_path = os.path.join(temporary_directory, "video_converted.ogg")
    output_segmentation_directory = output_directory + '/segmentation_video/'
    file_name_save = (output_segmentation_directory + '/transitions_video/')
    file_video_save = (output_segmentation_directory + '/parts_videos/')
    file_audio_save = (output_segmentation_directory + '/video_audio/')
    thumbnails_save_path = (output_segmentation_directory + '/thumbnails/')
    create_directory([output_segmentation_directory, file_name_save, file_video_save, file_audio_save, thumbnails_save_path])
    file_input_name = ogg_video_path
    capture = init_extract.createCapture(file_input_name)
    video_duration = get_video_duration(ogg_video_path)
    fps = cvGetCaptureProperty(capture, CV_CAP_PROP_FPS)
    total_frames = round(video_duration * fps, 0)
    frames_bloc = int(total_frames / ncpus)
    split_video(temporary_directory, ncpus, video_duration, ogg_video_path)
    list_videos_path = get_videos_path(temporary_directory)
    captures[1] = init_extract.createCapture(list_videos_path[0])
    cvSaveImage(file_name_save + 'trans_time_1.jpg', init_extract.initFrameCapture(captures[1]))
    for i in range(2, ncpus + 1):
        captures[i] = init_extract.createCapture(list_videos_path[i-1])
    print "Finding transitions..."
    video_process.create_video_process(captures, sensitivity, frames_bloc, file_input_name, file_name_save, file_video_save, ncpus, queue_list)   
    for i in range(ncpus):
        cut_list.extend(queue_list[i].get())
    cut_list = [round(x,6) for x in cut_list]        
    time_cut_list = cut_video.position_cut_list(cut_list, ncpus)
    print "Generating Segments..."
    video_process.create_cut_process(file_input_name, file_video_save, time_cut_list, ncpus)
    get_output_audio(file_audio_save, ogg_video_path)
    get_video_thumbnails(file_video_save, thumbnails_save_path)
    temporary.removeDirectory(temporary_directory)
    print 
    print "Conversion Time: %.2f s" % (start_time3 - start_time2)
    print "Segmentation Time: %.2f s" % ((time.time() - start_time) - (start_time3 - start_time2)) 
    print "Segmentation completed in : %.2f s" % (time.time() - start_time) 
           
Esempio n. 7
0
    def init_camera(self):
        # create the device
        self._device = hg.cvCreateCameraCapture(self._index)

        try:
            # try first to set resolution
            cv.hg(self._device, cv.CV_CAP_PROP_FRAME_WIDTH,
                              self.resolution[0])
            cv.hg(self._device, cv.CV_CAP_PROP_FRAME_HEIGHT,
                              self.resolution[1])

            # and get frame to check if it's ok
            frame = hg.cvQueryFrame(self._device)
            if not int(frame.width) == self.resolution[0]:
                raise Exception('OpenCV: Resolution not supported')

        except:
            # error while setting resolution
            # fallback on default one
            w = int(hg.cvGetCaptureProperty(self._device,
                    hg.CV_CAP_PROP_FRAME_WIDTH))
            h = int(hg.cvGetCaptureProperty(self._device,
                    hg.CV_CAP_PROP_FRAME_HEIGHT))
            frame = hg.cvQueryFrame(self._device)
            Logger.warning(
                'OpenCV: Camera resolution %s impossible! Defaulting to %s.' %
                (self.resolution, (w, h)))

            # set resolution to default one
            self._resolution = (w, h)

        # create texture !
        self._texture = Texture.create(*self._resolution)
        self._texture.flip_vertical()
        self.dispatch('on_load')

        if not self.stopped:
            self.start()
Esempio n. 8
0
    def __init__(self, src="", time=None):

        self.src = src
        self.time = time
        if self.time:
            hg.cvSetCaptureProperty(self.src, hg.CV_CAP_PROP_POS_FRAMES, self.time)
        self.iplimage = hg.cvQueryFrame(self.src)
        self.width = self.iplimage.width
        self.height = self.iplimage.height
        self.image = opencv.cvCreateImage(opencv.cvGetSize(self.iplimage), 8, 4)
        opencv.cvCvtColor(self.iplimage, self.image, opencv.CV_BGR2BGRA)
        self.buffer = numpy.fromstring(self.image.imageData, dtype=numpy.uint32).astype(numpy.uint32)
        self.buffer.shape = (self.image.width, self.image.height)
        self.time = hg.cvGetCaptureProperty(self.src, hg.CV_CAP_PROP_POS_MSEC)
Esempio n. 9
0
    def __init__(self, src="", time=None):

        self.src = src
        self.time = time
        if self.time:
            hg.cvSetCaptureProperty(self.src, hg.CV_CAP_PROP_POS_FRAMES, self.time)    
        self.iplimage = hg.cvQueryFrame(self.src)
        self.width = self.iplimage.width
        self.height = self.iplimage.height
        self.image = opencv.cvCreateImage(opencv.cvGetSize(self.iplimage),8, 4)
        opencv.cvCvtColor(self.iplimage,self.image,opencv.CV_BGR2BGRA)
        self.buffer = numpy.fromstring(self.image.imageData, dtype=numpy.uint32).astype(numpy.uint32)
        self.buffer.shape = (self.image.width, self.image.height)
        self.time = hg.cvGetCaptureProperty(self.src, hg.CV_CAP_PROP_POS_MSEC)
Esempio n. 10
0
    def _init_camera(self, cam_num):
        """Initializes the camera associated with the given camera number"""

        # Create the OpenCV camera capture object if one has not been created already
        if cam_num not in self._captures:
            self._captures[cam_num] = highgui.cvCreateCameraCapture(cam_num)
        self._capture = self._captures[cam_num]

        # Make sure the camera object was created
        if not self._capture:
            raise AetherCameraError("Unable to open camera %d" % cam_num)

            # cvCreateCameraCapture(id) takes ownership of the camera pointer
            # cvSetCaptureProperty won't work unless we disown it before setting
        self._capture.disown()

        # Set the capture dimensions
        highgui.cvSetCaptureProperty(self._capture, highgui.CV_CAP_PROP_FRAME_WIDTH, self.capture_dims[0])
        highgui.cvSetCaptureProperty(self._capture, highgui.CV_CAP_PROP_FRAME_HEIGHT, self.capture_dims[1])

        # Take ownership again
        self._capture.acquire()

        # Read the capture dims and see if they were set to what we specified
        read_dims = (
            int(highgui.cvGetCaptureProperty(self._capture, highgui.CV_CAP_PROP_FRAME_WIDTH)),
            int(highgui.cvGetCaptureProperty(self._capture, highgui.CV_CAP_PROP_FRAME_HEIGHT)),
        )

        # Set the scale flag depending on the results of setting the capture dimensions
        # If we are reading frames in the correct dimensions, we don't need to scale
        if self.capture_dims == read_dims:
            self.scale = False
        else:
            print "Tried setting capture resolution:", self.capture_dims, ", got:", read_dims
            self.scale = True
Esempio n. 11
0
def videoShot(args):
	w = time.time()
	file_atual = os.getcwd()
	initExtract = InitExtract()
	videoprocess = VideoProcess()
	shotvideo = ShotVideo()
	cutvideo = CutVideo()
	captures = {}
	cut_list=[]
	sensitivity = 0.35
	ncpus = cpu_count()
	queue_list=[]
	FileName = args[args.index('-i') + 1]
	output = args[args.index('-o') + 1]
	fileNameSave = (output + '/transitions_' + 'video' + '/')
	fileVideoSave = (output + '/parts_' + 'video'+'/')
	for files in (fileNameSave, fileVideoSave):
		try:
			shutil.rmtree(files)
		except:
			pass
		os.mkdir(files)
	capture = initExtract.createCapture(FileName)
	total_frames = cvGetCaptureProperty(capture, CV_CAP_PROP_FRAME_COUNT)
	# if utilizado para quando o video nao possui o metadado de total frame
	if total_frames == 0:
		total_frames = shotvideo.contFrames(capture)
	frames_bloc = int(total_frames / ncpus)
	captures[1] = initExtract.createCapture(FileName)
	cvSaveImage(fileNameSave + 'transition25.jpg', initExtract.initFrameCapture(captures[1]))
	for i in range(2, ncpus + 1):
		captures[i] = initExtract.createCapture(FileName)
		captures[i] = initExtract.pass_frames(captures[i], frames_bloc, i - 1)
	j = time.time()		
	videoprocess.create_video_process(captures,sensitivity,frames_bloc,FileName,fileNameSave,fileVideoSave,file_atual,ncpus,queue_list)   
	for i in range(ncpus):
		cut_list.extend(queue_list[i].get())
	cut_list = [round(x,6) for x in cut_list]        
	corte = cutvideo.position_cut_list(cut_list,ncpus)
	videoprocess.create_cut_process(FileName,fileVideoSave,file_atual,corte,ncpus)
	print "A segmentacao foi concluida em : %.2f segundos " % (time.time() - w) 
Esempio n. 12
0
 def shotDetect(self,queue, capture, sensitivity, number_frame, frames_bloc, file_name, file_name_save, file_video_save, file_atual, ncpu, ncpus): 
     self.number_frame = number_frame
     self.fps = cvGetCaptureProperty(capture, CV_CAP_PROP_FPS)
     histogramPolitic = HistogramPolitic()
     imageManipulation = ImageManipulation()
     frameA, frameB, frameC = self.passFrame(capture) 
     vetImg = self.initLoadFrames(frameA, frameB)
     frameAHistogram = imageManipulation.createHistogramBoxes(vetImg, 0)
     frameBHistogram = imageManipulation.createHistogramBoxes(vetImg, 1)
     limiar = histogramPolitic.calculateSensitivity(sensitivity, vetImg[0])   
     while not(frameC is None) and (self.number_frame<= frames_bloc):
         vetImg = self.atualizeVetImg(vetImg, Ipl2PIL(frameC))
         frameCHistogram = imageManipulation.createHistogramBoxes(vetImg, 2)
         if histogramPolitic.verifyTransition(frameAHistogram, frameBHistogram, frameCHistogram, limiar) and (self.number_frame - self.lastSaved) > 20:         
             self.saveTransition(file_name_save, frames_bloc, vetImg) 
         frameA, frameB, frameC = self.atualizeVar(frameA, frameB, frameC, capture) 	
         frameAHistogram = frameBHistogram
         frameBHistogram = frameCHistogram
         self.number_frame += 1
     if (ncpu == ncpus):
         self._list.append(frames_bloc / self.fps)
     elif (ncpu == 1):
         self._list.insert(0, 0)
     queue.put(self._list)
Esempio n. 13
0
        # we can assume this is a file name, so open it
        capture = highgui.cvCreateFileCapture (sys.argv [1])            

    # check that capture device is OK
    if not capture:
        print "Error opening capture device"
        sys.exit (1)

    # capture the 1st frame to get some propertie on it
    frame = highgui.cvQueryFrame (capture)

    # get size of the frame
    frame_size = cv.cvGetSize (frame)

    # get the frame rate of the capture device
    fps = highgui.cvGetCaptureProperty (capture, highgui.CV_CAP_PROP_FPS)
    if fps == 0:
        # no fps getted, so set it to 30 by default
        fps = 25

    frame_count = highgui.cvGetCaptureProperty(capture, 
                                               highgui.CV_CAP_PROP_FRAME_COUNT)
    frame_count = int(frame_count / 3600)
    highgui.cvCreateTrackbar('Seek', 'Camera', 0, int(frame_count),
                             lambda pos: seek_onChange(pos, capture, 'Camera'))

    # display the frames to have a visual output
    highgui.cvShowImage ('Camera', frame)

    i = 0
    start = 0
Esempio n. 14
0
        device = int(sys.argv[1])

        # got it ! so remove it from the arguments
        del sys.argv[1]
    except (IndexError, ValueError):
        # no device number on the command line, assume we want the 1st device
        device = 0

    if len(sys.argv) == 1:
        # no argument on the command line, try to use the camera
        capture = highgui.cvCreateCameraCapture(device)
        highgui.cvSetCaptureProperty(capture, highgui.CV_CAP_PROP_FRAME_WIDTH,
                                     320)
        highgui.cvSetCaptureProperty(capture, highgui.CV_CAP_PROP_FRAME_HEIGHT,
                                     240)
        contrast = highgui.cvGetCaptureProperty(capture,
                                                highgui.CV_CAP_PROP_CONTRAST)
        print contrast
    else:
        # we have an argument on the command line,
        # we can assume this is a file name, so open it
        capture = highgui.cvCreateFileCapture(sys.argv[1])

    # check that capture device is OK
    print "opening camera"
    if not capture:
        print "Error opening capture device"
        sys.exit(1)

    # capture the 1st frame to get some propertie on it
    frame = highgui.cvQueryFrame(capture)
Esempio n. 15
0
hmax = 18

highgui.cvNamedWindow('Camera', highgui.CV_WINDOW_AUTOSIZE)
#highgui.cvNamedWindow('Hue', highgui.CV_WINDOW_AUTOSIZE)
#highgui.cvCreateTrackbar("hmin Trackbar","Hue",hmin,180, change_hmin);
#highgui.cvCreateTrackbar("hmax Trackbar","Hue",hmax,180, change_hmax);

print "grabbing camera"
capture = highgui.cvCreateCameraCapture(0)
print "found camera"
time.sleep(1)
frame = highgui.cvQueryFrame(capture)
frameSize = cv.cvGetSize(frame)
print "frameSize =", frameSize
time.sleep(1)
cam_width = highgui.cvGetCaptureProperty(capture,
                                         highgui.CV_CAP_PROP_FRAME_WIDTH)
cam_height = highgui.cvGetCaptureProperty(capture,
                                          highgui.CV_CAP_PROP_FRAME_HEIGHT)
print "camers cam_height =", cam_height
print "camers cam_width =", cam_width

highgui.cvSetCaptureProperty(capture, highgui.CV_CAP_PROP_FRAME_WIDTH, 320)
highgui.cvSetCaptureProperty(capture, highgui.CV_CAP_PROP_FRAME_HEIGHT, 240)
time.sleep(1)
cam_width = highgui.cvGetCaptureProperty(capture,
                                         highgui.CV_CAP_PROP_FRAME_WIDTH)
cam_height = highgui.cvGetCaptureProperty(capture,
                                          highgui.CV_CAP_PROP_FRAME_HEIGHT)
print "camers cam_height =", cam_height
print "camers cam_width =", cam_width
print highgui.cvGetCaptureProperty(capture, highgui.CV_CAP_PROP_FPS)
Esempio n. 16
0
hmax = 18

highgui.cvNamedWindow('Camera', highgui.CV_WINDOW_AUTOSIZE)
#highgui.cvNamedWindow('Hue', highgui.CV_WINDOW_AUTOSIZE)
#highgui.cvCreateTrackbar("hmin Trackbar","Hue",hmin,180, change_hmin);
#highgui.cvCreateTrackbar("hmax Trackbar","Hue",hmax,180, change_hmax);

print "grabbing camera"
capture = highgui.cvCreateCameraCapture(0)
print "found camera"
time.sleep(1)
frame = highgui.cvQueryFrame(capture)
frameSize = cv.cvGetSize(frame)
print "frameSize =", frameSize
time.sleep(1)
cam_width = highgui.cvGetCaptureProperty(capture,highgui.CV_CAP_PROP_FRAME_WIDTH)
cam_height = highgui.cvGetCaptureProperty(capture,highgui.CV_CAP_PROP_FRAME_HEIGHT)
print "camers cam_height =", cam_height
print "camers cam_width =", cam_width

highgui.cvSetCaptureProperty(capture,highgui.CV_CAP_PROP_FRAME_WIDTH, 320)
highgui.cvSetCaptureProperty(capture,highgui.CV_CAP_PROP_FRAME_HEIGHT, 240)
time.sleep(1)
cam_width = highgui.cvGetCaptureProperty(capture,highgui.CV_CAP_PROP_FRAME_WIDTH)
cam_height = highgui.cvGetCaptureProperty(capture,highgui.CV_CAP_PROP_FRAME_HEIGHT)
print "camers cam_height =", cam_height
print "camers cam_width =", cam_width
print highgui.cvGetCaptureProperty(capture,highgui.CV_CAP_PROP_FPS)
print highgui.cvGetCaptureProperty(capture,highgui.CV_CAP_PROP_BRIGHTNESS)
#print highgui.cvGetCaptureProperty(capture,highgui.CV_CAP_CONTRAST )
print highgui.cvGetCaptureProperty(capture,highgui.CV_CAP_PROP_SATURATION )
Esempio n. 17
0
        # we can assume this is a file name, so open it
        capture = highgui.cvCreateFileCapture(sys.argv[1])

    # check that capture device is OK
    if not capture:
        print "Error opening capture device"
        sys.exit(1)

    # capture the 1st frame to get some propertie on it
    frame = highgui.cvQueryFrame(capture)

    # get size of the frame
    frame_size = cv.cvGetSize(frame)

    # get the frame rate of the capture device
    fps = highgui.cvGetCaptureProperty(capture, highgui.CV_CAP_PROP_FPS)
    if fps == 0:
        # no fps getted, so set it to 30 by default
        fps = 25

    frame_count = highgui.cvGetCaptureProperty(capture,
                                               highgui.CV_CAP_PROP_FRAME_COUNT)
    frame_count = int(frame_count / 3600)
    highgui.cvCreateTrackbar('Seek', 'Camera', 0, int(frame_count),
                             lambda pos: seek_onChange(pos, capture, 'Camera'))

    # display the frames to have a visual output
    highgui.cvShowImage('Camera', frame)

    i = 0
    start = 0
Esempio n. 18
0
        # we can assume this is a file name, so open it
        capture = highgui.cvCreateFileCapture (sys.argv [1])            

    # check that capture device is OK
    if not capture:
        print "Error opening capture device"
        sys.exit (1)

    # capture the 1st frame to get some propertie on it
    frame = highgui.cvQueryFrame (capture)

    # get size of the frame
    frame_size = cv.cvGetSize (frame)

    # get the frame rate of the capture device
    fps = highgui.cvGetCaptureProperty (capture, highgui.CV_CAP_PROP_FPS)
    if fps == 0:
        # no fps getted, so set it to 30 by default
        fps = 30

    # create the writer
    writer = highgui.cvCreateVideoWriter ("captured.mpg", MPEG1VIDEO,
                                          fps, frame_size, True)

    # check the writer is OK
    if not writer:
        print "Error opening writer"
        sys.exit (1)
        
    while 1:
        # do forever
Esempio n. 19
0
# Armazenamento temporario
# Temporary storage
storage1 = cv.cvCreateMemStorage()
storage2 = cv.cvCreateMemStorage()

# Carrega, binariza e procura o contorno dos padroes
# Load, binarize and find contours
for i in range(0,len(padroes)):
    target.append(hg.cvLoadImage(padroes[i], hg.CV_LOAD_IMAGE_GRAYSCALE))
    target_mod.append(cv.cvCreateImage((target[i].width,target[i].height), cv.IPL_DEPTH_8U, 1))
    cv.cvThreshold(target[i],target_mod[i],200,254,cv.CV_THRESH_BINARY)
    target_c.append(cv.cvFindContours(target_mod[i], storage1)[1])
    target_c[i] = cv.cvApproxPoly(target_c[i],cv.sizeof_CvContour,storage1,cv.CV_POLY_APPROX_DP,1)

frame_mod = cv.cvCreateImage((hg.cvGetCaptureProperty(capture,hg.CV_CAP_PROP_FRAME_WIDTH), hg.cvGetCaptureProperty(capture,hg.CV_CAP_PROP_FRAME_HEIGHT)), cv.IPL_DEPTH_8U, 1)

hg.cvNamedWindow("Resultado")
hg.cvNamedWindow("Binarizado")
#strut = cv.cvCreateStructuringElementEx(3,3,0,0,cv.CV_SHAPE_CROSS)

while True:
    turn = -1
    # Captura o frame, binariza, procura por contornos e checa com os padroes
    # Capture frame, binarize, find contours and check with known patterns
    frame = hg.cvQueryFrame(capture)
    cv.cvCvtColor(frame, frame_mod,cv.CV_RGB2GRAY)
    cv.cvThreshold(frame_mod,frame_mod,120,254,cv.CV_THRESH_BINARY)
    hg.cvShowImage("Binarizado", frame_mod)
    source_c = cv.cvFindContours(frame_mod, storage2)[1]
    if source_c:
Esempio n. 20
0
    try:
        # try to get the device number from the command line
        device = int (sys.argv [1])

        # got it ! so remove it from the arguments
        del sys.argv [1]
    except (IndexError, ValueError):
        # no device number on the command line, assume we want the 1st device
        device = 0

    if len (sys.argv) == 1:
        # no argument on the command line, try to use the camera
        capture = highgui.cvCreateCameraCapture (device)
        highgui.cvSetCaptureProperty(capture, highgui.CV_CAP_PROP_FRAME_WIDTH, 320)
        highgui.cvSetCaptureProperty(capture, highgui.CV_CAP_PROP_FRAME_HEIGHT, 240)
        contrast = highgui.cvGetCaptureProperty(capture, highgui.CV_CAP_PROP_CONTRAST)
        print contrast
    else:
        # we have an argument on the command line,
        # we can assume this is a file name, so open it
        capture = highgui.cvCreateFileCapture (sys.argv [1])            

    # check that capture device is OK
    print "opening camera"
    if not capture:
        print "Error opening capture device"
        sys.exit (1)

    # capture the 1st frame to get some propertie on it
    frame = highgui.cvQueryFrame (capture)