logo

拍摄语句后面的if与else是什么意思?

2019-08-24 15:56
X
风

# 鲁棒线性回归例程

#

# 这个例子展示了如何在OpenMV Cam上使用get_regression()方法来获得

# ROI的线性回归。 使用这种方法,你可以轻松地建立一个机器人,它可以

# 跟踪所有指向相同的总方向但实际上没有连接的线。 在线路上使用

# find_blobs(),以便更好地过滤选项和控制。

#

#我们在这个脚本中使用get_regression()的robust = True参数,该脚本使用更稳健的算法计算线性回归...但是可能慢得多。 鲁棒算法在图像上运行O(N ^ 2)时间。 所以,你需要限制像素的数量来使这个算法工作,它可能实际需要秒的时间给你一个结果...非常小心!

THRESHOLD = (0, 100) # Grayscale threshold for dark things...

BINARY_VISIBLE = True # 首先二值化,所以你可以看到什么线性回归正在

# 运行...虽然可能会降低FPS。

import sensor, image, time

sensor.reset()

sensor.set_pixformat(sensor.GRAYSCALE)

sensor.set_framesize(sensor.QQQVGA) # 80x60 (4,800 pixels) - O(N^2) max = 2,3040,000.

sensor.skip_frames(time = 2000) # WARNING: If you use QQVGA it may take seconds

clock = time.clock() # to process a frame sometimes.

while(True):

clock.tick()

img = sensor.snapshot().binary([THRESHOLD]) if BINARY_VISIBLE else sensor.snapshot()

# 返回类似于由find_lines()和find_line_segments()返回的线对象。

# 你有x1(),y1(),x2(),y2(),length(),

# theta()(以度为单位的旋转),rho()和magnitude()。

#

# magnitude() 表示线性回归的工作情况。这对于鲁棒的线性回归意味着不同

# 的东西。一般来说,值越大越好...

line = img.get_regression([(255,255) if BINARY_VISIBLE else THRESHOLD], robust = True)

if (line): img.draw_line(line.line(), color = 127)

print("FPS %f, mag = %s" % (clock.fps(), str(line.magnitude()) if (line) else "N/A"))

# About negative rho values:

#

# A [theta+0:-rho] tuple is the same as [theta+180:+rho].

a6b1f9c9-d2b8-48e6-904c-efacb42f104a.JPG

红线处的执行对前面有什么影响吗?

2019-08-26 13:18
I
网红小智智 星瞳科技

会有影响,如果BINARY_VISIBLE=True,会慢一些,但是你可以在IDE看到二值化的图像。

你看注释里面都有。