日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

openMv入手

發布時間:2024/1/1 编程问答 35 豆豆
生活随笔 收集整理的這篇文章主要介紹了 openMv入手 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

openMv入手

  • 前言
  • openmv是什么
  • 一些基本參數
    • 感光元件(也就是你IDE窗口看到的圖像)
    • 統計信息
    • 畫圖
    • 測距
    • 顏色形狀同時識別
    • 忠告忠告!

前言

之前學習了OpenCV的一些基本操作,但終究是圖片處理,有些干,回學校后拿到openmv模塊開始進行一些相關操作。

openmv是什么



還有一些擴展模塊可選用,but


價格勸退,選用了標配版


參數來源淘寶,它有沒有夸張就不知道了
openmv入手教程
上面這個是官方教程有很多例程講的也十分詳細,對新手十分友好
進階的openmv教程

一些基本參數

感光元件(也就是你IDE窗口看到的圖像)

import sensor#引入感光元件的模塊# 設置攝像頭 sensor.reset()#初始化感光元件 sensor.set_pixformat(sensor.RGB565)#設置為彩色 sensor.set_framesize(sensor.QVGA)#設置圖像的大小 sensor.skip_frames()#跳過n張照片,在更改設置后,跳過一些幀,等待感光元件變穩定。# 一直拍照 while(True):img = sensor.snapshot()#拍攝一張照片,img為一個image對象

sensor.set_pixformat() 設置像素模式。
sensor.GRAYSCALE: 灰度,每個像素8bit。
sensor.RGB565: 彩色,每個像素16bit。
從這里可以看出若轉換為灰度像素是減半的
以下列出了圖像的一些參數

sensor.set_framesize() 設置圖像的大小 sensor.QQCIF: 88x72 sensor.QCIF: 176x144 sensor.CIF: 352x288 sensor.QQSIF: 88x60 sensor.QSIF: 176x120 sensor.SIF: 352x240 sensor.QQQQVGA: 40x30 sensor.QQQVGA: 80x60 sensor.QQVGA: 160x120 sensor.QVGA: 320x240 sensor.VGA: 640x480 sensor.HQQQVGA: 80x40 sensor.HQQVGA: 160x80 sensor.HQVGA: 240x160 sensor.B64X32: 64x32 (用于幀差異 image.find_displacement()) sensor.B64X64: 64x64 用于幀差異 image.find_displacement()) sensor.B128X64: 128x64 (用于幀差異 image.find_displacement()) sensor.B128X128: 128x128 (用于幀差異 image.find_displacement()) sensor.LCD: 128x160 (用于LCD擴展板) sensor.QQVGA2: 128x160 (用于LCD擴展板) sensor.WVGA: 720x480 (用于 MT9V034) sensor.WVGA2:752x480 (用于 MT9V034) sensor.SVGA: 800x600 (僅用于 OV5640 感光元件) sensor.XGA: 1024x768 (僅用于 OV5640 感光元件) sensor.SXGA: 1280x1024 (僅用于 OV5640 感光元件) sensor.UXGA: 1600x1200 (僅用于 OV5640 感光元件) sensor.HD: 1280x720 (僅用于 OV5640 感光元件) sensor.FHD: 1920x1080 (僅用于 OV5640 感光元件) sensor.QHD: 2560x1440 (僅用于 OV5640 感光元件) sensor.QXGA: 2048x1536 (僅用于 OV5640 感光元件) sensor.WQXGA: 2560x1600 (僅用于 OV5640 感光元件) sensor.WQXGA2: 2592x1944 (僅用于 OV5640 感光元件)

我認為,mv比較nb的地方就是自動增益了,以下開啟

sensor.set_auto_gain() 自動增益開啟(True)或者關閉(False)。在使用顏色追蹤時,需要關閉自動增益。sensor.set_auto_whitebal() 自動白平衡開啟(True)或者關閉(False)。在使用顏色追蹤時,需要關閉自動白平衡。sensor.set_auto_exposure(enable[\, exposure_us])enable 打開(True)或關閉(False)自動曝光。默認打開。 如果 enable 為False, 則可以用 exposure_us 設置一個固定的曝光時間(以微秒為單位)。

設置翻轉
sensor.set_hmirror(True)
水平方向翻轉

sensor.set_vflip(True)
垂直方向翻轉 vflip的英文就是垂直鏡像

image.difference(image)
從這張圖片減去另一個圖片。比如,對于每個通道的每個像素點,取相減絕對值操作。這個函數,經常用來做移動檢測。

統計信息

使用統計信息

畫圖

畫線

image.draw_line(line_tuple, color=White) 在圖像中畫一條直線。

line_tuple的格式是(x0, y0, x1, y1),意思是(x0, y0)到(x1, y1)的直線。
顏色可以是灰度值(0-255),或者是彩色值(r, g, b)的tupple。默認是白色

畫框

image.draw_rectangle(rect_tuple, color=White) 在圖像中畫一個矩形框。

rect_tuple 的格式是 (x, y, w, h)。

畫圓

image.draw_circle(x, y, radius, color=White) 在圖像中畫一個圓。

x,y是圓心坐標
radius是圓的半徑

畫十字

image.draw_cross(x, y, size=5, color=White) 在圖像中畫一個十字

x,y是坐標
size是兩側的尺寸

寫字

image.draw_string(x, y, text, color=White) 在圖像中寫字 8x10的像素

x,y是坐標。使用\n, \r, and \r\n會使光標移動到下一行。
text是要寫的字符串。

測距

# Measure the distance # # This example shows off how to measure the distance through the size in imgage # This example in particular looks for yellow pingpong ball.import sensor, image, time# For color tracking to work really well you should ideally be in a very, very, # very, controlled enviroment where the lighting is constant... yellow_threshold = ( 56, 83, 5, 57, 63, 80) # You may need to tweak the above settings for tracking green things... # Select an area in the Framebuffer to copy the color settings.sensor.reset() # Initialize the camera sensor. sensor.set_pixformat(sensor.RGB565) # use RGB565. sensor.set_framesize(sensor.QQVGA) # use QQVGA for speed. sensor.skip_frames(10) # Let new settings take affect. sensor.set_auto_whitebal(False) # turn this off. clock = time.clock() # Tracks FPS.K=5000#the value should be measuredwhile(True):clock.tick() # Track elapsed milliseconds between snapshots().img = sensor.snapshot() # Take a picture and return the image.blobs = img.find_blobs([yellow_threshold])if len(blobs) == 1:# Draw a rect around the blob.b = blobs[0]img.draw_rectangle(b[0:4]) # rectimg.draw_cross(b[5], b[6]) # cx, cyLm = (b[2]+b[3])/2length = K/Lmprint(length)#print(clock.fps()) # Note: Your OpenMV Cam runs about half as fast while# connected to your computer. The FPS should increase once disconnected.

具體原理
測距

顏色形狀同時識別

import sensor, image, timesensor.reset() sensor.set_pixformat(sensor.RGB565) sensor.set_framesize(sensor.QQVGA) sensor.skip_frames(time = 2000) sensor.set_auto_gain(False) # must be turned off for color tracking sensor.set_auto_whitebal(False) # must be turned off for color tracking clock = time.clock()while(True):clock.tick()img = sensor.snapshot().lens_corr(1.8)for c in img.find_circles(threshold = 3500, x_margin = 10, y_margin = 10, r_margin = 10,r_min = 2, r_max = 100, r_step = 2):area = (c.x()-c.r(), c.y()-c.r(), 2*c.r(), 2*c.r())#area為識別到的圓的區域,即圓的外接矩形框statistics = img.get_statistics(roi=area)#像素顏色統計print(statistics)#(0,100,0,120,0,120)是紅色的閾值,所以當區域內的眾數(也就是最多的顏色),范圍在這個閾值內,就說明是紅色的圓。#l_mode(),a_mode(),b_mode()是L通道,A通道,B通道的眾數。if 0<statistics.l_mode()<100 and 0<statistics.a_mode()<127 and 0<statistics.b_mode()<127:#if the circle is redimg.draw_circle(c.x(), c.y(), c.r(), color = (255, 0, 0))#識別到的紅色圓形用紅色的圓框出來else:img.draw_rectangle(area, color = (255, 255, 255))#將非紅色的圓用白色的矩形框出來print("FPS %f" % clock.fps())

忠告忠告!


實驗室有個師兄就這樣燒壞一個openmv4,心疼啊T T

這個很重要
后續再補神經網絡,如果有興趣的小伙伴等不及可聯系我

總結

以上是生活随笔為你收集整理的openMv入手的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。