Hi there,
Quick question here on how to save data from the OpenMV camera to a file on the SD card.
I have a piece of code (below) measuring blob area, and I want to save these to the SD card. It works for the blob area (line 29-31) but I also want to save the blob coordinates and elapsed time.
How should I code the write command? Something like this doesn’t seem to work: f.write(“%d\n” % area, blob.cx(), blob.cy(), pyb.elapsed_millis(start)).
Any help much appreciated
Full code here:
import sensor, image, time, pyb, mjpeg, math, uarray
sensor.reset()
sensor.set_pixformat(sensor.RGB565)
sensor.set_framesize(sensor.QVGA)
sensor.set_windowing([180,160])
sensor.skip_frames(time = 2000)
clock = time.clock()
thresholds = (0, 30)
numbers = [0]
m = mjpeg.Mjpeg('openmv_video.mp4')
img = sensor.snapshot()
clock = time.clock()
start = pyb.millis()
with open("area.txt", "wb") as f:
while(True):
clock.tick()
for blob in img.find_blobs([thresholds], pixels_threshold=20, area_threshold=10, merge=True):
# These values depend on the blob not being circular - otherwise they will be shaky.
if blob.elongation() > 0.2:
img.draw_edges(blob.min_corners(), color=0)
img.draw_line(blob.major_axis_line(), color=0)
img.draw_line(blob.minor_axis_line(), color=0)
# These values are stable all the time.
img.draw_rectangle(blob.rect(), color=127)
img.draw_cross(blob.cx(), blob.cy(), color=127)
area = blob.area()
print(area, blob.cx(), blob.cy(), pyb.elapsed_millis(start))
f.write("%d\n" % area)
m.add_frame(sensor.snapshot())
if pyb.elapsed_millis(start) > 10000:
print('over')
print(time)
m.close(clock.fps())
break