我正在传递视频作为输入,而抓取的视频就是输出。输出显示在窗口中,但最后会抛出属性错误,并且视频文件以给定名称保存,但文件为空。
我经历了许多与此类似的问题,我尝试了所有这些答案,但输出是相同的。谁能告诉我这段代码有什么错误?
import imutils
import numpy as np
import argparse
import cv2
ap = argparse.ArgumentParser()
ap.add_argument("-v", "--video",
help="path to the (optional) video file")
args = vars(ap.parse_args())
lower = np.array([0, 0, 20], dtype="uint8")
upper = np.array([25, 255, 255], dtype="uint8")
if not args.get("video", False):
camera = cv2.VideoCapture('videos/15-IMG_1090.MOV')
fourcc = cv2.VideoWriter_fourcc(*'XVID')
out = cv2.VideoWriter('output.avi',fourcc, 20.0, (640,480))
else:
camera = cv2.VideoCapture('videos/15-IMG_1093.MOV')
fourcc = cv2.VideoWriter_fourcc(*'XVID')
out = cv2.VideoWriter('output.avi',fourcc, 20.0, (640,480))
while True:
# grab the current frame
(grabbed, frame) = camera.read()
if args.get("video") and not grabbed:
break
# resize the frame, convert it to the HSV color space,
# and determine the HSV pixel intensities that fall into
# the speicifed upper and lower boundaries
frame = imutils.resize(frame, width=500)
converted = cv2.cvtColor(frame, cv2.COLOR_BGR2HSV)
skinMask = cv2.inRange(converted, lower, upper)
kernel = cv2.getStructuringElement(cv2.MORPH_ELLIPSE, (11, 11))
skinMask = cv2.erode(skinMask, kernel, iterations=2)
skinMask = cv2.dilate(skinMask, kernel, iterations=2)
skinMask = cv2.GaussianBlur(skinMask, (3, 3), 0)
skin = cv2.bitwise_and(frame, frame, mask=skinMask)
out.write(skin)
cv2.imshow("images", np.hstack([frame, skin]))
# if the 'q' key is pressed, stop the loop
if cv2.waitKey(1) & 0xFF == ord("q"):
break
camera.release()
out.release()
cv2.destroyAllWindows()
这是错误。
Traceback (most recent call last):
File "E:/Harshitha/python learning/python/video_analysis/new_code_grab.py", line 60, in <module>
frame = imutils.resize(frame, width=500)
File "C:\Users\Harshitha\Anaconda3\lib\site-packages\imutils\convenience.py", line 69, in resize
(h, w) = image.shape[:2]
AttributeError: 'NoneType' object has no attribute 'shape'
请任何人帮助我纠正错误并保存新的抓取视频。 谢谢。