M
m2wt
@m2wt
0
声望
9
楼层
376
资料浏览
0
粉丝
0
关注
m2wt 发布的帖子
-
RE: openmv上电后芯片过热,frame buffer区域的图像会很暗,这是代码问题还是硬件出问题了?
![0_1627201332979_2.bmp](正在上传 100%) @kidswong999 ![0_1627201328481_1.bmp](正在上传 100%)
-
RE: openmv上电后芯片过热,frame buffer区域的图像会很暗,这是代码问题还是硬件出问题了?
@kidswong999 openmv4 h7 之前没有发觉 今天用的时候一直出现这个问题
-
RE: openmv上电后芯片过热,frame buffer区域的图像会很暗,这是代码问题还是硬件出问题了?
THRESHOLD = (0,100) # Grayscale threshold for dark things... (5, 70, -23, 15, -57, 0)(18, 100, 31, -24, -21, 70) import sensor, image, time, pyb from pyb import LED from pyb import UART,Timer from pyb import Pin uart = UART(3,115200)#初始化串口 波特率 115200 sensor.reset() #sensor.set_vflip(True) #sensor.set_hmirror(True) sensor.set_pixformat(sensor.RGB565) sensor.set_framesize(sensor.QVGA) # 80x60 (4,800 pixels) - O(N^2) max = 2,3040,000. sensor.set_auto_gain(False) # 在进行颜色追踪时,必须关闭 sensor.set_auto_whitebal(False) # 在进行颜色追踪时,必须关闭 sensor.skip_frames(time = 2000) # WARNING: If you use QQVGA it may take seconds clock = time.clock() # to process a frame sometimes. green_led = LED(2) blue_led = LED(3) p_out = Pin('P7', Pin.OUT_PP)#设置p_out为输出引脚 thresholds1 = [(9, 46, 127, -30, 27, 127)]#异物阈值 thresholds2 = [(0, 10, 127, -128, -128, 127)]#杆阈值 class Object(object): pixels = 0 num = 0 flag1 = 0 flag2 = 0 flag3 = 0 class receive(object): uart_buf = [] _data_len = 0 _data_cnt = 0 state = 0 R=receive() class ctrl(object): work_mode = 0x01 #工作模式.默认是点检测,可以通过串口设置成其他模式 #check_show = 1 #开显示,在线调试时可以打开,离线使用请关闭,可提高计算速度 ctr=ctrl() object = Object() #line.flag = 0 timer_update_flag=0 timer = Timer(4, freq=20) # func会自动接收timer这个对象 def func(timer): global timer_update_flag #print(timer.counter()) # 定义回调函数 timer_update_flag=1 timer.callback(func) #物块检测数据打包 def pack_object_data(): pack_data=bytearray([0xAA,0xAF,0xC0,0x00,object.flag1,object.flag2,object.flag3,0x00,0x00,object.num,0x00,0x00]) lens = len(pack_data)#数据包大小 pack_data[3] = lens-5;#有效数据个数 i = 0 sum = 0 #和校验 while i<(lens-1): sum = sum + pack_data[i] i = i+1 pack_data[lens-1] = sum; return pack_data #串口数据解析 def Receive_Anl(data_buf,num): #和校验 sum = 0 i = 0 while i<(num-1): sum = sum + data_buf[i] i = i + 1 sum = sum%256 #求余 if sum != data_buf[num-1]: return #和校验通过 #if data_buf[2]==0x01: # print("receive 1 ok!") #if data_buf[2]==0x02: # print("receive 2 ok!") if data_buf[2]==0xFC: #设置模块工作模式 ctr.work_mode = data_buf[4] #print("Set work mode success!") #串口通信协议接收 def Receive_Prepare(data): if R.state==0: if data == 0xAA:#帧头 R.state = 1 R.uart_buf.append(data) else: R.state = 0 elif R.state==1: if data == 0xAF:#帧头 R.state = 2 R.uart_buf.append(data) else: R.state = 0 elif R.state==2: if data <= 0xFF:#控制字 R.state = 3 R.uart_buf.append(data) else: R.state = 0 elif R.state==3:#数据个数 if data <= 33: R.state = 4 R.uart_buf.append(data) R._data_len = data R._data_cnt = 0 else: R.state = 0 elif R.state==4: if R._data_len > 0: R. _data_len = R._data_len - 1 R.uart_buf.append(data) if R._data_len == 0: R.state = 5 else: R.state = 0 elif R.state==5: R.state = 0 R.uart_buf.append(data) Receive_Anl(R.uart_buf,R.uart_buf[3]+5) R.uart_buf=[]#清空缓冲区,准备下次接收数据 else: R.state = 0 #读取串口缓存 def uart_read_buf(): i = 0 buf_size = uart.any() while i<buf_size: Receive_Prepare(uart.readchar()) i = i + 1 #检测函数 def check_object(img): #寻找色块 blobs = img.find_blobs(thresholds1, pixels_threshold=200, area_threshold=200, merge=True, margin=5) #for blob in blobs: if blobs: #if object.pixels<blob.pixels():#寻找最大的黑点 #object.pixels=blob.pixels() object.flag1 = 1 #img.draw_cross(blob.cx(), blob.cy(), color=127, size = 10) for blob in blobs: img.draw_rectangle(blob.rect(), color=127) blue_led.on() 1 p_out.low()#设置p_out引脚为低 else: blue_led.off() p_out.high() #object.flag = 0 #判断标志位 赋值像素点数据 #object.flag = object.ok #object.num = object.pixels #清零标志位 #object.pixels = 0 #object.ok = 0 #寻找黑杆 blobs1 = img.find_blobs(thresholds2, pixels_threshold=2000, area_threshold=200, merge=True, margin=5) if blobs1: #if object.pixels<blob.pixels():#寻找最大的黑点 #object.pixels=blob.pixels() object.flag2 = 1 #img.draw_cross(blob.cx(), blob.cy(), color=127, size = 10)- for blob1 in blobs1: img.draw_rectangle(blob1.rect()) print(blob1.pixels()) #寻找二维码 if object.flag2 == 1: img.lens_corr(1.8) # strength of 1.8 is good for the 2.8mm lens. codes = img.find_qrcodes() if codes: object.flag3 = 1 for code in codes: green_led.on() print(code) else: green_led.off() #object.flag = 0 #object.flag = object.ok #object.ok = 0 global timer_update_flag #发送数据 if timer_update_flag: uart.write(pack_object_data()) #timer_update_flag=0 while(True): clock.tick() #img = sensor.snapshot().binary([THRESHOLD]) #img = sensor.snapshot() if (ctr.work_mode&0x01)!=0: img = sensor.snapshot() check_object(img) #LED(1).on() #亮灯 #time.sleep(10) #延时150ms #LED(1).off() #time.sleep(10) #延时150ms #print(object.flag) #接收串口数据 uart_read_buf() #found_line(img) #print(clock.fps())