星瞳实验室APP,快速收到回复
  • 我们只解决官方正版的OpenMV的问题(STM32),其他的分支有很多兼容问题,我们无法解决。
  • 发帖子之前,请确认看过所有的视频教程,https://singtown.com/learn/ 和所有的上手教程http://book.openmv.cc/
  • 每一个新的提问,单独发一个新帖子
  • 帖子需要目的,你要做什么?
  • 如果涉及代码,需要报错提示全部代码文本,请注意不要贴代码图片
  • 必看:玩转星瞳论坛了解一下图片上传,代码格式等问题。
  • 运行了几秒下面的程序,就自动停止了



    • # Untitled - By: HP - 周五 6月 7 2019
      
      import sensor,time,pyb,math,image
      import json, struct,ustruct
      from pyb import Pin,Timer,LED
      
      x_error =0
      y_error =0
      x_Sign = 0
      y_Sign = 0
      error_flag = 0
      car_lost = 1
      
      
      
      def uart_pack(args):      # 打包发送 uart_pack()  args 是以message_id开头的有效数据
      
          temp = ustruct.pack('<bi{}s'.format(len(args)),85, len(args),args)
          temp += "\x00" * (4 + (len(temp) % 4))
          return temp
      
      
      def find_max(blobs):    #寻找最大色块函数定义
          max_pixels=0         #通过像素比较
          for blob in blobs:     #blob[0,1,2,3,4]=x,y,w,h,pixels (int)
               if blob[4]>max_pixels:
                   max_blob=blob
                   max_pixels=blob[4]
          return max_blob
      
      sensor.reset()
      sensor.set_pixformat(sensor.RGB565)
      sensor.set_framesize(sensor.QQVGA) # we run out of memory if the resolution is much bigger...  图像像素大小QQVGA是160✖120
      sensor.skip_frames(30)
      sensor.set_auto_gain(False)  # must turn this off to prevent image washout...
      sensor.set_auto_whitebal(False)  # must turn this off to prevent image washout...
      sensor.set_auto_exposure(True)
      clock = time.clock()
      
      
      black = (25, 95, 77, 22, -16, 63)
      
      
      
      text = "Hello!\n"
      data = ustruct.pack("<bi%ds" % len(text), 85, len(text), text) # 85 is a sync char.
      data += "\x00" * (4 + (len(data) % 4))
      
      
      spi = pyb.SPI(2, pyb.SPI.SLAVE, polarity=0,phase=0)
      
      
      
      def callback(line):
          spi.send(data, timeout=1000)
          #打印线程信息
          extint.disable()
      
      SPI_SS = pyb.Pin("P7", pyb.Pin.IN, pull=pyb.Pin.PULL_DOWN)
      # 上升沿进行中断
      extint = pyb.ExtInt(SPI_SS, pyb.ExtInt.IRQ_RISING,pyb.Pin.PULL_DOWN,callback)
      
      
      while(True):
      
         clock.tick()
      
         img=sensor.snapshot()
      
         blobs = img.find_blobs([black],area_threshold=50, pixels_threshold=50)
      
         if blobs:
            max_blob=find_max(blobs)
            img.draw_rectangle(max_blob.rect())
            img.draw_cross(max_blob.cx(),max_blob.cy())
            x_error = int(max_blob.cx()-img.width()/2)
            y_error = int(img.height()/2-max_blob.cy())
            if x_error >= 0:
               x_Sign = 0
            if x_error <= 0:
               x_Sign = 1
      
            if y_error >= 0:
               y_Sign = 0
            if y_error <= 0:
               y_Sign = 1
      
            x_abs = abs(x_error)
            y_abs = abs(y_error)
      
      
            message_id = 1           # message_id
            lenth = 5                 #除了头尾之外的,不包括他自己 的和message_id的数据
            error_flag = 0
      
            args_used ="%d %d %d %d %d %d %d" %(lenth, message_id, error_flag, x_abs, y_abs, x_Sign, y_Sign)
            #args_used = (lenth, message_id, error_flag, x_abs, y_abs, x_Sign, y_Sign)
            out_str = json.dumps([0x55,args_used,0xAA])
      
            #print('you send:', out_str)
            data = uart_pack(args_used)
            print('you send1')
            extint.enable()
      
         else:
            error_flag = car_lost
            x_abs = 0
            y_abs = 0
      
            message_id = 1
            lenth = 1
      
            args_used = "%d %d %d" % (lenth, message_id, error_flag)
            #args_used =  (lenth, message_id, error_flag)
            out_str = json.dumps([0x55, args_used,0xAA])
      
            #print('you send:', out_str)
            data = uart_pack(args_used)
            print('you send2')
            extint.enable()
      
      
      
      


    • 我使用OpenMV3和OpenMV4都没有出现你的问题。

      建议你换一个电脑USB口,可能是USB口松了,
      如果还有问题,建议你升级到最新的固件,
      如果还有问题,建议你运行hello world,
      如果还有问题,联系售后维修。



    • 已经解决了,谢谢~