Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

how to save thresholding video in python opencv

import numpy as np import cv2

cap = cv2.VideoCapture(0)

fourcc = cv2.VideoWriter_fourcc(*'XVID') out = cv2.VideoWriter('output.avi', fourcc, 20.0, (640,480)) frame1 = None while(cap.isOpened()): ret, frame = cap.read() if ret==True: #frame = cv2.flip(frame,0) gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY) if frame1 is None: frame1 = gray frameT = cv2.absdiff(frame1, gray) _ ,thresh = cv2.threshold(frameT, 25, 255, cv2.THRESH_BINARY)

    out.write(thresh)
    cv2.imshow('thresh',thresh)
    cv2.imshow('frame',frame)
    if cv2.waitKey(1) & 0xFF == ord('q'):
        break
else:
    break

cap.release()

out.release()

cv2.destroyAllWindows()

by using above code i can save the video as frame by using this "out.write(frame)" but not able to save video "out.write(thresh)" when i use this any idea please?

how to save thresholding video in python opencv

import numpy as np np

import cv2

cap = cv2.VideoCapture(0)

fourcc = cv2.VideoWriter_fourcc(*'XVID') cv2.VideoWriter_fourcc(*'XVID')

out = cv2.VideoWriter('output.avi', fourcc, 20.0, (640,480)) (640,480))

frame1 = None while(cap.isOpened()): None

while(cap.isOpened()):

ret, frame = cap.read()
  if ret==True:
      #frame = cv2.flip(frame,0)
      gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
      if frame1 is None:
          frame1 = gray
      frameT = cv2.absdiff(frame1, gray)
      _ ,thresh = cv2.threshold(frameT, 25, 255, cv2.THRESH_BINARY)

cv2.THRESH_BINARY)



    out.write(thresh)
     cv2.imshow('thresh',thresh)
     cv2.imshow('frame',frame)
     if cv2.waitKey(1) & 0xFF == ord('q'):
         break
 else:
     break

cap.release()

out.release()

cv2.destroyAllWindows()

by using above code i can save the video as frame by using this "out.write(frame)" but not able to save video "out.write(thresh)" when i use this any idea please?