标题: 关于OPNEMV的视觉识别系统 [打印本页]

作者: 公长拜拜    时间: 2018-6-19 13:49
标题: 关于OPNEMV的视觉识别系统

作者: 公长拜拜    时间: 2018-6-19 13:49
标题: 关于OPNEMV的视觉识别系统
相机采用openmv硬件相机,能够识别颜色,并将RGB值返回,或是找到固定RGB值的图像区域范围

程序如下://语言 :python 编程

import sensor, image, pyb, os, time

sensor.reset() # Initialize the camera sensor.
sensor.set_pixformat(sensor.GRAYSCALE) # or sensor.GRAYSCALE
sensor.set_framesize(sensor.QQVGA) # or sensor.QQVGA (or others)
sensor.skip_frames(time = 2000) # Let new settings take affect.
sensor.set_auto_whitebal(True) # Turn off white balance.
clock = time.clock() # Tracks FPS.
min_degree = 0
max_degree = 179
#获取正确样本图片
if not "temp" in os.listdir():os.mkdir("temp")#创建文件夹temp
print("3秒后录制正确样本")
kernel_size = 1 # kernel width = (size*2)+1, kernel height = (size*2)+1
kernel = [-1, -1, -1,\
          -1, +3, -1,\
          -1, -1, -1]
sensor.skip_frames(time= 3000)
sensor.snapshot().save("temp/bg.bmp")
print("正确样本保存结束")

while(True):
    clock.tick()
    print("请放置好被检测样本")
    time.sleep(3)
    print("开始检测")
    img = sensor.snapshot()


    img.difference("temp/bg.bmp")
    thresholds=(240,255)
    img.find_blobs([thresholds], pixels_threshold=100, area_threshold=100, merge=True);
    for l in img.find_lines(threshold = 1000, theta_margin = 25, rho_margin = 25):
           if (min_degree <= l.theta()) and (l.theta() <= max_degree):
               img.draw_line(l.line(), color = (255, 0, 0))

               print(l)
//下面是一些重要函数用法
image.find_template(template, threshold, roi=Auto, step=2, search=image.SEARCH_EX)
Tries to find the first location in the image where template matches using Normalized Cross Correlation. Returns a bounding box tuple (x, y, w, h) for the matching location otherwise None.

template is a small image object that is matched against this image object. Note that both images must be grayscale.

threshold is floating point number (0.0-1.0) where a higher threshold prevents false positives while lowering the detection rate while a lower threshold does the opposite.

roi is the region-of-interest rectangle (x, y, w, h) to search in.

step is the number of pixels to skip past while looking for the template. Skipping pixels considerably speeds the algorithm up. This only affects the algorithm in SERACH_EX mode.

search can be either image.SEARCH_DS or image.SEARCH_EX. image.SEARCH_DS searches for the template using as faster algorithm than image.SEARCH_EX but may not find the template if it’s near the edges of the image. image.SEARCH_EX does an exhaustive search for the image but can be much slower than image.SEARCH_DS.

Note

roi, step, and search are keyword arguments which must be explicitly invoked in the function call by writing roi=, step=, or search=.


作者: 公长拜拜    时间: 2018-6-19 13:49
主要代码,以及一个例程




欢迎光临 (http://www.51hei.com/bbs/) Powered by Discuz! X3.1