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



    • 0_1626943017722_屏幕截图 2021-07-22 155752.png 第一个openmv

      !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
       while(True):#抓  6无 1234垃圾分类  7  8起  dat接收的数据 datat发送的数据
                          if uart.any():
                              dat = uart.readline().decode().strip()
                          if int(dat)==5:
                              break
                          elif int(dat)==1 or int(dat)==2 or int(dat)==3 or int(dat)==4:
                              while(True):        #寻找终点
      
      
      
      第二个openmv!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
      # Edge Impulse - OpenMV Image Classification Example
      
      import sensor, image, time, os, tf
      import pwm
      from pyb import UART
      from pyb import Servo
      from pyb import LED
      
      pan_servo=Servo(1)
      tilt_servo=Servo(2)
      pan_servo.calibration(500,2500,500)
      tilt_servo.calibration(500,2500,500)
      
      sensor.reset()                         # Reset and initialize the sensor.
      sensor.set_pixformat(sensor.RGB565)    # Set pixel format to RGB565 (or GRAYSCALE)
      sensor.set_framesize(sensor.QVGA)      # Set frame size to QVGA (320x240)
      sensor.set_windowing((240, 240))       # Set 240x240 window.
      sensor.skip_frames(time=2000)          # Let the camera adjust.
      uart = UART(3, 115200)
      dat=0
      what=0
      number=0
      LED(1).on()
      LED(2).on()
      LED(3).on()
      net = "trained.tflite"
      labels = [line.rstrip('\n') for line in open("labels.txt")]
      
      clock = time.clock()
      while(True):
          clock.tick()
          img = sensor.snapshot()
          if uart.any():
              dat = uart.readline().decode().strip()
          if int(dat)==6:
              pan_servo.angle(85,300)
              tilt_servo.angle(120,300)
              time.sleep(1.5)
              pwm.pw(3)#爪子
              time.sleep(1.5)
              dat=0
          if int(dat)==5:
              while(True):
                  clock.tick()
                  img = sensor.snapshot()
                  for obj in tf.classify(net, img, min_scale=1.0, scale_mul=0.8, x_overlap=0.5, y_overlap=0.5):
                      #print("**********\nPredictions at [x=%d,y=%d,w=%d,h=%d]" % obj.rect())
                      img.draw_rectangle(obj.rect())
                      if obj.output()[0]>=0.7 :  #电池
                          if what!=3:
                              number=0
                          else :
                              number=number+1
                          what=3 #红色
                      elif obj.output()[1]>=0.7 : #瓶子
                          if what!=1:
                              number=0
                          else :
                              number=number+1
                          what=1 #蓝色
                      elif obj.output()[2]>=0.7 : #杯子
                          if what!=4:
                              number=0
                          else :
                              number=number+1
                          what=4 #黑灰色
                      elif obj.output()[3]>=0.7 : #没有
                          if what!=5:
                              number=0
                          else :
                              number=number+1
                          what=5 #没有识别到东西
                      elif obj.output()[4]>=0.7 : #橘子
                          if what!=2:
                              number=0
                          else :
                              number=number+1
                          what=2 #绿色
                      elif obj.output()[5]>=0.7 : #纸团
                          if what!=1:
                              number=0
                          else :
                              number=number+1
                          what=1 #蓝色
                  if number>=2:
                      number=0
                      break
                      #predictions_list = list(zip(labels, obj.output()))
                      '''
                      for i in range(len(predictions_list)):
                          print("%s = %f" % (predictions_list[i][0], predictions_list[i][1]))
                          print(obj.output()[1])
                      '''
              if what!=0:
                  dat=10
                  pan_servo.angle(69,500)
                  tilt_servo.angle(148,500)
                  time.sleep(0.7)
                  pwm.pw(9)#爪子
                  time.sleep(1.5)
                  pan_servo.angle(160,300)
                  tilt_servo.angle(100,300)
          if int(dat)==10:
              pan_servo.angle(160,300)
              tilt_servo.angle(120,300)
              pwm.pw(9)#爪子
              uart.write(str(what)+'\r\n')
      
          else:
              pwm.pw(3)#爪子
              time.sleep(1.5)
              pan_servo.angle(148,300)
              tilt_servo.angle(80)
      
          print(dat)
          print(what)
      


    • 你不用int函数,先把里面的数据打印出来,你看看是啥。肯定不是10进制字符串。