[boot.py] It won't run

I am using it as an industrial camera.
This is openmv4 h7 plus product.
I am using it by uploading boot.py.
There are no problems in the office.
In an industrial setting, it works well at first. After some time, it won’t work. It seems to be a problem with the surrounding environment. We are going to test by uploading main.py. I was wondering if you had any experience like this before.

Can you point out the failure? Note that you might want to enable the watchdog on the processor. In general, power issues are likely your problem causing the processor to brownout.

Below is my program. The algorithm part has been deleted.

boot.py source.

import sensor, image, time, math, pyb
from machine import WDT
from pyb import LED
from pyb import UART

uart = UART(3, 9600)
uart1 = UART(1, 9600)
red_led   = LED(1)
green_led = LED(2)
blue_led  = LED(3)
ir_led	= LED(4)

def led_control(x):
    if   (x&1)==0: red_led.off()
    elif (x&1)==1: red_led.on()
    if   (x&2)==0: green_led.off()
    elif (x&2)==2: green_led.on()
    if   (x&4)==0: blue_led.off()
    elif (x&4)==4: blue_led.on()
    if   (x&8)==0: ir_led.off()
    elif (x&8)==8: ir_led.on()

sensor.reset()
sensor.set_framerate(15)
sensor.set_pixformat(sensor.GRAYSCALE)
sensor.set_framesize(sensor.VGA)
sensor.set_auto_gain(False,0)
sensor.set_auto_whitebal(False)#ov7725,5640
sensor.set_auto_exposure(False,exposure_us=100)
sensor.skip_frames(time = 200)

clock = time.clock()

wdt = WDT(timeout=500)  # enable it with a timeout of 500ms
wdt.feed()

while(True):
    clock.tick()
    wdt.feed()
    img = sensor.snapshot()

    for blob in img.find_blobs(thresholds, area_threshold=2, pixels_threshold=2, merge=True, margin=1 ):#area_threshold=2, pixels_threshold=2, merge=True, margin=1
        if abs(blob.w() - blob.h()) <= (blob.w() + blob.h())/5 + 4 and blob.w()<60 and blob.h()<60 and blob.w()>=1 and blob.h()>=1 and count<20 and blob.cxf()>0 and blob.cyf()>0:
            Listx[count] = blob.cxf()
            Listy[count] = blob.cyf()
            Listxs[count] = blob.w()
            Listys[count] = blob.h()
            #img.draw_circle(blob.enclosing_circle( ))
            #img.draw_rectangle(blob.rect(),(0))
            #img.draw_cross(blob.cx(), blob.cy(),(150),5,1)
            count = count+1
        #else:
            #img.draw_rectangle(blob.rect(),(180))
            #print('[%03d][%03d]'% (blob.w(),blob.h()))
           # img.draw_cross(blob.cx(), blob.cy(),(180),8,2)
        if count==20:
            break
pyb.hard_reset( )

Even if the camera brought from the field is turned on, it does not proceed.
We are reviewing power related issues.

And there is a problem that an error occurs when a lot of find_blob is detected. It seems to be a memory related issue. We request that the number of detections be limited so that errors do not occur in the original. When an error occurs, it is reset.

You need to add try: except: to your program to handle exceptions and recover from them.

example source please

try:
  while(True):
      clock.tick()
      wdt.feed()
      img = sensor.snapshot()
  
      for blob in img.find_blobs(thresholds, area_threshold=2, pixels_threshold=2, merge=True, margin=1 ):#area_threshold=2, pixels_threshold=2, merge=True, margin=1
          if abs(blob.w() - blob.h()) <= (blob.w() + blob.h())/5 + 4 and blob.w()<60 and blob.h()<60 and blob.w()>=1 and blob.h()>=1 and count<20 and blob.cxf()>0 and blob.cyf()>0:
              Listx[count] = blob.cxf()
              Listy[count] = blob.cyf()
              Listxs[count] = blob.w()
              Listys[count] = blob.h()
              #img.draw_circle(blob.enclosing_circle( ))
              #img.draw_rectangle(blob.rect(),(0))
              #img.draw_cross(blob.cx(), blob.cy(),(150),5,1)
              count = count+1
          #else:
              #img.draw_rectangle(blob.rect(),(180))
              #print('[%03d][%03d]'% (blob.w(),blob.h()))
             # img.draw_cross(blob.cx(), blob.cy(),(180),8,2)
          if count==20:
              break
except:
  pyb.hard_reset( )

https://docs.python.org/3/tutorial/errors.html

:+1: Thank you very much.