OpenCV(4.5.5) :-1: 错误: (-5:Bad argument) 在函数“cvtColor”中

发布于 2025-01-10 14:01:18 字数 1935 浏览 0 评论 0原文

你们能帮我吗?我正在尝试使用我自己的数据(路径=数据)通过在我的视频上应用媒体管道来创建数据集。处理后的 vid (.ny) 将位于我之前声明的输出文件夹 (path = O_Video) 中。 seq 数量为 30,因为我有 30 个视频,start_folder = 0 且 start_video = 0。

videos = cv2.VideoCapture(IMPORT_DATA)
videos_input = cv2.cvtColor(videos, cv2.COLOR_BGR2RGB)

# Set mediapipe model 
with mp_holistic.Holistic(min_detection_confidence=0.5, min_tracking_confidence=0.5) as holistic:
    
    # NEW LOOP
    # Loop through actions
    for action in actions:
    # Loop through sequences aka videos
        for sequence in range(start_folder, start_video+no_sequences):

                # get results
            results = mp_face.process(videos_input)

            for detection in results.detections: # iterate over each detection and draw on image
                  mp_drawing.draw_detection(videos, detection)
                
                
                # NEW Export keypoints
            keypoints = extract_keypoints(results)
            npy_path = os.path.join(DATA_PATH, action, str(sequence))
            np.save(npy_path, keypoints)

                # Break gracefully
            if cv2.waitKey(10) & 0xFF == ord('q'):
                break
                    
    cap.release()
    cv2.destroyAllWindows()

我收到的错误如下:

Error                                     Traceback (most recent call last)
Input In [15], in <module>
      1 videos = cv2.VideoCapture(IMPORT_DATA)
----> 2 videos_input = cv2.cvtColor(videos, cv2.COLOR_BGR2RGB)
      4 # Set mediapipe model 
      5 with mp_holistic.Holistic(min_detection_confidence=0.5, min_tracking_confidence=0.5) as holistic:
      6     
      7     # NEW LOOP
      8     # Loop through actions

error: OpenCV(4.5.5) :-1: error: (-5:Bad argument) in function 'cvtColor'
> Overload resolution failed:
>  - src is not a numpy array, neither a scalar
>  - Expected Ptr<cv::UMat> for argument 'src'

Can you guys help me? I'm trying to use my own data (path = data) to create a dataset by applying the mediapipe on my videos. The processed vid (.ny) will be in output folder (path = O_Video) which I have declared previously. No of seq is 30 as I have 30 videos with the start_folder = 0 and start_video = 0.

videos = cv2.VideoCapture(IMPORT_DATA)
videos_input = cv2.cvtColor(videos, cv2.COLOR_BGR2RGB)

# Set mediapipe model 
with mp_holistic.Holistic(min_detection_confidence=0.5, min_tracking_confidence=0.5) as holistic:
    
    # NEW LOOP
    # Loop through actions
    for action in actions:
    # Loop through sequences aka videos
        for sequence in range(start_folder, start_video+no_sequences):

                # get results
            results = mp_face.process(videos_input)

            for detection in results.detections: # iterate over each detection and draw on image
                  mp_drawing.draw_detection(videos, detection)
                
                
                # NEW Export keypoints
            keypoints = extract_keypoints(results)
            npy_path = os.path.join(DATA_PATH, action, str(sequence))
            np.save(npy_path, keypoints)

                # Break gracefully
            if cv2.waitKey(10) & 0xFF == ord('q'):
                break
                    
    cap.release()
    cv2.destroyAllWindows()

Error that I'm getting is as below:

Error                                     Traceback (most recent call last)
Input In [15], in <module>
      1 videos = cv2.VideoCapture(IMPORT_DATA)
----> 2 videos_input = cv2.cvtColor(videos, cv2.COLOR_BGR2RGB)
      4 # Set mediapipe model 
      5 with mp_holistic.Holistic(min_detection_confidence=0.5, min_tracking_confidence=0.5) as holistic:
      6     
      7     # NEW LOOP
      8     # Loop through actions

error: OpenCV(4.5.5) :-1: error: (-5:Bad argument) in function 'cvtColor'
> Overload resolution failed:
>  - src is not a numpy array, neither a scalar
>  - Expected Ptr<cv::UMat> for argument 'src'

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

我恋#小黄人 2025-01-17 14:01:18

您无法将 VideoCapture 对象传递给 cvtColor

您必须单独传递每个帧(numpy 数组)。

vid = cv.VideoCapture(...)
assert vid.isOpened()

while True:
    (valid, frame) = vid.read()
    if not valid:
        break

    converted = cv.cvtColor(frame, ...)
    ...

You can't pass a VideoCapture object to cvtColor.

You have to pass each frame (numpy array) individually.

vid = cv.VideoCapture(...)
assert vid.isOpened()

while True:
    (valid, frame) = vid.read()
    if not valid:
        break

    converted = cv.cvtColor(frame, ...)
    ...
但可醉心 2025-01-17 14:01:18

您需要捕获帧数据,如下所示。

videos = cv2.VideoCapture(IMPORT_DATA)
# Capture the video by frame
ret, frame = videos.read()
# check ret for success and then do this
videos_input = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)

you need to capture the frame data as shown below.

videos = cv2.VideoCapture(IMPORT_DATA)
# Capture the video by frame
ret, frame = videos.read()
# check ret for success and then do this
videos_input = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文