logo

例程上改的(算是大改)报错AttributeError怎么解决

2019-07-09 20:33
1
stzo

AttributeError:'module' object has no attribute 'draw_circle'

# 识别自己在直线例程

#

# 这个例子展示了如何在图像中查找线条。对于在图像中找到的每个线对象,

# 都会返回一个包含线条旋转的线对象。

# 注意:线条检测是通过使用霍夫变换完成的:

# http://en.wikipedia.org/wiki/Hough_transform

# 请阅读以上关于“theta”和“rho”的更多信息。

# find_lines()找到无限长度的线。使用find_line_segments()

# 来查找非无限线。

enable_lens_corr = False # turn on for straighter lines...

import sensor, image, time

lim1=[1,2,3,4]

lim2=[1,2,3,4]

sum=0

flag=0

i=0

li=(0,1,2,3,)

x=0

y=0

zan=()

sensor.reset()

sensor.set_pixformat(sensor.RGB565) # grayscale is faster

sensor.set_framesize(sensor.QQVGA)

sensor.skip_frames(time = 2000)

clock = time.clock()

# 所有的线对象都有一个`theta()`方法来获取它们的旋转角度。

# 您可以根据旋转角度来过滤线条。

min_degree = 0

max_degree = 179

# 所有线段都有 `x1()`, `y1()`, `x2()`, and `y2()` 方法来获得他们的终点

# 一个 `line()` 方法来获得所有上述的四个元组值,可用于 `draw_line()`.

while(True):

clock.tick()

img = sensor.snapshot()

if enable_lens_corr: img.lens_corr(1.8) # for 2.8mm lens...

# `threshold` controls how many lines in the image are found. Only lines with

# edge difference magnitude sums greater than `threshold` are detected...

# `threshold`控制从霍夫变换中监测到的直线。只返回大于或等于阈值的

# 直线。应用程序的阈值正确值取决于图像。注意:一条直线的大小是组成

# 直线所有索贝尔滤波像素大小的总和。

# `theta_margin`和`rho_margin`控件合并相似的直线。如果两直线的

# theta和ρ值差异小于边际,则它们合并。

sum=0

flag=0;

for l in img.find_lines(threshold = 3000, y_stride=2,y_stride=2,theta_margin = 25, rho_margin = 25):

if (min_degree <= l.theta()) and (l.theta() <= max_degree):

img.draw_line(l.line(), color = (255, 0, 0))

# print(l)

if flag==0:

sum=l.theta()

flag=1

lim1=l

y= lim1[1]

else :

sum-=l.theta()

lim2=l

x= lim2[0]

if sum<110 and sum>70:

for i in range(0,3):

print(lim1[i],lim2[i])

#x=0

#y=0

if x!=0 or y!=0:

image.draw_cross(x=100, y=100, size=5, color=White)

#image.draw_circle(x=100,y=100, radius=100,color=(0,255,0))

print("FPS %f" % clock.fps())

print(sum)

# About negative rho values:

#

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

3e2e4a97-84b6-4d0e-bbca-2799a00a4ad0.PNG
64c31914-59e2-4739-a51f-c29f22bfb8c8.PNG

求大佬指点迷津

2019-07-09 21:25
I
网红小智智 星瞳科技

是img.draw_cross,不是image.draw_cross

2019-07-10 09:14
1
stzo

改完后出现了新错误

316c726f-d9c2-4272-b932-1e966ec43098.PNG
2019-07-10 17:45
I
网红小智智 星瞳科技

http://book.openmv.cc/example/03-Drawing/rectangle-drawing.html

看例子。