gstreamer 问题 - 在 anaconda 3 env 中的 pycharm

问题描述 投票:0回答:0

我在 anaconda 3 环境中运行此代码时遇到问题:

import matplotlib.pyplot as plt
import numpy as np
import cv2


def video_to_frames(vid_path: str, start_second, end_second):
    """
    Load a video and return its frames from the wanted time range.
    :param vid_path: video file path.
    :param start_second: time of first frame to be taken from the
    video in seconds.
    :param end_second: time of last frame to be taken from the
    video in seconds.
    :return:
    frame_set: a 4D uint8 np array of size [num_of_frames x H x W x C]
    containing the wanted video frames in BGR format.
    """
    # importing video to function
    cap = cv2.VideoCapture(vid_path)

    # rate of frames per sec
    frate = int(cap.get(cv2.CAP_PROP_FPS))

    # properties of video
    frameCount = int(cap.get(cv2.CAP_PROP_FRAME_COUNT))
    frameWidth = int(cap.get(cv2.CAP_PROP_FRAME_WIDTH))
    frameHeight = int(cap.get(cv2.CAP_PROP_FRAME_HEIGHT))

    # correction for wanted amount of frames if needed
    if start_second == end_second:
        frameCount = 1
    else:
        frameCount = (end_second - start_second) * frate

    frame_set = np.empty((frameCount, frameHeight, frameWidth, 3), np.dtype('uint8'))
    flag = True
    fc = 0
    start_frame = start_second * frate
    end_frame = end_second * frate
    frame_set_counter = 0

    # occuping frame_set
    while flag and frame_set_counter < frameCount:
        flag, image = cap.read()
        fc += 1
        if fc >= start_frame and fc <= end_frame:
            frame_set[frame_set_counter] = image
            frame_set_counter += 1

    cap.release()
    # ========================
    return frame_set


def question1():
    vid_path = 'given_data/MilkyChance_StolenDance.mp4'
    frame_set = video_to_frames(vid_path, 8, 8)
    out_image = cv2.cvtColor(frame_set[0], cv2.COLOR_BGR2GRAY)
    plt.imshow(out_image, cmap="gray")
    plt.xlabel('Width')
    plt.ylabel('Height')
    plt.title('Gray Image')

question1()

我收到这个错误:

[ WARN:[email protected]] global C:\ci_311_rebuilds\opencv-suite_1679001454889\work\modules\videoio\src\cap_gstreamer.cpp (2386) cv::handleMessage OpenCV | GStreamer warning: your GStreamer installation is missing a required plugin

[ WARN:[email protected]] global C:\ci_311_rebuilds\opencv-suite_1679001454889\work\modules\videoio\src\cap_gstreamer.cpp (2386) cv::handleMessage OpenCV | GStreamer warning: your GStreamer installation is missing a required plugin

[ WARN:[email protected]] global C:\ci_311_rebuilds\opencv-suite_1679001454889\work\modules\videoio\src\cap_gstreamer.cpp (2402) cv::handleMessage OpenCV | GStreamer warning: Embedded video playback halted; module uridecodebin0 reported: Your GStreamer installation is missing a plug-in.

[ WARN:[email protected]] global C:\ci_311_rebuilds\opencv-suite_1679001454889\work\modules\videoio\src\cap_gstreamer.cpp (1356) cv::GStreamerCapture::open OpenCV | GStreamer warning: unable to start pipeline

[ WARN:[email protected]] global C:\ci_311_rebuilds\opencv-suite_1679001454889\work\modules\videoio\src\cap_gstreamer.cpp (862) cv::GStreamerCapture::isPipelinePlaying OpenCV | GStreamer warning: GStreamer: pipeline have not been created

我已经尝试了我找到的每一个解决方案,但没有任何帮助我解决了它,我重新安装了所有东西,我安装了所有应该是问题的插件,但没有任何帮助:(。

我在 Windows 10 上运行它 使用anaconda 3环境 蟒蛇3.11 IDE pycharm

感谢您的帮助!

尝试毫无问题地运行代码

opencv anaconda gstreamer anaconda3 python-3.11
© www.soinside.com 2019 - 2024. All rights reserved.