I’m using OpenMV on a project which requires the running code switches between color and black&white modes dynamically according to the message received by UART.
The situation:
By default, I set the sensor to GRAYSCALE and then set it to RGB565 according to the UART. Possibly, I need to set back to GRAYSCALE.
However, when I test it, the camera would freeze when I switch the sensor between GRAYSCALE and RGB565 for 1 or 2 times.
What could cause this problem? And how should this be fixed?
I guess it may be related to the UART interrupt because I try to use a counter variable to switch the mode and it didn’t freeze.
By the way, sometimes when I reconnect the Cam to the IDE, and run the code for the first time, the IDE would show: “MemoryError: memory allocation failed”…What is this problem?
Some key code:
def init(mode):
if mode == TRACK_XY:
# sensor.reset()
sensor.set_pixformat(sensor.GRAYSCALE)
sensor.set_framesize(sensor.QQVGA)
sensor.skip_frames(300)
sensor.set_auto_gain(True)
sensor.set_auto_whitebal(False)
elif mode == TRACK_COLOR:
# sensor.reset()
sensor.set_pixformat(sensor.RGB565)
sensor.set_framesize(sensor.QQVGA)
sensor.skip_frames(time=1500)
sensor.set_auto_gain(False)
sensor.set_auto_whitebal(False)
if color_learn:
threshold_learn(threshold_color_mid)
print(threshold_color_mid)
elif mode == TRACK_TAG:
# sensor.reset()
sensor.set_pixformat(sensor.GRAYSCALE)
sensor.set_framesize(sensor.QQVGA)
sensor.skip_frames(time=30)
sensor.set_auto_gain(False)
sensor.set_auto_whitebal(False)
else:
pass
while(True):
# Init
if init_flag == 0:
init(cam_mode)
init_flag = 1
if cam_mode == SLEEP:
pass
elif cam_mode == TRACK_XY:
img = sensor.snapshot()
pass
elif cam_mode == TRACK_COLOR:
img = sensor.snapshot()
pass
elif cam_mode == TRACK_TAG:
pass
#read mode from uart
cam_mode_old = cam_mode
for i in range(available()):
parse_byte(read_byte())
# Init again
if cam_mode != cam_mode_old:
init_flag = 0