如图所示,当Image是灰度图的时候使用阈值二值化得到的图像只有一个图层,图像大小是正确的;但是当image为RGB的时候生成的图像就有两个图层,这导致RGB图像的二值化图像无法正常进行腐蚀和膨胀操作,求大神解答!


如果涉及代码,需要报错提示与全部代码文本,请注意不要贴代码图片
并且提供具体的错误信息。错误现象。
RGB图像代码:
import sensor, image, time
sensor.reset()
sensor.set_framesize(sensor.QVGA)
sensor.set_pixformat(sensor.RGB565)
sensor.skip_frames(time = 2000)
clock = time.clock()
# Use the Tools -> Machine Vision -> Threshold Edtor to pick better thresholds.
threshold_dark = (70, 100, -77, 76, 19, 74)
gray_threshold = (80, 255)
while(True):
clock.tick()
img = sensor.snapshot()
img.binary([threshold_dark])
# img.erode(100)
# img.dilate(5)
print(img)灰度值图像代码
# Color Binary Filter Example
#
# This script shows off the binary image filter. You may pass binary any
# number of thresholds to segment the image by.
import sensor, image, time
sensor.reset()
sensor.set_framesize(sensor.QVGA)
sensor.set_pixformat(sensor.GRAYSCALE)
sensor.skip_frames(time = 2000)
sensor.set_auto_whitebal(True) # 开启自动白平衡
clock = time.clock()
# Use the Tools -> Machine Vision -> Threshold Edtor to pick better thresholds.
threshold_dark = (70, 100, -77, 76, 19, 74)
threshold_light = (86, 100, -26, 8, -3, 45)
gray_threshold = (80, 255)
while(True):
clock.tick()
img = sensor.snapshot()
img.binary([gray_threshold])
# img.erode(100)
# img.dilate(5)
print(img)这个问题已解决。
请更新固件到最新版本。3.4.1