我已经编写了代码以找到轮廓并为其着色。但是视频无法保存,但可以成功运行。
我认为我将问题范围缩小到两行代码,当我对它们进行评论时,视频将保存,但将以灰度显示,这是我不想要的。
#change to black and white
gray = cv2.cvtColor(frame, cv2.COLOR_RGB2GRAY)
gaus = cv2.adaptiveThreshold(gray, 255, cv2.ADAPTIVE_THRESH_GAUSSIAN_C,
cv2.THRESH_BINARY, 115,50)
frame = gaus
#Bluring the video
blur = cv2.GaussianBlur(frame,(15,15),cv2.BORDER_DEFAULT)
frame = blur
# Canny Edge
Canny = cv2.Canny(frame ,25,50)
frame = Canny
# Contours
contours,hierachy= cv2.findContours(frame,cv2.RETR_TREE,cv2.CHAIN_APPROX_SIMPLE)
index = -1
thickness = 5
# these two lines bellow are preventing the file from being saved
img2 = cv2.cvtColor(frame, cv2.COLOR_GRAY2RGB)
frame = img2
cv2.drawContours(frame, contours, -1, (255,0,0), thickness)
# Save the video
cv2.imshow("frame", frame)
out.write(frame)