• 安装星瞳实验室APP,快速收到回复。扫描二维码或者点击 https://singtown.com/app/
  • 必看:玩转星瞳论坛了解一下图片上传,代码格式等问题。
  • 一个提问,一个帖子,标题为问题的介绍
  • 请贴出具体的代码,与报错提示。
  • 代码一定要让别人可以运行的文本,不要贴图片
  • 麻烦问一下这个怎么解决object with buffer protocol required



    • import sensor, image, time
      from pyb import UART
      #----------------init-------------------------------#
      sensor.reset() # 初始化摄像头
      sensor.set_pixformat(sensor.RGB565) # 格式为 RGB565.
      sensor.set_framesize(sensor.QVGA)
      sensor.skip_frames(10) # 跳过10帧,使新设置生效
      sensor.set_auto_whitebal(False)               # Create a clock object to track the FPS
      uart = UART(3,19200)
      
      
      
      #------------------site----------------------#
      ROI=[None,(80,30,15,15),(160,30,15,15),(240,30,15,15)]
      
      
      
      while(True):
          message_int = 0
          img = sensor.snapshot()         # Take a picture and return the image.
          statistics1=img.get_statistics(roi=ROI[1])
          color_l1=statistics1.l_mode()
          color_a1=statistics1.a_mode()
          color_b1=statistics1.b_mode()
          print(color_l1,color_a1,color_b1)  #debug
          
      
          if color_l1 <= 80:
              message_1 = 1
          else:
              message_1 = 0
          img.draw_rectangle(ROI[1])
      
      
      
          statistics2=img.get_statistics(roi=ROI[2])
          color_l2=statistics2.l_mode()
          color_a2=statistics2.a_mode()
          color_b2=statistics2.b_mode()
          print(color_l2,color_a2,color_b2)
          if color_l1 <= 80:
              message_2 = 1
          else:
              message_2 = 0
          img.draw_rectangle(ROI[2])
      
      
      
          statistics3=img.get_statistics(roi=ROI[3])
          color_l3=statistics3.l_mode()
          color_a3=statistics3.a_mode()
          color_b3=statistics3.b_mode()
          print(color_l3,color_a3,color_b3)
          if color_l3 <= 80:
              message_3 = 1
          else:
              message_3 = 0
          img.draw_rectangle(ROI[3])
      
      
          send = 1*100000+message_1*10000+2*1000+message_2*100+3*10+message_3 #发送我
          uart.write(send)
          time.sleep(500)