logo

RuntimeError Capture Failed: -2 问题怎么解决?

2021-06-07 11:28
0
w236
85e99e51-f282-4df7-9b5a-0c2ade6d97ff.png
bd2d632c-f0a7-4091-bea6-6feafbd107b0.png

计算出roi后,设置window后拍摄图片失败,谢谢

关键代码如下:

--------------------------------------

import sensor, image, time


# Set the basic parameters of the image sensor.
sensor.reset() # 初始化摄像头
sensor.set_pixformat(sensor.GRAYSCALE)          # 格式为 灰度图.
sensor.set_framesize(sensor.VGA)                # 使用 QVGA 视野广,1280*960。
sensor.set_auto_gain(False)                     # 关闭自动自动增益。默认开启的,在颜色识别中,一定要关闭白平衡。
sensor.set_auto_whitebal(False)                 # 关闭白平衡。白平衡是默认开启的,在颜色识别中,一定要关闭白平衡。
sensor.set_auto_exposure(False, 10000)           # 关闭自动曝光,并将曝光时间设定为5000 us。
sensor.skip_frames(time = 1000)                 # 跳过2000ms,使新设置生效。

# Set the RoI area.
tracking_threshold      = (232, 255)            # 设定光源图像的灰度阈值。
img                     = sensor.snapshot()     # 从感光芯片获得一张图像。
blobs                   = img.find_blobs([tracking_threshold])      # 检测图片中的疑似光源图像RoIs。


# 如果找到了疑似光源图像RoIs
if blobs:
    print(str(len(blobs)) + " blocks are found!")
    # 迭代找到的疑似光源图像RoIs的区域
    for b in blobs:
        # Draw a rect around the blob.
        print("The found RoI is: " + str(b[0:4]))
        img.draw_rectangle(b[0:4])              # 用矩形标记出目标颜色区域
else:
    print("No blocks are found!\n")


roi     = (b[0], b[1], b[2], b[3])              # 计算光源像点的RoI
print(roi)

sensor.reset() # 初始化摄像头
sensor.set_pixformat(sensor.GRAYSCALE)          # 格式为 灰度图.
sensor.set_framesize(sensor.VGA)                # 使用 QVGA 视野广,1280*960。
sensor.set_windowing(roi)                       # 设置相机的RoI
sensor.skip_frames(time = 1000)                 # 跳过1000ms,使新设置生效。


img                     = sensor.snapshot()
rows                    = img.width()
columns                 = img.height()
print(rows, columns)


clock = time.clock()

while(True):
    clock.tick()
    img = sensor.snapshot()
    print(clock.fps())
2021-06-07 19:25
I
网红小智智 星瞳科技

https://github.com/openmv/openmv/issues/1350

提交了issue,会尽快解决。

2021-06-09 17:49
I
网红小智智 星瞳科技

当图像大小不是16byte整数的时候会报错。

第31行改为:

roi = (b[0], b[1], b[2]//16*16, b[3]//16*16)

I
网红小智智 星瞳科技

PS:你的程序要多加一些判断。比如23行那里,加一个find_max,roi那里也要判断一下宽度和高度是否为0

2021-06-10 20:59
0
w236

@kidswong999

问题已解决,谢谢!