• OpenMV VSCode 扩展发布了,在插件市场直接搜索OpenMV就可以安装
  • 如果有产品硬件故障问题,比如无法开机,论坛很难解决。可以直接找售后维修
  • 发帖子之前,请确认看过所有的视频教程,https://singtown.com/learn/ 和所有的上手教程http://book.openmv.cc/
  • 每一个新的提问,单独发一个新帖子
  • 帖子需要目的,你要做什么?
  • 如果涉及代码,需要报错提示全部代码文本,请注意不要贴代码图片
  • 必看:玩转星瞳论坛了解一下图片上传,代码格式等问题。
  • 大佬请问为什么二值化之后找线段在正对矩形的时候找的到 歪了就不行



    • import pyb
      from pyb import LED #导入LED
      from machine import UART
      import sensor, image, time, math, os, tf
      uart = UART(1, baudrate=115200)
      sensor.reset()
      sensor.set_pixformat(sensor.GRAYSCALE)
      sensor.set_framesize(sensor.QVGA)
      sensor.set_auto_exposure(False, 1000)
      sensor.__write_reg(0x03,0x04)
      sensor.__write_reg(0x04,0x05)
      sensor.__write_reg(0xB2,0x40)
      sensor.__write_reg(0xB3,0x00)
      sensor.__write_reg(0xB4,0x40)
      sensor.__write_reg(0xB5,0x00)
      sensor.__write_reg(0x03,0x03)
      sensor.__write_reg(0x5B,0x60)
      sensor.__write_reg(0x03,0x08)
      sensor.set_auto_whitebal(False, (0x80,135,0x80))
      sensor.set_brightness(500)
      sensor.set_auto_gain(False)
      sensor.skip_frames(time = 2000)
      clock = time.clock()
      Large_area=[0,0,320,180]
      min_degree = 45
      max_degree = 135
      i=0
      yzb=[0,0]
      he=[]
      ypj=[]
      yjd=[]
      lbypj=[]
      lbyjd=[]
      suibian=[]
      red_threshold = (0,150)
      def get_pj(point):
          point_1 = point[0]
          point_2 = point[1]
          he = int((point_1+ point_2)/2)
          return he
      while(True):
          img = sensor.snapshot()
          img.binary([red_threshold])
          #img.draw_rectangle(Large_area, color = (255, 0, 0))
          for l in img.find_line_segments(roi=Large_area,merge_distance = 10, max_theta_diff = 10):
                  #if (min_degree <= l.theta()) and (l.theta() <= max_degree):
                      img.draw_line(l.line(), color = (255, 0, 0))
                      #print(l.line())
                      yzb = [l.y1(),l.y2()]
                      #yjd= [l.theta()]
                      ypj = get_pj(yzb)
                      if(i<5):
                          lbypj.append(ypj)
                          #lbyjd.append(yjd)
                          i=i+1
                      if (i==5):
                          #suibian=lbypj
                          ypjmax=max(lbypj)
                          juliy=240-ypjmax
                          img.draw_line([0,ypjmax,320,ypjmax], color = (255, 0, 0))
                          #zuidixian=suibian.index(max(suibian))
                          #outjd =lbyjd[zuidixian]
                          print(juliy)
                          lbypj=[]
                          #lbyjd=[]
                          i=0
      
      

      1_1650804075413_QQ图片20220424204052.png

      0_1650804075411_QQ图片20220424204044.png







    • 你的这个代码,我没办法拍出黑色的矩形。你改成正常的二值化的代码,我再测试。