• 免费好用的星瞳AI云服务上线!简单标注,云端训练,支持OpenMV H7和OpenMV H7 Plus。可以替代edge impulse。 https://forum.singtown.com/topic/9519
  • 我们只解决官方正版的OpenMV的问题(STM32),其他的分支有很多兼容问题,我们无法解决。
  • 如果有产品硬件故障问题,比如无法开机,论坛很难解决。可以直接找售后维修
  • 发帖子之前,请确认看过所有的视频教程,https://singtown.com/learn/ 和所有的上手教程http://book.openmv.cc/
  • 每一个新的提问,单独发一个新帖子
  • 帖子需要目的,你要做什么?
  • 如果涉及代码,需要报错提示全部代码文本,请注意不要贴代码图片
  • 必看:玩转星瞳论坛了解一下图片上传,代码格式等问题。
  • 帧间差分法代码中灰度值相减在哪部分呀?



    • # 高级帧间差分例子
      #
      # 注意: 为了运行这个程序,你需要插入SD卡。
      #
      # 这个例子示范了OpenMV的帧间差分算法。
      # 之所以叫做高级的帧间查分,是因为背景图片会实时更新
      
      import sensor, image, pyb, os, time
      
      BG_UPDATE_FRAMES = 50 # How many frames before blending. 融合前有多少帧图像
      BG_UPDATE_BLEND = 128 # How much to blend by... ([0-256]==[0.0-1.0]).
      
      sensor.reset() # 初始化摄像头
      
      sensor.set_pixformat(sensor.GRAYSCALE) # or sensor.RGB565
      #设置图像色彩格式,有RGB565色彩图和GRAYSCALE灰度图两种
      
      sensor.set_framesize(sensor.QVGA) # or sensor.QQVGA (or others)  
      #设置图像像素大小
      
      sensor.skip_frames(time = 2000) # 让新的设置生效
      sensor.set_auto_whitebal(False) # 关闭白平衡
      clock = time.clock() # 跟踪FPS帧率
      
      if not "temp" in os.listdir(): os.mkdir("temp") # 新建一个新的文件夹
      
      print("About to save background image...")
      sensor.skip_frames(time = 2000) # 给用户一个时间来准备
      sensor.snapshot().save("temp/bg.bmp")
      print("Saved background image - Now frame differencing!")
      
      frame_count = 0
      while(True):
          clock.tick() # 追踪两个snapshots()之间经过的毫秒数.
          img = sensor.snapshot() # 拍一张照片,返回图像
      
          frame_count += 1
          if frame_count > BG_UPDATE_FRAMES:
              frame_count = 0
              # Blend in new frame. We're doing 256-alpha here because we want to
              # blend the new frame into the backgound. Not the background into the
              # new frame which would be just alpha. Blend replaces each pixel by
              # ((NEW*(alpha))+(OLD*(256-alpha)))/256. So, a low alpha results in
              # low blending of the new image while a high alpha results in high
              # blending of the new image. We need to reverse that for this update.
      
              # 融入新的帧。
              # 我们在这里做256-alpha因为我们想把新帧混合到背景中而不是背景进入新帧,背景融入新帧只是alpha。
              # Blend将每个像素替换为((NEW*(alpha))+(OLD*(256-alpha)) /256.
              # 因此,低alpha导致新图像的低混合,而高alpha导致新图像的高混。
              # 我们需要在这次更新中逆转这一点
              img.blend("temp/bg.bmp", alpha=(256-BG_UPDATE_BLEND))
              img.save("temp/bg.bmp")
      
          # Replace the image with the "abs(NEW-OLD)" frame difference.
          # 将图像替换为 "abs(NEW-OLD)" 帧差
          img.difference("temp/bg.bmp")
      
          print(clock.fps()) # 注意: 当连接电脑后,OpenMV会变成一半的速度。当不连接电脑,帧率会增加。
      

      帧间差分法代码中灰度值相减在哪部分呀?