Hi Kwagyeman,
Im running my script and, often, after 5min aprox, some other times after 15min… my h7 plus camera is disconnected from the IDE.
Do you have a guess of what am I doing wrong?
My scripts are not called “main.py” but i guess thats fine because while running the script the H7 plus is connected to the PC. (Please correct me if I am wrong)
I do not know if the high temperature of the hardware has something to do… or if the framesize that im using is a problem because it is too big.
Thanks in advance!
Code is below:
import sensor, image, time, os, tf, pyb, math
L_mean = 0
A_mean = 8
B_mean = 16
sensor.reset() # Reset and initialize the sensor.
sensor.set_pixformat(sensor.GRAYSCALE)
sensor.set_framesize(sensor.WQXGA2) #2592x1944
sensor.set_windowing((1775,1450))
sensor.set_saturation(-3)
sensor.set_contrast(-3)
sensor.set_brightness(0)
sensor.skip_frames(time=2000) # Let the camera adjust.
net = "trained.tflite"
labels = [line.rstrip('\n') for line in open("labels.txt")]
clock = time.clock()
base_image = sensor.snapshot()
start = True
decision = [0,0,0]
if not "temp" in os.listdir(): os.mkdir("temp") # Make a temp directory
while(True):
clock.tick()
img = sensor.snapshot()
if start == False:
base_image = potential_image
base_hist = base_image.histogram()
base_image_stats = base_hist.get_statistics()
base_image_L_mean = base_image_stats[L_mean]
potential_image = sensor.snapshot()
potential_hist = potential_image.histogram()
potential_image_stats = potential_hist.get_statistics()
potential_image_L_mean = potential_image_stats[L_mean]
DeltaE = math.fabs(potential_image_L_mean - base_image_L_mean)
decision[0] = decision[1]
decision[1] = decision[2]
decision[2] = DeltaE
sumDecision = decision[0] + decision[1] + decision[2]
if sumDecision > 2.42:
saved = "YES"
else:
saved ="NO"
FPS = clock.fps()
start = False
frames = 0
frames_limit = 9
Background = 0
NonTarget = 0
Target = 0
predicted = "Unclear"
if saved == "YES":
while(frames <= frames_limit):
for obj in tf.classify(net, img, min_scale=1.0, scale_mul=0.8, x_overlap=0.5, y_overlap=0.5):
predictions_list = list(zip(labels, obj.output()))
Background = Background + predictions_list[0][1]
NonTarget = NonTarget + predictions_list[1][1]
Target = Target + predictions_list[2][1]
frames = frames + 1
Background_mean = Background/(frames_limit + 1)
NonTarget_mean = NonTarget/(frames_limit + 1)
Target_mean = Target/(frames_limit + 1)
if (Background >= 6):
predicted = "Background"
if (NonTarget >=5):
predicted = "Not Target"
if (Target >= 7):
predicted = "Target!"
print("Predictions: Background: %.2f, Not target: %.2f, Target: %.2f. Predicted: %s" % (Background, NonTarget, Target, predicted))