Ask Your Question

idg101's profile - activity

2020-08-10 03:09:32 -0600 received badge  Popular Question (source)
2016-07-29 23:37:20 -0600 received badge  Self-Learner (source)
2016-07-29 14:06:32 -0600 commented question Simple example of writing color imagery using VideoWriter in python

Solution (i am not waiting 2 days to answer my own question).

import cv2
import numpy as np
x = np.random.randint(0,255,(100,100,3)).astype('uint8')
writer = cv2.VideoWriter('output.avi', cv2.VideoWriter_fourcc('M','J','P','G'), 25, (100,100), True)
for k in range(100):
  writer.write(x)
writer.release()

EDIT 1:

I just changed video form to MJPG and it worked. I still have no idea why PIM1 doesnt work. It works on my other computer just fine.

2016-07-29 13:37:56 -0600 received badge  Editor (source)
2016-07-29 12:34:26 -0600 commented question Simple example of writing color imagery using VideoWriter in python

The avi file has size to it on disk, but VLC player wont play it. VLC doesnt give me an error, it simply hangs.

2016-07-29 12:10:05 -0600 asked a question Simple example of writing color imagery using VideoWriter in python

I want to be able to write out a color raster for each video from in python. However, when I pass a 3d array to video writer, it generates a bad output. What am I doing wrong?

Sampled code below....

 h,w = raster.shape
cmap = hot()
writer = cv2.VideoWriter('output.avi', cv2.VideoWriter_fourcc('P','I','M','1'), 25, (h,w), True)    
for i in range(len(images)):
    x = np.transpose((dsp.normalize(images[i]**(0.5))*255).astype('uint8'))
    x  = (cmap(x)*255).astype('uint8')
    for k in range(25):
        writer.write(x)  
del writer

EDIT 1: Here is a simplier, stand alone version of the problem. This hangs VLC.

import cv2
import numpy as np
x = np.random.randint(0,255,(100,100,3)).astype('uint8')
writer = cv2.VideoWriter('output.avi', cv2.VideoWriter_fourcc('P','I','M','1'), 25, (100,100), True)
for k in range(100):
  writer.write(x)
del writer