logo

使用MV4 H7 PLUS,提示:RuntimeError:Capturn Failed:-4,需要重新连接,怎么解决?

2020-09-19 23:48
1
ckor
import sensor, image, time, math,lcd,pyb
from pyb import UART
import json
import ustruct

sensor.reset()
sensor.set_framesize(sensor.QVGA)
sensor.set_pixformat(sensor.RGB565)
sensor.skip_frames(time = 2000)
lcd.init()
clock = time.clock()
uart = UART(3,115200)   #定义串口3变量    P4 TX<-->PA10  P5 RX<-->PA9
uart.init(115200, bits=8, parity=None, stop=1) # init with given parameters

find_threshold = (35, 9, -5, 6, 28, 13)

def find_max(blobs): 
    blobs.sort(key=lambda x:x.pixels(),reverse=True);
    max_blob={}            
    length=len(blobs)
    if length>0:
        max_blob=blobs[0]
    return max_blob

def sending_data(cx_max,cy_max):
    global uart;
    #frame=[0x2C,18,cx%0xff,int(cx/0xff),cy%0xff,int(cy/0xff),0x5B];
    #data = bytearray(frame)
    data = ustruct.pack("<bbhhb", 
                   0x2C,                       
                   0x12,                      
                   int(cx_max), # up sample by 4    
                   int(cy_max), # up sample by 4    
                   0x5B);
    uart.write(data); 

while(True):
    clock.tick()
    lcd.display(sensor.snapshot()) 
    img = sensor.snapshot()#.lens_corr(1.3);
    #img.binary([binary_threshold], invert = 1)
    blobs = img.find_blobs([find_threshold],area_threshold=100,pixel_threshold=8000)


    if blobs:
        max_blob=find_max(blobs)
        img.draw_rectangle(max_blob.rect(),color=(0,0,255))
        img.draw_cross(max_blob.cx(), max_blob.cy(),color=(0,0,255))
        img.draw_cross(160, 120,color=(255,0,0)) # 在中心点画标记
        img.draw_line((160,120,max_blob.cx(),max_blob.cy()), color=(0,0,255));
        img.draw_circle(160, 120, 10, color = (255,0,0), thickness = 1, fill = False)

        xywh=max_blob.rect()
        print("xywh=",xywh)
        print("中心x坐标:",max_blob.cx(),"中心y坐标:",max_blob.cy())
        print("L =", 160 - max_blob.cx())
        print("H =", 120 - max_blob.cy())
        print("像素数量:",max_blob.pixels()) 
        print("\r\n")
        print(clock.fps())
2020-09-20 10:53
1
ckor
528cef9c-1785-4307-b9df-8800adb31109.png
2020-09-20 10:59
1
ckor

但是我用其他的openmv却能正常运行;

报错的是:openmv4 cam h7 plus

正常的是:openmv4 cam h7

2020-09-20 20:13
I
网红小智智 星瞳科技

你有没有把PLUS的摄像头模组的两个螺丝拧紧?我感觉像是摄像头模组没有安装紧固。