导入cv2
cap = cv2.VideoCapture('video.avi')
car_cascade = cv2.CascadeClassifier('cars.xml')
如果已初始化捕获,则虽然是真的: #从视频中读取帧 ret,frames = cap.read()
# convert to gray scale of each frames
gray = cv2.cvtColor(frames, cv2.COLOR_BGR2GRAY)
*[
cars = car_cascade.detectMultiScale(gray, 1.1, 1)
# To draw a rectangle in each cars
for (x,y,w,h) in cars:
cv2.rectangle(frames,(x,y),(x+w,y+h),(0,0,255),2)
# Display frames in a window
] [1] * cv2.imshow('video2',frames)
# Wait for Esc key to stop
if cv2.waitKey(33) == 27:
break
cv2.destroyAllWindows()
来源:https://github.com/shaanhk/New-GithubTest 错误: Traceback(最近一次调用最后一次): 文件“C:/Users/xyz/Desktop/python/abc/detection/detect.py”,第9行,in car_cascade = cv2.CascadeClassifier('cars.xml') cv2.error:C:\ projects \ opencv-python \ opencv \ modules \ core \ src \ persistence.cpp:2754:错误:(-212)cars.xml(2):属性名称后跟'='函数icvXMLParseTag
直到现在我找不到答案帮助我 提前致谢
答案 0 :(得分:0)
以下代码是您的错误弹出的地方。我从persistence.cpp中获取了这个。我认为这可能是你的xml文件本身的问题。
if( *ptr != '=' )
{
ptr = icvXMLSkipSpaces( fs, ptr, CV_XML_INSIDE_TAG );
if( *ptr != '=' )
CV_PARSE_ERROR( "Attribute name should be followed by \'=\'" );
}