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



    • #THRESHOLD =(0, 23, -12, 5, -5, 13)
      THRESHOLD_day=(0, 30, -47, 20, -28, 19)
      import sensor, image, time,math,pyb
      from pyb import UART,Pin,Timer
      from pyb import LED
      from pid import PID
      output_str=''
      uart = UART(3,9600)
      sensor.reset()
      sensor.set_vflip(True)
      sensor.set_hmirror(True)
      sensor.set_pixformat(sensor.RGB565)
      sensor.set_framesize(sensor.QQVGA)
      sensor.set_windowing((0,60,120,60))
      sensor.skip_frames(time = 2000)
      clock = time.clock()
      LED(1).on()
      LED(2).on()
      LED(3).on()
      roi_X=[30,0,30,30]
      roi_stra=[50,0,30,30]
      rho_pid = PID(p=0.7, i=0)
      theta_pid = PID(p=0.3, i=0.5,d=0.1)
      while(True):
           img = sensor.snapshot()
           img.draw_rectangle(roi_X, color = (255, 0, 0), thickness = 2, fill = False)
           img.draw_rectangle(roi_stra, color = (255, 0, 0), thickness = 2, fill = False)
           blobs = img.find_blobs([THRESHOLD_day], roi=roi_X,x_stride=1, y_stride=1,pixels_threshold=10)
           for blob in blobs:
                  img.draw_rectangle(blob.rect())
                  img.draw_cross(blob.cx(), blob.cy())
                  if blob:
                      blobsss = img.find_blobs([THRESHOLD_day],roi=roi_stra,x_stride=1, y_stride=1,pixels_threshold=10)
                      for blob in blobs:
                              img.draw_rectangle(blob.rect())
                              img.draw_cross(blob.cx(), blob.cy())
                              if blob:
                                  print('go!')
                                  output_str =bytearray([0x2C,0x12,128,128,0x5B])
                                  #output_str='&0%d%d*' % (300, 300)
                                  uart.write(output_str)
                                  print(output_str)
                                  pyb.delay(200)
           img = sensor.snapshot().binary([THRESHOLD_day])
           line1 = img.get_regression([(100,100)], robust = True)
           if (line1):
               rho_err = abs(line1.rho())-img.width()/2
               if line1.theta()>90:
                   theta_err = line1.theta()-180
               else:
                   theta_err = line1.theta()
               img.draw_line(line1.line(), color = 127)
               if line1.magnitude()>8:
                  rho_output = rho_pid.get_pid(rho_err,1)
                  theta_output = theta_pid.get_pid(theta_err,1)
                  output = rho_output+theta_output
                  output1=128-output
                  output2=128+output
                  int(output1)
                  int(output2)
                  output_str =bytearray([0x2C,0x12,output1,output2,0x5B])
                  #output_str='&0%d%d*' % (300-output, 300+output)
                  uart.write(output_str)
                  print(output_str)
               else:
                  output_str =bytearray([0x2C,0x12,0,128,0x5B])
                  #output_str='&0000300*'
                  uart.write(output_str)  
                  print(output_str)
                  pass
      
      

      0_1674529020783_458688f8-f7dd-4668-be43-eb155605bb39-image.png