• OpenMV VSCode 扩展发布了,在插件市场直接搜索OpenMV就可以安装
  • 如果有产品硬件故障问题,比如无法开机,论坛很难解决。可以直接找售后维修
  • 发帖子之前,请确认看过所有的视频教程,https://singtown.com/learn/ 和所有的上手教程http://book.openmv.cc/
  • 每一个新的提问,单独发一个新帖子
  • 帖子需要目的,你要做什么?
  • 如果涉及代码,需要报错提示全部代码文本,请注意不要贴代码图片
  • 必看:玩转星瞳论坛了解一下图片上传,代码格式等问题。
  • 我的这个代码会运行一下之后后要么是运行一会响两声后中断(U盘插拔的两声),要么出现错误



    • import sensor, time, image, pyb
      sensor.reset()
      sensor.set_pixformat(sensor.GRAYSCALE)
      sensor.set_framesize(sensor.B128X128)
      sensor.set_windowing((92,112))
      sensor.skip_frames(10)
      sensor.skip_frames(time = 5000)
      NUM_SUBJECTS = 2
      NUM_SUBJECTS_IMGS = 3
      img = sensor.snapshot()
      d0 = img.find_lbp((0, 0, img.width(), img.height()))
      img1 = None
      pmin = 999999
      num=0
      def min(pmin, a, s):
          global num
          if a<pmin:
              pmin=a
              num=s
          return pmin
      import sensor, time, image
      from pyb import UART
      sensor.reset()
      sensor.set_contrast(1)
      sensor.set_gainceiling(16)
      sensor.set_framesize(sensor.HQVGA)
      sensor.set_pixformat(sensor.GRAYSCALE)
      face_cascade = image.HaarCascade("frontalface", stages=25)
      uart = UART(3, 115200, timeout_char=1000)
      clock = time.clock()
      num = 0
      while (True):
          clock.tick()
          img = sensor.snapshot()
          objects = img.find_features(face_cascade, threshold=0.75, scale_factor=1.25)
          for r in objects:
              if(r):
                  img.draw_rectangle(r,color = (0,255,0))
                  cx = r[0]+r[2]/2
                  cy = r[1]+r[3]/2
                  print('x:%d, y:%d, w:%d, h:%d' % (r[0],r[1],r[2],r[3]) )
                  print('cx = %d, cy = %d' % (cx,cy))
                  img = sensor.snapshot()
                  d0 = img.find_lbp((0, 0, img.width(), img.height()))
                  img1 = None
                  pmin = 999999
                  num=0
                  for s in range(1, NUM_SUBJECTS+1):
                      dist = 0
                      for i in range(1, NUM_SUBJECTS_IMGS+1):
                          img1 = image.Image("singtown/s%d/%d.pgm"%(s, i))
                          d1 = img1.find_lbp((0, 0, img1.width(), img1.height()))
                          dist += image.match_descriptor(d0, d1)
                      print("Average dist for subject %d: %d"%(s, dist/NUM_SUBJECTS_IMGS))
                      pmin = min(pmin, dist/NUM_SUBJECTS_IMGS, s)
                  print(pmin)
                  print(num)
                  uart.write('X%dY%dN%dOK\r\n' % (cx,cy,num))
                  break
          else:
                  uart.write('X-1Y-1N-1OK\r\n')
      
      

      0_1689150638759_IMG_6079.JPG