Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

In [23] import cv2 from scipy import misc import numpy as np import matplotlib.p

ID: 3727892 • Letter: I

Question

In [23] import cv2 from scipy import misc import numpy as np import matplotlib.pyplot as plt from PIL import Image In [25] import cv2 import os image_folder_nameUntitled Folder 1" video name -'video.avi' images = [ingi for img1 in os.listdir(image folder_name) if 1mg1.endswith(".jpg")] frame cv2.inread (os.path.join(image_folder_name, 'Untitled Folder 1'[0])) height, width, layers frame. Shape video-output cv2.VideoWriter(video-name , -1, 1, (width,height)) = for image1 in 'Untitled Folder 1': video_output.write(cv2.imread (os.path.join(image_folder_name, image1))) cv2.destroyAllWindows() video_output.release( Traceback (most recent call last) AttributeError ipython-input-25-09bf647522cE> in () img1.endswith(".jpg")] 1. [e])) if 7 images 8 frame = img1 [img1 for cv2.inread (os.path.join(image_folder_name, in os.listdir(image_folder_name) = 'Untitled Folder > 9 height, width, layers frame. Shape 10 11 video-output cv2.VideoWriter(video-name, -1, 1, (width,height)) = AttributeError: NoneType' object has no attribute 'shape'

Explanation / Answer

from images2gif import writeGif

from PIL import Image

from time import time

import os

import sys

#Part 1 -------------------------------

#Create the screengrabs

BatFileString = "GS.bat"

#Set Filename

BatFileString += " AD5.wmv"

#Set Start frame

BatFileString += " 75"

#Set Desired Number of Frames

BatFileString += " 10"

print BatFileString

os.system(BatFileString)

# Part 2 -------------------------------

#Get the file names

file_names = sorted((fn for fn in os.listdir('./Images') if fn.endswith('.png')))

print file_names

#Open the files

print 'Opening the images'

images = [Image.open('Images/' + fn) for fn in file_names]

#Resize

baseSize = images[0].size

minheight = 192

height = baseSize[1]

scale = float(height)/float(minheight)

print "Scale: " + str(scale)

print "Old Size: " + str(baseSize)

baseSize = ( int(baseSize[0] /scale) , int(baseSize[1] /scale) )

print 'Resizing'

size = baseSize;

for im in images:

im.thumbnail(size, Image.ANTIALIAS)

#Part 3-------------------------------

#Set to 24FPS

runningtime = 0.0416

print runningtime

print 'Saving'

filename = "Gif/Gif"

writeGif(filename + str(int(time())) + ".gif", images, duration=runningtime, dither=1, nq = 1)

#Clean Up -----------------------------

#Remove generated images

filelist = [ f for f in os.listdir('./Images') if f.endswith(".png") ]

for f in filelist:

os.remove('./Images/' + f)

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote