I am trying to convert my code that works on images to video. My program takes in an image, works out the mean RGB of each 9*9 window and outputs an image:
Here is my code that has an image as input/output:
import numpy as np
import cv2
#Read in image
img = cv2.imread('images/0021.jpg')
scale = 9
#Get x and y components of image
y_len,x_len,_ = img.shape
mean_values = []
for y in range(scale):
for x in range(scale):
#Crop image 3*3 windows
cropped_img=img[(y*y_len)/scale:((y+1)*y_len)/scale,
(x*x_len)/scale:((x+1)*x_len)/scale]
mean_val=cv2.mean(cropped_img)
mean_val=mean_val[:3]
cropped_img[:,:,:] = mean_val
print img.shape
cv2.imshow('mean_RGB',img)
cv2.waitKey(0)
When trying to use the same code on a video I get a video output but it is empty (0 bytes).
Here is the code:
import numpy as np
import cv2
cap = cv2.VideoCapture('videos/kondo2.avi')
fourcc = cv2.cv.CV_FOURCC(*'DIVX')
out = cv2.VideoWriter('videos/output.avi',fourcc, 15.0, (800,600),True)
while(cap.isOpened()):
ret, frame = cap.read()
if ret == True:
y_len,x_len,_ = frame.shape
scale = 9
for y in range(scale):
for x in range(scale):
cropped_frame=frame[(y*y_len)/scale:((y+1)*y_len)/scale,
(x*x_len)/scale:((x+1)*x_len)/scale]
mean_val=cv2.mean(cropped_frame)
mean_val=mean_val[:3]
cropped_frame[:,:,:] = mean_val
out.write(frame)
cap.release()
out.release()
cv2.destroyAllWindows()
Thank you for reading :)

