logo

像素块数量提取的相关问题

2019-07-04 11:12
D
fuzs
0467d6bf-8054-4ec4-a235-6b5fcefb87e3.png

如图所示,上面的部分为视野里有捕捉对象返回的数据,下面的部分为视野里没有捕捉对象返回的数据

如何设置才能使没有捕捉对象也能返回一个值(比如说返回0)

2019-07-04 16:06
I
网红小智智 星瞳科技

请提供你的代码。请注意不要贴代码图片

2019-07-04 22:36
D
fuzs

# Single Color RGB565 Blob Tracking Example

#

# This example shows off single color RGB565 tracking using the OpenMV Cam.

import sensor, image, time, math, lcd

from pyb import UART

# Color Tracking Thresholds (L Min, L Max, A Min, A Max, B Min, B Max)

# The below thresholds track in general red/green/blue things. You may wish to tune them...

thresholds = (0, 100, -128, -7, -9, 127), # generic_red_thresholds

sensor.reset()

sensor.set_pixformat(sensor.RGB565)

sensor.set_framesize(sensor.QVGA) # 320*240

sensor.skip_frames(time = 2000)

sensor.set_auto_gain(False) # must be turned off for color tracking

sensor.set_auto_whitebal(False) # must be turned off for color tracking

clock = time.clock()

lcd.init()

uart = UART(3, 9600, timeout_char=1000) # i使用给定波特率初始化

uart.init(9600, bits=8, parity=None, stop=0, timeout_char=1000) # 使用给定参数初始化

# Only blobs that with more pixels than "pixel_threshold" and more area than "area_threshold" are

# returned by "find_blobs" below. Change "pixels_threshold" and "area_threshold" if you change the

# camera resolution. "merge=True" merges all overlapping blobs in the image.

while(True):

clock.tick()

img = sensor.snapshot()

for blob in img.find_blobs([thresholds[0]], pixels_threshold=3000, area_threshold=3000, merge=True):

img.draw_rectangle(blob.rect())

img.draw_cross(blob.cx(), blob.cy())

a = 76800

b = blob.pixels()

c = b/a

d = int(255-255*c)

img.draw_string(100,150,'b='+str(b),color=(0,0,0))

img.draw_string(100,170,'c='+str(c),color=(0,0,0))

lcd.display(img)

uart.writechar(d) # write 1 character 写入一个字符

#time.sleep(500)

print(a, b, c, d)

print(clock.fps())

2019-07-05 13:53
I
网红小智智 星瞳科技
数据=0
色块们 = img.find_blobs()
for 色块 in 色块们:
    数据=blob.pixels()
print(数据)
2019-07-05 14:40
D
fuzs

@kidswong999 不好意思 再请问一下 这个“色块”用什么代码指代呢?直接就是image.blob?

2019-07-05 14:59
D
fuzs
9ed8c4fd-a8fc-476d-a73d-5091bf4f5dbe.png

调试过程中出现了该问题 请问是调用有问题吗? 该如何解决呢?

2019-07-05 15:53
I
网红小智智 星瞳科技

问题:find_blobs里面没有阈值参数。

解决办法:填入阈值参数

2019-07-05 21:11
D
fuzs

@kidswong999

已解决 十分感谢:folded_hands: :folded_hands_light_skin_tone: :folded_hands_medium-light_skin_tone: