OpenCV错误:(-215)scn == 3 || scn == 4在函数ipp_cvtColor中 [英] OpenCV error: (-215) scn == 3 || scn == 4 in function ipp_cvtColor

查看:137
本文介绍了OpenCV错误:(-215)scn == 3 || scn == 4在函数ipp_cvtColor中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

按照教程中的说明,我尝试播放文件中的视频.我的程序如下:

I tried playing a video from a file, as given in the tutorials. My program was as follows:

import numpy as np
import cv2

cap = cv2.VideoCapture('output.avi')

while(cap.isOpened()):
    ret, frame = cap.read()
    frame = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
    cv2.imshow('outVideo',frame)
    if cv2.waitKey(1) & 0xFF == ord('q'):
        break

cap.release()
cv2.destroyAllWindows()

但是我遇到了以下错误:

But I got the following error:

Traceback (most recent call last):
  File "playVideo.py", line 8, in <module>
    frame = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
cv2.error: /home/hp/opencv/modules/imgproc/src/color.cpp:7456: error: (-215) scn == 3 || scn == 4 in function ipp_cvtColor

我检查了ret,结果发现它是False. 因此,实际的问题是保存视频.我使用以下代码通过VideoWriter函数保存了"output.avi":

I checked ret and it turned out to be False. So the actual problem is with saving video. I used the following code to save 'output.avi' using VideoWriter function:

import numpy as np
import cv2

cap = cv2.VideoCapture(0)
fourCc = cv2.VideoWriter_fourcc(*'XVID')
out = cv2.VideoWriter('output.avi',fourCc,20.0,(640,480))

while(cap.isOpened()):
    ret, frame = cap.read()
    if ret==True:
        frame = cv2.flip(frame,0)
        out.write(frame)
        cv2.imshow('frame',frame)
        if cv2.waitKey(1) & 0xFF == ord('q'):
            break
    else:
        break

cap.release()
out.release()
cv2.destroyAllWindows()

即使使用VLC,我也无法打开'output.avi'

I am not able to open 'output.avi', even using VLC

推荐答案

首先:

使用以下命令检查ret值:ret == True

check ret value with: ret==True

其次是教程中所说的:

确保已安装正确版本的ffmpeg或gstreamer.有时,使用Video Capture会让人头疼,主要是因为ffmpeg/gstreamer的安装错误.

Make sure proper versions of ffmpeg or gstreamer is installed. Sometimes, it is a headache to work with Video Capture mostly due to wrong installation of ffmpeg/gstreamer.

来自: http://docs.opencv.org/3.1.0/dd/d43/tutorial_py_video_display.html#gsc.tab = 0

最后检查视频编解码器: 无法使用opencv2打开视频

Finally check the video codec: Can't open video with opencv2

这篇关于OpenCV错误:(-215)scn == 3 || scn == 4在函数ipp_cvtColor中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆