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



    • 0_1555762894291_707312c6-72b9-43ff-b74e-0eadd15278ec-image.png
      试了好几种转换,就是报错。



    • 如果涉及代码,需要报错提示与全部代码文本,请注意不要贴代码图片



    • import sensor, image, time, pyb, math
      from pyb import UART,Pin,Timer
      import utime
      import json
      uart=pyb.UART(3,115200,timeout_char=1000)
      
      
      threshold_index = 0 # 0 for red, 1 for green, 2 for blue
      
      # Color Tracking Thresholds (L Min, L Max, A Min, A Max, B Min, B Max)
      # The below thresholds track in general red/green/blue things. You may wish to tune them...
      thresholds = [(30, 100, 15, 127, 15, 127), # generic_red_thresholds
                    (30, 100, -64, -8, -32, 32), # generic_green_thresholds
                    (0, 100, -16, 127, -128, -31)] # generic_blue_thresholds
      #-------------------摄像头初始化-----------------------------
      sensor.reset()
      sensor.set_pixformat(sensor.RGB565)
      sensor.set_framesize(sensor.QVGA)
      sensor.skip_frames(time = 2000)
      sensor.set_auto_gain(False) # must be turned off for color tracking
      sensor.set_auto_whitebal(False) # must be turned off for color tracking
      clock = time.clock()
      #start = pyb.millis() # get value of millisecond counter  获取毫秒计数器的值
      verify_code=b'\xFF\x00\xAA\xEA\xFF'
      # Only blobs that with more pixels than "pixel_threshold" and more area than "area_threshold" are
      # returned by "find_blobs" below. Change "pixels_threshold" and "area_threshold" if you change the
      # camera resolution. "merge=True" merges all overlapping blobs in the image.
      def find_max(blobs):
          max_size=0
          for blob in blobs:
           if blob[2]*blob[3]>max_size:
              max_blob=blob
              max_size=blob[2]*blob[3]
          return max_blob
         #if(blob[5]==sensor.width/2) and (blob[6]==sensor.height/2):
      while(True):
          clock.tick()
          img = sensor.snapshot().lens_corr(strength = 1.8, zoom = 1.0)#摄像头畸变矫正
          blobs = img.find_blobs([thresholds[2]])
          #print(img.width()/2,img.height()/2)
      
          if blobs:
              max_blob=find_max(blobs)
              #img.draw_rectangle(max_blob.rect())
              img.draw_cross(max_blob.cx(),max_blob.cy())
              print("you're on camera!")
              #sensor.snapshot().save("LHP.jpg")
              #x="[%u]"%(max_blob.cx())
              #y="[%u]"%(max_blob.cy())
              x=hex(max_blob.cx())
              y=hex(max_blob.cy())
              print(x,y)
              x_h=(x>>8)&0xff
              #x_l=hex(x&0xff)
              #y_h=((y>>8)&0x0ff)
              #y_l=(y&0xff)
              #rc=x_h+x_l+y_h+y_l
              #data=bytearray([0x02,x_h,x_l,y_h,y_l,0x00,rc])
             #print('you send:',data)
      

      报错就和上面一样,我就想把坐标数据拆成十六进制的打包发送



    • hex函数不是你想的那样。他返回的是字符串,用来给人类看的。

      >>> hex(100)
      '0x64'
      

      (max_blob.cx()>>8)&0xFF
      就行



    • This post is deleted!