当前位置: 首页>>代码示例>>Python>>正文


Python cv2.CAP_PROP_FPS属性代码示例

本文整理汇总了Python中cv2.CAP_PROP_FPS属性的典型用法代码示例。如果您正苦于以下问题:Python cv2.CAP_PROP_FPS属性的具体用法?Python cv2.CAP_PROP_FPS怎么用?Python cv2.CAP_PROP_FPS使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在cv2的用法示例。


在下文中一共展示了cv2.CAP_PROP_FPS属性的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: initialize

# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import CAP_PROP_FPS [as 别名]
def initialize(self):
        self.capture = cv2.VideoCapture(self.camera)
        if not self.capture.isOpened():
            print("Error opening video camera")
            return

        # cap.set(cv2.CAP_PROP_FPS, 5)
        self.capture.set(cv2.CAP_PROP_FRAME_WIDTH, self.width)
        self.capture.set(cv2.CAP_PROP_FRAME_HEIGHT, self.height)

        if self.record:
            self.videowriter = cv2.VideoWriter(self.filename,
                                                cv2.VideoWriter_fourcc('m', 'p', '4', 'v'),
                                                10,
                                                (self.width, self.height), 
                                                isColor=True) 
开发者ID:PacktPublishing,项目名称:Advanced-Deep-Learning-with-Keras,代码行数:18,代码来源:video.py

示例2: extract_allframescommand

# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import CAP_PROP_FPS [as 别名]
def extract_allframescommand(filename):
    if filename:

        pathDir = str(filename[:-4])
        if not os.path.exists(pathDir):
            os.makedirs(pathDir)

        picFname = '%d.png'

        saveDirFilenames = os.path.join(pathDir, picFname)
        print(saveDirFilenames)

        fname = str(filename)
        cap = cv2.VideoCapture(fname)
        fps = cap.get(cv2.CAP_PROP_FPS)
        amount_of_frames = cap.get(7)
        print('The number of frames in this video = ',amount_of_frames)
        print('Extracting frames... (Might take awhile)')
        command = str('ffmpeg -i ' +'"'+ str(fname)+'"' + ' ' + '-q:v 1' + ' ' + '-start_number 0' + ' '+'"'+ str(saveDirFilenames)+'"')
        print(command)
        subprocess.call(command, shell=True)
        print('All frames are extracted!')
    else:
        print('Please select a video to convert') 
开发者ID:sgoldenlab,项目名称:simba,代码行数:26,代码来源:tkinter_functions.py

示例3: test_input_framerate

# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import CAP_PROP_FPS [as 别名]
def test_input_framerate(c_ffmpeg):
    """
    Testing "-input_framerate" parameter provided by WriteGear(in Compression Mode) 
    """
    stream = cv2.VideoCapture(return_testvideo_path())  # Open stream
    test_video_framerate = stream.get(cv2.CAP_PROP_FPS)
    output_params = {"-input_framerate": test_video_framerate}
    writer = WriteGear(
        output_filename="Output_tif.mp4",
        custom_ffmpeg=c_ffmpeg,
        logging=True,
        **output_params
    )  # Define writer
    while True:
        (grabbed, frame) = stream.read()
        if not grabbed:
            break
        writer.write(frame)
    stream.release()
    writer.close()
    output_video_framerate = getFrameRate(os.path.abspath("Output_tif.mp4"))
    assert test_video_framerate == output_video_framerate
    os.remove(os.path.abspath("Output_tif.mp4")) 
开发者ID:abhiTronix,项目名称:vidgear,代码行数:25,代码来源:test_compression_mode.py

示例4: __init__

# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import CAP_PROP_FPS [as 别名]
def __init__(self, device=None, size=None, fps=None, sync=False):
        self.device = device or 0
        self.size = size or (480, 640)
        fps = fps or 30

        self.cap = cv2.VideoCapture(self.device)
        cap_height, cap_width = self.cap.get(cv2.CAP_PROP_FRAME_HEIGHT), self.cap.get(cv2.CAP_PROP_FRAME_WIDTH)
        if cap_height != self.size[0]:
            self.cap.set(cv2.CAP_PROP_FRAME_HEIGHT, self.size[0])
        if cap_width != self.size[1]:
            self.cap.set(cv2.CAP_PROP_FRAME_WIDTH, self.size[1])
        cap_fps = self.cap.get(cv2.CAP_PROP_FPS)
        if cap_fps != fps:
            self.cap.set(cv2.CAP_PROP_FPS, fps)
        if sync:
            raise ValueError("sync not supported") 
开发者ID:alexlee-gk,项目名称:visual_dynamics,代码行数:18,代码来源:video.py

示例5: main

# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import CAP_PROP_FPS [as 别名]
def main():
    args = set_args()

    dest = args.destination_path + '.json'

    if os.path.isfile(dest) and not args.force:
        if input("'%s' already exists. Do you want to override it? [y/n]: " % args.destination_path) != 'y':
            print('exiting')
            exit(4)

    file = open(dest, 'w')
    cap = extract_video.get_capture(args.capture_path)

    if cap is None or cap.get(cv2.CAP_PROP_FPS) == 0:
        if extract_video.youtube_url_validation(args.capture_path):
            print("Cannot access video in URL. Please check the URL is a valid YouTube video")
            exit(2)

        print("Cannot access video in file. Please make sure the path to the file is valid")
        exit(3)

    get_data(cap, file, to_float(args.launch_time), args.out, args.destination_path, args.live, args.from_launch) 
开发者ID:shahar603,项目名称:SpaceXtract,代码行数:24,代码来源:get_telemetry_rocketlab.py

示例6: main

# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import CAP_PROP_FPS [as 别名]
def main():
    args = set_args()

    dest = args.destination_path + '.json'

    if os.path.isfile(dest) and not args.force:
        if input("'%s' already exists. Do you want to override it? [y/n]: " % args.destination_path) != 'y':
            print('exiting')
            exit(4)

    file = open(dest, 'w')
    cap = extract_video.get_capture(args.capture_path)

    if cap is None or cap.get(cv2.CAP_PROP_FPS) == 0:
        if extract_video.youtube_url_validation(args.capture_path):
            print("Cannot access video in URL. Please check the URL is a valid YouTube video")
            exit(2)

        print("Cannot access video in file. Please make sure the path to the file is valid")
        exit(3)

    get_data(cap, file, to_float(args.launch_time), args.out, args.destination_path, args.live) 
开发者ID:shahar603,项目名称:SpaceXtract,代码行数:24,代码来源:get_telemetry_spacex.py

示例7: skip_from_launch

# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import CAP_PROP_FPS [as 别名]
def skip_from_launch(self, cap, key, time, thresh=None):
        """
        Move the capture to T+time (time can be negative) and returns the frame index.
        :param cap: OpenCV capture
        :param time: delta time from launch to skip to
        :return: index of requested frame
        """        
        if thresh is None:
            thresh = self.extractor.image_dict[key][2]

        number_of_frames = int(cap.get(cv2.CAP_PROP_FPS) * time) + self.search_switch(cap, key, thresh)

        number_of_frames = max(number_of_frames, 0)
        number_of_frames = min(number_of_frames, cap.get(cv2.CAP_PROP_FRAME_COUNT))

        cap.set(cv2.CAP_PROP_POS_FRAMES, number_of_frames)

        return number_of_frames 
开发者ID:shahar603,项目名称:SpaceXtract,代码行数:20,代码来源:util.py

示例8: __init__

# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import CAP_PROP_FPS [as 别名]
def __init__(self, video_source, video_width, video_height, video_fps, queue_size=1):
        self.video_fps = video_fps

        vc = cv2.VideoCapture(video_source)

        if hasattr(cv2, 'cv'):
            vc.set(cv2.cv.CV_CAP_PROP_FRAME_WIDTH, video_width)
            vc.set(cv2.cv.CV_CAP_PROP_FRAME_HEIGHT, video_height)
            vc.set(cv2.cv.CV_CAP_PROP_FPS, video_fps)
        else:
            vc.set(cv2.CAP_PROP_FRAME_WIDTH, video_width)
            vc.set(cv2.CAP_PROP_FRAME_HEIGHT, video_height)
            vc.set(cv2.CAP_PROP_FPS, video_fps)

        self.stream = vc
        self.stopped = False
        self.queue = Queue(maxsize=queue_size)
        self.thread = Thread(target=self.update, args=())
        self.thread.daemon = True
        self.thread.start() 
开发者ID:blue-oil,项目名称:blueoil,代码行数:22,代码来源:demo.py

示例9: getInfo

# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import CAP_PROP_FPS [as 别名]
def getInfo(sourcePath):
    cap = cv2.VideoCapture(sourcePath)
    info = {
        "framecount": cap.get(cv2.CAP_PROP_FRAME_COUNT),
        "fps": cap.get(cv2.CAP_PROP_FPS),
        "width": int(cap.get(cv2.CAP_PROP_FRAME_WIDTH)),
        "height": int(cap.get(cv2.CAP_PROP_FRAME_HEIGHT)),
        "codec": int(cap.get(cv2.CAP_PROP_FOURCC))
    }
    cap.release()
    return info

#
# Extracts one frame for every second second of video.
# Effectively compresses a video down into much less data.
# 
开发者ID:tafsiri,项目名称:filmstrip,代码行数:18,代码来源:preprocess.py

示例10: VideoToSequence

# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import CAP_PROP_FPS [as 别名]
def VideoToSequence(path, time):
    video = cv2.VideoCapture(path)
    dir_path = 'frames_tmp'
    os.system("rm -rf %s" % dir_path)
    os.mkdir(dir_path)
    fps = int(video.get(cv2.CAP_PROP_FPS))
    length = int(video.get(cv2.CAP_PROP_FRAME_COUNT))
    print('making ' + str(length) + ' frame sequence in ' + dir_path)
    i = -1
    while (True):
        (grabbed, frame) = video.read()
        if not grabbed:
            break
        i = i + 1
        index = IndexHelper(i*time, len(str(time*length)))
        cv2.imwrite(dir_path + '/' + index + '.png', frame)
        # print(index)
    return [dir_path, length, fps] 
开发者ID:CM-BF,项目名称:FeatureFlow,代码行数:20,代码来源:sequence_run.py

示例11: load_video

# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import CAP_PROP_FPS [as 别名]
def load_video(video, all_frames=False):
    cap = cv2.VideoCapture(video)
    fps = cap.get(cv2.CAP_PROP_FPS)
    if fps > 144 or fps is None:
        fps = 25
    frames = []
    count = 0
    while cap.isOpened():
        ret, frame = cap.read()
        if isinstance(frame, np.ndarray):
            if int(count % round(fps)) == 0 or all_frames:
                frame = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
                frames.append(center_crop(resize_frame(frame, 256), 256))
        else:
            break
        count += 1
    cap.release()
    return np.array(frames) 
开发者ID:MKLab-ITI,项目名称:visil,代码行数:20,代码来源:__init__.py

示例12: __init__

# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import CAP_PROP_FPS [as 别名]
def __init__(self, sources='streams.txt', img_size=416, half=False):
        self.mode = 'images'
        self.img_size = img_size
        self.half = half  # half precision fp16 images

        if os.path.isfile(sources):
            with open(sources, 'r') as f:
                sources = [x.strip() for x in f.read().splitlines() if len(x.strip())]
        else:
            sources = [sources]

        n = len(sources)
        self.imgs = [None] * n
        self.sources = sources
        for i, s in enumerate(sources):
            # Start the thread to read frames from the video stream
            print('%g/%g: %s... ' % (i + 1, n, s), end='')
            cap = cv2.VideoCapture(0 if s == '0' else s)
            assert cap.isOpened(), 'Failed to open %s' % s
            w = int(cap.get(cv2.CAP_PROP_FRAME_WIDTH))
            h = int(cap.get(cv2.CAP_PROP_FRAME_HEIGHT))
            fps = cap.get(cv2.CAP_PROP_FPS) % 100
            _, self.imgs[i] = cap.read()  # guarantee first frame
            thread = Thread(target=self.update, args=([i, cap]), daemon=True)
            print(' success (%gx%g at %.2f FPS).' % (w, h, fps))
            thread.start()
        print('')  # newline 
开发者ID:zbyuan,项目名称:pruning_yolov3,代码行数:29,代码来源:datasets.py

示例13: compound_bgm

# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import CAP_PROP_FPS [as 别名]
def compound_bgm(video_path, bgm_path):
    """
    通过视频、BGM 合成一段视频
    :param video_path: 视频路径
    :param bgm_path: BGM路径
    :return:
    """
    # $ ffmpeg -i 2_003_014.mp4 -vn -y -acodec copy 3.aac
    # 1.提前temp.mp4这个视频的BGM,文件结果为:temp.aac
    # os.system('ffmpeg -i temp.mp4 -vn -y -acodec copy temp.aac')

    # 2.获取视频的长度
    cap = cv2.VideoCapture(video_path)
    # 帧率
    fps = cap.get(cv2.CAP_PROP_FPS)
    # 总帧数
    frame_count = cap.get(cv2.CAP_PROP_FRAME_COUNT)
    # 总时长-秒,这里做取整操作 【浮点类型】
    time_count = math.floor(frame_count / fps)

    print('帧率:%f,总帧数:%d' % (fps, frame_count))
    print(time_count)

    # 3.截取音频
    # 为了简单,这里一般不会超过一分钟
    bgm_temp_path = get_temp_path(bgm_path, 'temp_new')
    os.system('ffmpeg -i %s -ss 00:00:00 -t 00:00:%d -acodec copy %s' % (bgm_path, time_count, bgm_temp_path))

    # 3.1 删除源音频并重命令当前文件
    os.remove(bgm_path)
    os.rename(bgm_temp_path, bgm_path)

    # 4.视频、音频合二为一
    video_temp_path = get_temp_path(video_path, 'temp')
    os.system('ffmpeg -i %s  -i %s  -vcodec copy -acodec copy %s' % (video_path, bgm_path, video_temp_path))
    os.remove(video_path)
    os.rename(video_temp_path, video_path)

    print('音视频合成完成~') 
开发者ID:xingag,项目名称:tools_python,代码行数:41,代码来源:video_cut_cv2.py

示例14: add_water_mask

# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import CAP_PROP_FPS [as 别名]
def add_water_mask(video_path, mask_word):
    """
    给视频增加水印
    :param video_part3: 视频源
    :param mask_word: 水印文字
    :return:
    """
    cap = cv2.VideoCapture(video_path)
    fps = cap.get(cv2.CAP_PROP_FPS)

    # 保证帧率不变
    fourcc = cv2.VideoWriter_fourcc('m', 'p', '4', 'v')
    video_temp_path = get_temp_path(video_path, 'temp')
    video_writer = cv2.VideoWriter(video_temp_path, fourcc, fps, img_size)

    ret, frame = cap.read()

    while ret:
        # 文字在图中的坐标(注意:这里的坐标原点是图片左上角)
        x, y = img_size[0] - 200, img_size[1] - 50

        cv2.putText(img=frame, text=mask_word,
                    org=(x, y), fontFace=cv2.FONT_HERSHEY_COMPLEX_SMALL,
                    fontScale=1, color=(255, 255, 255))

        video_writer.write(frame)
        ret, frame = cap.read()

    # 删除源文件,并重命名临时文件
    os.remove(video_path)
    os.rename(video_temp_path, video_path)

    print('水印添加完成~')
    video_writer.release()
    cap.release() 
开发者ID:xingag,项目名称:tools_python,代码行数:37,代码来源:video_cut_cv2.py

示例15: generate_dataset

# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import CAP_PROP_FPS [as 别名]
def generate_dataset(videos_path, framerate, width, height):
    """Converts videos from specified path to ndarrays of shape [numberOfVideos, -1, width, height, 1]

    Args:
        videos_path: Inside the 'videos/' directory, the name of the subdirectory for videos.
        framerate: The desired framerate of the dataset.
        width: The width we will resize the videos to.
        height: The height we will resize the videos to.

    Returns:
        The dataset with the new size and framerate, and converted to monochromatic.

    """
    dataset = []
    video_index = 0
    for playlist in os.listdir('videos/' + videos_path):
        for video_name in os.listdir('videos/{}/{}'.format(videos_path, playlist)):
            dataset.append([])
            print('Video: {}'.format(video_name))
            video = cv2.VideoCapture('videos/{}/{}/{}'.format(videos_path, playlist, video_name))
            while video.isOpened():
                success, frame = video.read()
                if success:
                    frame = preprocess_image(frame, width, height)
                    dataset[video_index].append(frame)

                    frame_index = video.get(cv2.CAP_PROP_POS_FRAMES)
                    video_framerate = video.get(cv2.CAP_PROP_FPS)
                    video.set(cv2.CAP_PROP_POS_FRAMES, frame_index + video_framerate // framerate)
                    last_frame_index = video.get(cv2.CAP_PROP_FRAME_COUNT)
                    if frame_index >= last_frame_index:
                        # Video is over
                        break

                    
                else:
                    break
            dataset[video_index] = np.reshape(dataset[video_index], (-1, width, height, 1))
            video_index += 1
    return dataset 
开发者ID:MaxSobolMark,项目名称:HardRLWithYoutube,代码行数:42,代码来源:train_featurizer.py


注:本文中的cv2.CAP_PROP_FPS属性示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。