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



    • while (1):
          if uart.any():
              receive=uart.readline().decode()
              if receive=='N':                #when receive 'N',begin to find the color
                  threshold_index=0           #red for 0
                  print(receive)
                  while(True):
                      img = sensor.snapshot() # Take a picture and return the image.
      
                      blobs = img.find_blobs([thresholds[threshold_index]])
                      if blobs:
                          max_blob=find_max(blobs)
                          img.draw_rectangle(max_blob.rect())
                          img.draw_cross(max_blob.cx(), max_blob.cy())
                          aim=1                #1 find the aim,0 not find
                          a=max_blob.cx()
                          b=max_blob.cy()
      
                          #transfer the format become(x,xxx,xxx)
                          if max_blob.cx()<10:
                              a='00'+str(a)
                              if max_blob.cy()<10:
                                  b='00'+str(b)
                          elif max_blob.cy()<10:
                              b='00'+str(b)               #the case that max_blob.cx or .cy<10
      
                          elif max_blob.cx()<100:
                              a='0'+str(a)
      #                         print(a)
                              if max_blob.cy()<100:
                                  b='0'+str(b)
                          elif max_blob.cy()<100:
                              b='0'+str(b)                #the case that max_blob.cx or .cy<100
      
                          output_str="[%s,%s,%s]" % (aim,a,b)
                          print('you send:',output_str)
                          uart.write(output_str+'\r\n')      #the output foemat is (x,xxx,xxx)
                      else:
                          aim=0
                          aim="[%s]"%(aim)
                          uart.write(aim+'\r\n')
                          print('not found!')
      
                      if uart.any():
                          receiv=uart.readline().decode()
                          if receiv=='G':                  #the command is the symbol of find green
                              threshold_index=2            #green for 2
                              while(True):
                                  img = sensor.snapshot() # Take a picture and return the image.
      
                                  blobs = img.find_blobs([thresholds[threshold_index]])
                                  if blobs:
                                      max_blob=find_max(blobs)
                                      img.draw_rectangle(max_blob.rect())
                                      img.draw_cross(max_blob.cx(), max_blob.cy())
                                      aim=1                #1 find the aim,0 not find
                                      a=max_blob.cx()
                                      b=max_blob.cy()
      
                                      #transfer the format become(x,xxx,xxx)
                                      if max_blob.cx()<10:
                                          a='00'+str(a)
                                          if max_blob.cy()<10:
                                              b='00'+str(b)
                                      elif max_blob.cy()<10:
                                          b='00'+str(b)               #the case that max_blob.cx or .cy<10
      
                                      elif max_blob.cx()<100:
                                          a='0'+str(a)
                                          print(a)
                                          if max_blob.cy()<100:
                                              b='0'+str(b)
                                      elif max_blob.cy()<100:
                                          b='0'+str(b)                #the case that max_blob.cx or .cy<100
      
                                      output_str="[%s,%s,%s]" % (aim,a,b)
                                      print('send:',output_str)
                                      uart.write(output_str+'\r\n')      #the output foemat is (x,xxx,xxx)
                                  else:
                                      aim=0
                                      aim="[%s]"%(aim)
                                      uart.write(aim+'\r\n')
                                      print('not found!')
      


    • 你的 if receive=='N'里面又有一个死循环。