I am new at coding python and based the code on your github capture_raw10_opencv.py 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):
try:
print(“Reset the focus…”)
camera.reset_control(v4l2.V4L2_CID_FOCUS_ABSOLUTE)
except Exception as e:
print(e)
print(“The camera may not support this control.”)
try:
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:
print(e)
if name == “main”:
try:
camera = arducam.mipi_camera()
print(“Open camera…”)
camera.init_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))
set_controls(camera)
time.sleep(0.5)
#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...")
camera.close_camera()
except Exception as e:
print(e)