logo

识别黑色的阈值问题

2018-05-29 17:50
W
骄傲女王

识别黑色,设置阈值,是使用black_threshold =(100,59,33,-100,-128,30),还是GRAYSCALE_THRESHOLD = [(0, 64)],如果用灰度图的话,就红色也会当成黑色识别,这个问题怎么解决。同时,如何在不同颜色的干扰下识别指定宽度的黑色直线,如0.5cm的黑色直线

2018-05-29 18:10
I
网红小智智 星瞳科技

既然你用灰度图有问题,那就用彩色的呗。。。

直线你可以试试 http://book.openmv.cc/example/09-Feature-Detection/find-lines.html

2018-05-29 18:18
W
骄傲女王

您说的这个,我试过,不管用。只要是直线都识别,也是灰度图,分不出哪条是自己需要的,达不到效果。

彩色图又会特别乱,无法圈出正确的黑色区域

2018-05-29 18:29
I
网红小智智 星瞳科技

你需要具体说一下你要做什么,最好上张图。

2018-05-29 20:18
W
骄傲女王

我需要做的就是让openmv识别一条宽为0.5cm的黑线,然后上传数据```

请在这里粘贴代码

import sensor, image, time, pyb

from pyb import UART

import json

import math

black_threshold =(100,59,33,-100,-128,30)

#black_threshold =(100,50,97,-126,-128,93)

sensor.reset() # Initialize the camera sensor.

sensor.set_pixformat(sensor.RGB565) # use RGB565.

sensor.set_framesize(sensor.QVGA) # use QQVGA for speed.

sensor.skip_frames(10) # Let new settings take affect.

sensor.set_auto_whitebal(False) # turn this off.

clock = time.clock() # Tracks FPS.

uart = UART(3, 9600)

uart.init(9600, bits=8, parity=None, stop=1)

while(True):

clock.tick()

img = sensor.snapshot()

img.draw_cross(160,120)

blobs = img.find_blobs([black_threshold])

if blobs:

print('sum : %d'% len(blobs))

out_str = '['

for b in blobs:

img.draw_rectangle(b[0:4]) # rect

img.draw_cross(b[5], b[6]) # cx, cy

x = b[5]

y = b[6]

img.get_pixel(x,y)

out_str += '(%d,%d)' % (x,y)

out_str += ']'

print(out_str)

if x<160:

text = "right\n"

elif x>160:

text = "left\n"

else:

text = "stop\n"

for b in blobs:

img.draw_rectangle(b[0:4]) # rect

img.draw_cross(b[5], b[6]) # cx, cy

x = b[5]

y = b[6]

p1=Point(b[5],b[6])

p2=Point(160,120)

l=Getlen(p1,p2)

#获取两点之间直线的长度

print(l.getlen())

img.get_pixel(x,y)

out_str += '(%d,%d)' % (x,y)

out_str += ']'

print(out_str)

uart.write(out_str+'\r\n')

uart = UART(3, 9600)

for i in (0,360):

if x<160:

uart.write(string1+'\r\n')

elif x>160:

uart.write(string2+'\r\n')

else:

uart.write(string5+'\r\n')

for j in (0,240):

if x<120:

uart.write(string3+'\r\n')

elif x>120:

uart.write(string4+'\r\n')

else:

uart.write(string5+'\r\n')

while(True):

clock.tick()

img = sensor.snapshot()

img.draw_cross(160,120)

blobs = img.find_blobs([black_threshold])

if blobs:

print('sum : %d'% len(blobs))

out_str = '['

for b in blobs:

img.draw_rectangle(b[0:4]) # rect

img.draw_cross(b[5], b[6]) # cx, cy

x = b[5]

y = b[6]

a=b[0]+b[1]

c=b[1]+b[3]

out_str += '(%d,%d)' % (x,y)

out_str += ']'

print(out_str)

if b[2]>b[3]:

if 160<a:

uart.write(string1+'\r\n')

elif 160>a:

uart.write(string2+'\r\n')

else:

uart.write(string5+'\r\n')

else:

if 120<c:

uart.write(string4+'\r\n')

elif 120>c:

uart.write(string3+'\r\n')

else:

uart.write(string5+'\r\n')

8cf1415d-b5c1-49e8-9d10-e3a89e2949db.jpg
b819454b-2296-4a5d-8304-5c6d840bf321.jpg

这个图片是您说的那个直线识别的程序跑出来的,openmv图像上标出的直线是乱的

2018-05-30 11:37
X
Yuan

@18892337362 图片没有上传成功

2018-05-31 22:38
W
骄傲女王

@yuan 没有收到您发过来的,图片上传不成功