星瞳实验室APP,快速收到回复
  • 我们只解决官方正版的OpenMV的问题(STM32),其他的分支有很多兼容问题,我们无法解决。
  • 如果有产品硬件故障问题,比如无法开机,论坛很难解决。可以直接找售后维修
  • 发帖子之前,请确认看过所有的视频教程,https://singtown.com/learn/ 和所有的上手教程http://book.openmv.cc/
  • 每一个新的提问,单独发一个新帖子
  • 帖子需要目的,你要做什么?
  • 如果涉及代码,需要报错提示全部代码文本,请注意不要贴代码图片
  • 必看:玩转星瞳论坛了解一下图片上传,代码格式等问题。
  • AprilTag测距准确性问题,是否需要做相机参数校准标定?



    • 使用find_apriltags_3d_pose例程来获取AprilTag相对于相机的6-DOF位姿,但是当相机保持固定,在和相机距离恒定的墙面上移动AprilTag(从视野到边缘)却发现Z方向位移值一直有变化,理论上这不应该呀,这个误差是由什么造成的呢?是和镜头畸变有关吗?但是例程注释里说识别AprilTag不需要对相机做校准呀。



    • z方向是标签和OpenMV的距离轴。这个是通过画面中的大小计算的。



    • 你提供一下具体的代码,误差数据,
      和实际场景的照片,和OpenMV画面里标签的大小的照片。



    • 代码就是IDE中AprilTag定位的例程(位移乘了个k换算成了实际距离):

      # AprilTags Example
      #
      # This example shows the power of the OpenMV Cam to detect April Tags
      # on the OpenMV Cam M7. The M4 versions cannot detect April Tags.
      
      import sensor, image, time, math
      
      sensor.reset()
      sensor.set_pixformat(sensor.RGB565)
      sensor.set_framesize(sensor.QQVGA) # we run out of memory if the resolution is much bigger...
      sensor.skip_frames(time = 2000)
      sensor.set_auto_gain(False)  # must turn this off to prevent image washout...
      sensor.set_auto_whitebal(False)  # must turn this off to prevent image washout...
      clock = time.clock()
      
      tag_families = 0
      tag_families |= image.TAG16H5 # comment out to disable this family
      tag_families |= image.TAG25H7 # comment out to disable this family
      tag_families |= image.TAG25H9 # comment out to disable this family
      tag_families |= image.TAG36H10 # comment out to disable this family
      tag_families |= image.TAG36H11 # comment out to disable this family (default family)
      tag_families |= image.ARTOOLKIT # comment out to disable this family
      
      # What's the difference between tag families? Well, for example, the TAG16H5 family is effectively
      # a 4x4 square tag. So, this means it can be seen at a longer distance than a TAG36H11 tag which
      # is a 6x6 square tag. However, the lower H value (H5 versus H11) means that the false positve
      # rate for the 4x4 tag is much, much, much, higher than the 6x6 tag. So, unless you have a
      # reason to use the other tags families just use TAG36H11 which is the default family.
      
      def family_name(tag):
          if(tag.family() == image.TAG16H5):
              return "TAG16H5"
          if(tag.family() == image.TAG25H7):
              return "TAG25H7"
          if(tag.family() == image.TAG25H9):
              return "TAG25H9"
          if(tag.family() == image.TAG36H10):
              return "TAG36H10"
          if(tag.family() == image.TAG36H11):
              return "TAG36H11"
          if(tag.family() == image.ARTOOLKIT):
              return "ARTOOLKIT"
      
      # Note! Unlike find_qrcodes the find_apriltags method does not need lens correction on the image to work.
      
      # What's the difference between tag families? Well, for example, the TAG16H5 family is effectively
      # a 4x4 square tag. So, this means it can be seen at a longer distance than a TAG36H11 tag which
      # is a 6x6 square tag. However, the lower H value (H5 versus H11) means that the false positve
      # rate for the 4x4 tag is much, much, much, higher than the 6x6 tag. So, unless you have a
      # reason to use the other tags families just use TAG36H11 which is the default family.
      
      # The AprilTags library outputs the pose information for tags. This is the x/y/z translation and
      # x/y/z rotation. The x/y/z rotation is in radians and can be converted to degrees. As for
      # translation the units are dimensionless and you must apply a conversion function.
      
      # f_x is the x focal length of the camera. It should be equal to the lens focal length in mm
      # divided by the x sensor size in mm times the number of pixels in the image.
      # The below values are for the OV7725 camera with a 2.8 mm lens.
      
      # f_y is the y focal length of the camera. It should be equal to the lens focal length in mm
      # divided by the y sensor size in mm times the number of pixels in the image.
      # The below values are for the OV7725 camera with a 2.8 mm lens.
      
      # c_x is the image x center position in pixels.
      # c_y is the image y center position in pixels.
      
      f_x = (2.8 / 3.984) * 160 # find_apriltags defaults to this if not set
      f_y = (2.8 / 2.952) * 120 # find_apriltags defaults to this if not set
      c_x = 160 * 0.5 # find_apriltags defaults to this if not set (the image.w * 0.5)
      c_y = 120 * 0.5 # find_apriltags defaults to this if not set (the image.h * 0.5)
      
      def degrees(radians):
          return (180 * radians) / math.pi
      
      while(True):
          clock.tick()
          img = sensor.snapshot()
          for tag in img.find_apriltags(fx=f_x, fy=f_y, cx=c_x, cy=c_y): # defaults to TAG36H11
              img.draw_rectangle(tag.rect(), color = (255, 0, 0))
              img.draw_cross(tag.cx(), tag.cy(), color = (0, 255, 0))
              print_args = (family_name(tag), tag.id(), tag.x_translation()*4.317, tag.y_translation()*4.317, tag.z_translation()*4.317, \
                  degrees(tag.x_rotation()), degrees(tag.y_rotation()), degrees(tag.z_rotation()))
              # Translation units are unknown. Rotation units are in degrees.
              print("Tag Family %s, Tag ID %d, Tx: %f, Ty %f, Tz %f, Rx %f, Ry %f, Rz %f" % print_args)
          print(clock.fps())
      

      ![0_1600024664856_00.jpg](正在上传 100%)
      0_1600024676498_01.png
      0_1600024681261_02.png 0_1600024687028_03.png
      0_1600024718971_04.png
      场景和结果如图,AprilTag紧贴墙平移,OpenMV固定在和墙平移距墙恒定的位置,按说Ty Tz应该在平移过程中保持不变,但尤其Z方向,有一个0.5cm左右的误差



    • @kidswong999 代码和图片如上,场景图片显示失败,就是AprilTag靠墙平移,摄像头粘在盒子上固定在和墙平行且距离恒定的位置。

      那请问X和Y方向是怎么实现定位的呢?可以提供底层代码吗?





    • @kidswong999
      那请问对如图的Y和Z方向的误差的原因,有什么见解呢?