简体   繁体   English

不支持 python opencv 格式

[英]python opencv format not supported

import cv2
image_counter = 0
video = cv2.VideoCapture(0)
while True:
    check, frame = video.read()
    gray_f = cv2.flip(frame, 1)
    gray = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
    gray_flip = cv2.flip(frame, 1)
    cv2.imshow("kara", gray_flip)
    key = cv2.waitKey(1)

    if key == ord('q'):
        break
video.release()
cv2.destroyAllWindows()

I have written this code for using my camera using OpenCV python 3 it worked earlier but after I upgraded my python it gives following error:-我已经编写了这段代码,用于使用 OpenCV python 3 使用我的相机,但在我升级了 python 后它会更早地工作,但它会给出以下错误:-

[ WARN:0] global C:\Users\appveyor\AppData\Local\Temp\1\pip-req-build-j8nxabm_\opencv\modules\videoio\src\cap_msmf.cpp (682) CvCapture_MSMF::initStream Failed to set mediaType (stream 0, (640x480 @ 30) MFVideoFormat_RGB24(unsupported media type) [警告:0] 全局 C:\Users\appveyor\AppData\Local\Temp\1\pip-req-build-j8nxabm_\opencv\modules\videoio\src\cap_msmf.cpp (682) CvCapture_MSMF::initStream 设置失败mediaType (stream 0, (640x480 @ 30) MFVideoFormat_RGB24(不支持的媒体类型)

Python version:3.8.5 x64
OpenCV version: 4.4.0.42

The following code resolved this issue for me:以下代码为我解决了这个问题:

video = cv2.VideoCapture(0,cv2.CAP_DSHOW)

i had this problem with java and Open Cv the problem is because the format of the video file (video.mp4) has sound and this is the reason why appear the trouble "MFVideoFormat_RGB32(unsupported media type)" the solution i found was use ffmpeg, I remove the audio of the video file with the next comand in cmd:我在使用 java 和 Open Cv 时遇到了这个问题,问题是因为视频文件(video.mp4)的格式有声音,这就是出现“MFVideoFormat_RGB32(不支持的媒体类型)”问题的原因,我找到的解决方案是使用 ffmpeg ,我用 cmd 中的下一个命令删除视频文件的音频:

ffmpeg -i video.mp4 -an -c copy no_sound.mp4

Then I use the no_sound.mp4 in the next code:然后我在下一个代码中使用 no_sound.mp4:

VideoCapture cap =  new VideoCapture();
cap.open("no_sound.mp4");

This worked for me.这对我有用。

It's a reported issue, See the details: https://github.com/opencv/opencv/issues/16711这是一个报告的问题,请参阅详细信息: https://github.com/opencv/opencv/issues/16711

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM