我已经阅读了许多关于包含文件完整路径的解决方案并尝试了但是它无效!
这是我工作的基本代码:
import numpy as np
import cv2
import sys
import os
# capture frames from a video
cap = cv2.VideoCapture('F:\KUNAL ECE\SPIG\ video.avi')
#cap = cv2.VideoCapture(sys.argv[1])
# Trained XML classifiers describes some features of some object we want to detect
car_cascade = cv2.CascadeClassifier('F:\KUNAL ECE\SPIG\cars.xml')
# loop runs if capturing has been initialized.
while True:
# reads frames from a video
ret, frames = cap.read()
# convert to gray scale of each frames
gray = cv2.cvtColor(frames, cv2.COLOR_BGR2GRAY)
这是我得到的错误: -
OpenCV Error: Assertion failed (scn == 3 || scn == 4) in cv::cvtColor, file C:\projects\opencv-python\opencv\modules\imgproc\src\color.cpp, line 9748
Traceback (most recent call last):
File "F:\KUNAL ECE\SPIG\car.py", line 20, in <module>
gray = cv2.cvtColor(frames, cv2.COLOR_BGR2GRAY)
cv2.error: C:\projects\opencv-python\opencv\modules\imgproc\src\color.cpp:9748: error: (-215) scn == 3 || scn == 4 in function cv::cvtColor
warning: Error opening file (/build/opencv/modules/videoio/src/cap_ffmpeg_impl.hpp:779)
warning: F:\KUNAL ECE\SPIG\ video.avi (/build/opencv/modules/videoio/src/cap_ffmpeg_impl.hpp:780)
[Finished in 0.5s]
请帮助!!
答案 0 :(得分:0)
我认为opencv没有找到/读取你指定的avi文件。尝试删除字符串中的空格
'F:/ KUNAL ECE / SPIG / video.avi'