1
我已經閱讀了許多關於包含文件完整路徑的解決方案,並且已經嘗試過了,但它不工作!OpenCV錯誤:錯誤:(-215)scn == 3 || scn == 4在函數cv :: cvtColor
這是基本的代碼上我的工作:
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]
請幫助!
先生,我已經嘗試過了,我收到了同樣的錯誤。 –
還是這樣說:
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]
?什麼是新的輸出? – travisjayday好的,另外:嘗試使用'F:/ KUNAL ECE/SPIG/video.avi' – travisjayday