logo

脱机与连电脑得到的值不同

2022-11-20 18:48
K
bw4c

为什么使用openmv求寻迹偏差值的时候脱机运行和连电脑时得到的值不同,连电脑的时候很完美,脱机错误很大

2022-11-22 17:43
I
网红小智智 星瞳科技

如果涉及代码,需要报错提示与全部代码文本,请注意不要贴代码图片

2022-12-03 16:05
K
bw4c
import sensor, image, time
from pyb import UART,LED
import json
write_threshold=(0, 19, 28, -33, 122, -2)
sensor.reset()
sensor.set_pixformat(sensor.RGB565)
sensor.set_framesize(sensor.VGA)
sensor.set_windowing((504,480))
sensor.set_vflip(True)
sensor.set_hmirror(True)
sensor.skip_frames(time = 2000)
clock = time.clock()
quyu=[278,278,278,278,278,278,278,278,278,278]
LED(1).on()
LED(2).on()
LED(3).on()
lx=0
x=0
k=0
t=0
m=0
last=0
l=0
uart=UART(3,115200)
def find_max(blobs):
 max_size=0
 for blob in blobs:
  if blob.pixels()>max_size:
   max_blob=blob
   max_size = blob.pixels()
  return max_blob
while(True):
  clock.tick()
  img=sensor.snapshot ()
  for n in range(0,10):
   blobs = img.find_blobs([write_threshold],roi=[193,480-48*(n+1),172,48],x_stride=20,y_stride=20,x_stride=400)
   img.draw_rectangle((193,480-48*(n+1),172,48),color=(231,188,105))
   max_blob=find_max(blobs)
   if blobs:
    for blob in blobs:
     img.draw_cross(max_blob.cx(), max_blob.cy())
     quyu[n]=max_blob.cx()
     m+=1
     if m>=2:
      k+=(max_blob.cx()-lx)/48
     lx=max_blob.cx()
   x=x+quyu[n]
  blobs = img.find_blobs([write_threshold],roi=[53,80,100,80])
  max_blob=find_max(blobs)
  if blobs:
   for blob in blobs:
    img.draw_cross(max_blob.cx(), max_blob.cy())
    t+=max_blob.cx()
  blobs = img.find_blobs([write_threshold],roi=[53,240,452,80])
  max_blob=find_max(blobs)
  if blobs:
   for blob in blobs:
    l=max_blob.w()
  if m!=0:
   last=x/10+k*30/m
  if l>200:
   t=666
  if k>1:
   k=1
  if k<-1:
   k=-1
  print(last-278,t)
  output_str="%.3d, %.3d" % (last,t)
  lx=0
  x=0
  k=0
  t=0
  m=0
  uart.write('\n'+output_str+'\r')
  img.draw_rectangle((53,80,100,80),color=(231,188,105))
  img.draw_rectangle((53,240,452,80), color=(231,188,105))
2022-12-03 16:15
K
bw4c

@kidswong999

import sensor, image, time
from pyb import UART,LED
import json
write_threshold=(0, 19, 28, -33, 122, -2)
sensor.reset()
sensor.set_pixformat(sensor.RGB565)
sensor.set_framesize(sensor.VGA)
sensor.set_windowing((504,480))
sensor.set_vflip(True)
sensor.set_hmirror(True)
sensor.skip_frames(time = 2000)
clock = time.clock()
quyu=[278,278,278,278,278,278,278,278,278,278]
LED(1).on()
LED(2).on()
LED(3).on()
lx=0
x=0
k=0
t=0
m=0
last=0
l=0
uart=UART(3,115200)
def find_max(blobs):
 max_size=0
 for blob in blobs:
  if blob.pixels()>max_size:
   max_blob=blob
   max_size = blob.pixels()
  return max_blob
while(True):
  clock.tick()
  img=sensor.snapshot ()
  for n in range(0,10):
   blobs = img.find_blobs([write_threshold],roi=[193,480-48*(n+1),172,48],x_stride=20,y_stride=20,x_stride=400)
   img.draw_rectangle((193,480-48*(n+1),172,48),color=(231,188,105))
   max_blob=find_max(blobs)
   if blobs:
    for blob in blobs:
     img.draw_cross(max_blob.cx(), max_blob.cy())
     quyu[n]=max_blob.cx()
     m+=1
     if m>=2:
      k+=(max_blob.cx()-lx)/48
     lx=max_blob.cx()
   x=x+quyu[n]
  blobs = img.find_blobs([write_threshold],roi=[53,80,100,80])
  max_blob=find_max(blobs)
  if blobs:
   for blob in blobs:
    img.draw_cross(max_blob.cx(), max_blob.cy())
    t+=max_blob.cx()
  blobs = img.find_blobs([write_threshold],roi=[53,240,452,80])
  max_blob=find_max(blobs)
  if blobs:
   for blob in blobs:
    l=max_blob.w()
  if m!=0:
   last=x/10+k*30/m
  if l>200:
   t=666
  if k>1:
   k=1
  if k<-1:
   k=-1
  print(last-278,t)
  output_str="%.3d, %.3d" % (last,t)
  lx=0
  x=0
  k=0
  t=0
  m=0
  uart.write('\n'+output_str+'\r')
  img.draw_rectangle((53,80,100,80),color=(231,188,105))
  img.draw_rectangle((53,240,452,80), color=(231,188,105))
2022-12-06 18:50
I
网红小智智 星瞳科技

代码没看出来有什么问题,你是不是环境光源不一致?