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



    • import sensor, image, time, math

      threshold=(60, 255, -20, 20, -20, 20) # 激光灯在纸上颜色的阈值,可以执行调节
      from pyb import Pin
      sensor.reset()
      sensor.set_auto_gain(False)
      sensor.set_pixformat(sensor.GRAYSCALE) # or sensor.RGB565
      sensor.set_framesize(sensor. QVGA) # or sensor.QVGA (or others)
      sensor.skip_frames(time=900) # Let new settings take affect.
      sensor.set_auto_exposure(False, 1000)#在这里调节曝光度,调节完可以比较清晰地看清激光点
      sensor.set_auto_whitebal(False) # turn this off.
      sensor.set_auto_gain(False) # 关闭增益(色块识别时必须要关)
      clock = time.clock() # Tracks FPS.

      def color_blob(threshold):

      blobs = img.find_blobs([threshold,x_stride=1, y_stride=1, area_threshold=0, pixels_threshold=0,merge=False,margin=1])
      
      if len(blobs)>=1 :#有色块
          # Draw a rect around the blob.
          b = blobs[0]
          img.draw_rectangle(b[0:4]) # rect
          cx = b[5]
          cy = b[6]
          for i in range(len(blobs)-1):
              img.draw_rectangle(b[0:4]) # rect
              cx = blobs[i][5]+cx
              cy = blobs[i][6]+cy
          cx=int(cx/len(blobs))
          cy=int(cy/len(blobs))
          img.draw_cross(cx, cy) # cx, cy
          print(cx,cy)
          return int(cx), int(cy)
      return -1, -1 #表示没有找到
      

      while(True):
      clock.tick() # Track elapsed milliseconds between snapshots().
      img = sensor.snapshot() # Take a picture and return the image.

      blobs = img.find_blobs([threshold])
      if blobs:
          max_blob = color_blob(threshold)
          pan_error = max_blob.cx()-img.width()/2
          tilt_error = max_blob.cy()-img.height()/2
      
          print("pan_error: ", pan_error)
      
          img.draw_rectangle(max_blob.rect()) # rect
          img.draw_cross(max_blob.cx(), max_blob.cy()) # cx, cy
      
          pan_output=pan_pid.get_pid(pan_error,1)/2
          tilt_output=tilt_pid.get_pid(tilt_error,1)
          print("pan_output",pan_output)
          pan_servo.angle(pan_servo.angle()+pan_output)
          tilt_servo.angle(tilt_servo.angle()-tilt_output)