I'm making a mandelbrot set zoom video maker and openCV is not allowing me to feed in my numpy array.
My end goal is to make a video that zooms in on "interesting" points in the mandelbrot set automaticly, but for now all I'm doing is zooming in on the center.
This is my code for making the video.
from mandelbrot import getMandelbrot
import numpy as np
from cv2 import VideoWriter, VideoWriter_fourcc
import numpy
width = 500
height = 500
fps = 45
seconds = 1
fourcc = VideoWriter_fourcc(*'MP42')
video = VideoWriter('./mandelzoom.avi', fourcc, float(fps), (width, height))
for i in range(fps*seconds):
frame = getMandelbrot((-1/(i/(fps*seconds)+1), -1/(i/(fps*seconds)+1), 1/(i/(fps*seconds)+1), 1/(i/(fps*seconds)+1)), (width, height), 75)
video.write(np.array(frame, dtype=np.int8))
print("frame "+str(i)+" out of "+str(fps*seconds)+".")
video.release()
This is the mandelbrot module I have made.
import colorsys
def hsv2rgb(h,s,v):
return [round(i * 255) for i in colorsys.hsv_to_rgb(h,s,v)]
def doesConverge(c, iterations, radius=2):
x=0
xpre=0
for i in range(iterations):
xpre=x
x=x*x+c
if abs(x)>radius:
return hsv2rgb(i/iterations, 1, 1)
if xpre==x:
return [0, 0, 0]
return [0, 0, 0]
def getMandelbrot(locationRect, size, iterations):
scaleX = size[0]/abs(locationRect[0]-locationRect[2])
scaleY = size[1]/abs(locationRect[1]-locationRect[3])
mandelbrot=[]
for i in range(size[1]):
mandelbrot.append([])
for j in range(size[0]):
mandelbrot[i].append(doesConverge(complex(j/scaleX+locationRect[0], i/scaleY+locationRect[1]), iterations))
return mandelbrot
When I run my video maker, it throws this error:
File "C:/Users/Max/AppData/Local/Programs/Python/Python37/mandelzoom.py", line 15, in <module>
video.write(np.array(frame, dtype=np.int8))
cv2.error: OpenCV(4.1.0) C:\projects\opencv-python\opencv\modules\videoio\src\cap_ffmpeg.cpp:298: error: (-215:Assertion failed) image.depth() == CV_8U in function 'cv::`anonymous-namespace'::CvVideoWriter_FFMPEG_proxy::write'