how can i save the processed video as image sequence exactly as seen after processing

asked 2018-02-19 03:30:58 -0500

I used averaging algo to remove foreground. Now i want to save the output as the image sequence exactly as seen in #cv2.imshow('window_name',res2). i tried but not getting any result

   c= cv2.VideoCapture("p3.avi")
_,f = c.read()

avg1 = np.float32(f)
avg2 = np.float32(f)

try:
    if not os.path.exists('data2'):
        os.makedirs('data2')
except OSError:
    print ('Error: Creating directory of data')

currentFrame = 0

while(1):
    _,f = c.read()

    cv2.accumulateWeighted(f,avg1,0.1)
    cv2.accumulateWeighted(f,avg2,0.01)

    res1 = cv2.convertScaleAbs(avg1)
    res2 = cv2.convertScaleAbs(avg2)

    #cv2.imshow('img',f)

    #cv2.imshow('avg1',res1)
    #cv2.imshow('avg2',res2) 


    name = './data/frame' + str(currentFrame) + '.jpg'
    cv2.imwrite(name, res2)


    #frame_no=7800
    #c.set(1,frame_no); # Where frame_no is the frame you want
    # Read the frame
    #cv2.imshow('window_name',res2)


    k = cv2.waitKey(20)

    if k == 27:
        break

cv2.destroyAllWindows()
c.release()
edit retag flag offensive close merge delete

Comments

Something missing cv2.VideoWriter Check tutorial VideoWriter

supra56 gravatar imagesupra56 ( 2018-02-19 21:52:21 -0500 )edit

you're creating a data2 folder, but try to save images in data

berak gravatar imageberak ( 2018-02-20 05:09:40 -0500 )edit