Segmentation fault, Arducam 2MP OV2311 Global Shutter NoIR Mono Camera

I am new at coding python and based the code on your github and edited it a bit so it would capture and save image on a loop but i get a segmentation fault and it does not capture or save an image. If i remove the loop, i get an raw10 image. i want to be able to get many images using loop

import arducam_mipicamera as arducam
import v4l2 #sudo pip install v4l2
import time
import numpy as np
import cv2 #sudo apt-get install python-opencv

frame = []

def align_down(size, align):
return (size & ~((align)-1))

def align_up(size, align):
return align_down(size + align - 1, align)

def set_controls(camera):
print(“Reset the focus…”)
except Exception as e:
print(“The camera may not support this control.”)

    print("Enable Auto Exposure...")
    camera.software_auto_exposure(enable = False)
    print("Enable Auto White Balance...")
    camera.software_auto_white_balance(enable = False)
except Exception as e:

if name == “main”:
camera = arducam.mipi_camera()
print(“Open camera…”)
camera.set_mode(6) # chose a camera mode which yields raw10 pixel format, see output of list_format utility
fmt = camera.get_format()
width = fmt.get(“width”)
height = fmt.get(“height”)
print(“Current resolution is {w}x{h}”.format(w=width, h=height))
# print(“Start preview…”)
# camera.start_preview(fullscreen = False, window = (0, 0, 1280, 720))
#while cv2.waitKey(10) != 27:
for i in range(5):

        frame[i] = camera.capture(encoding = 'raw')
        #height = fmt[1]
        #width  = fmt[0]
        frame[i] = arducam.remove_padding(frame[i].data, width, height, 10)
        frame[i] = arducam.unpack_mipi_raw10(frame[i])
        #frame = frame.reshape(height, width) << 6
        #image = frame
        #image = cv2.cvtColor(frame, cv2.COLOR_YUV2BGR_I420)
        #cv2.imshow("Arducam", frame)
        frame[i].tofile('ThesisTest' + str[i] + '.raw')

    # Release memory
    del frame
    # print("Stop preview...")
    # camera.stop_preview()
    print("Close camera...")
except Exception as e: