logo

这个代码需要如何优化才能提速?

2020-05-21 23:35
5
yzrl
# 红外RGB565跟踪示例

#

# 这个例子展示了使用OpenMV Cam进行红外RGB565跟踪。


import sensor, image
import time
#from numba import jit
from pyb import UART

import json
import utime

import pyb

#EXPOSURE_TIME_SCALE = 0.1
thresholds = (100,100,0,0,0,0) # thresholds for bright white light from IR.

TimeBin = [0,0]
TimeBox = [0,0]

sensor.reset()

sensor.set_pixformat(sensor.RGB565)

sensor.set_framesize(sensor.QQQVGA)

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

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

sensor.skip_frames(time = 10)
sensor.get_exposure_us()#以毫秒为单位返回曝光率

sensor.set_auto_exposure(False,exposure_us=100)#设置曝光


#sensor.set_auto_exposure(False, \
   # exposure_us = int(current_exposure_time_in_microseconds* EXPOSURE_TIME_SCALE))


clock = time.clock() # Tracks FPS.

uart = UART(3,115200)



def find_max(blobs):
   max_size=0
   for blob in blobs:
        if blob.pixels() >max_size:
            max_blob=blob
#            max_size = blob.pixels()
   return max_blob



while(True):
    #utime.sleep_ms(50)
    #for i in range(0,6000):
    clock.tick()# Track elapsed milliseconds between snapshots().

    img = sensor.snapshot()#binary([thresholds], invert=True, zero=True)
   # TimeBox[1]= TimeBox[0]
   # TimeBox[0] = utime.ticks_ms()
    #deal = utime.ticks_diff(TimeBox[0],TimeBox[1])
    #print("deal :",deal)
   # start = utime.ticks_ms()
    blobs=img.find_blobs([thresholds],pixels_threshold=200,area_threshold=250)


    for blob in blobs:

      output_str = json.dumps(blobs)

      max_blob=find_max(blobs)

      img.draw_rectangle(max_blob.rect(),color=(255,0,0))

      output_str="[%d,%d]" % (max_blob.cx(),max_blob.cy())

      print('you send:',output_str)
      uart.write(output_str+'\n')

     # print("Initial exposure == %d" % sensor.set_auto_exposure())

      #current_exposure_time_in_microseconds=sensor.get_exposure_us()

      #sensor.set_auto_exposure(False, \'
         # exposure_us = int(sensor.get_exposure_us() * EXPOSURE_TIME_SCALE))
      print("New exposure == %d" % sensor.get_exposure_us())

      TimeBin[1] = TimeBin[0]
      TimeBin[0] = utime.ticks_ms()
      delta= utime.ticks_diff(TimeBin[0], TimeBin[1])
      print('duration:',delta)

      print("FPS:", clock.fps())

            #img.draw_cross(blob.cx(), blob.cy())
    else:

                print('not found!')




说要优化代码来提速,但是真的不知道怎么弄了...请问该在哪里优化才能达到提速的效果?
2020-05-22 14:32
I
网红小智智 星瞳科技

我使用OpenMV4 +OV7725 测试你的代码是

FPS: 53.53319

把循环里的 print("New exposure == %d" % sensor.get_exposure_us())注释掉。FPS 64

你具体想达到什么速度?

2020-05-22 20:25
5
yzrl

想到10ms以内,现在多几毫秒

2020-05-23 17:50
I
网红小智智 星瞳科技

换成全局快门,改成灰度,速度可以达到。

https://singtown.com/product/50303/global-shutter-camera-module/

2020-05-23 19:40
5
yzrl

请问这个速度用openmv4 H7是无法达到吗?

2020-05-24 14:32
I
网红小智智 星瞳科技

OpenMV4 标配的OV7725不行,需要换成MT9V034

2020-05-24 20:19
5
yzrl

MT9V034就是全局快门吗?

2020-05-25 12:40
I
网红小智智 星瞳科技

看我上面发的链接。

2020-05-26 12:13
I
网红小智智 星瞳科技

最新OV7725的驱动代码有更新,采集速度提高很多。但是要过一段时间,出release可以用。

详情:https://github.com/openmv/openmv/pull/807

2020-05-26 22:07
5
yzrl

怎样更新板子驱动?

2020-05-27 13:14
I
网红小智智 星瞳科技

过一段时间出release,直接IDE更新资源,IDE会提示更新固件。

2020-05-27 20:24
5
yzrl

大概什么时候能出呢?