openmv第一次除錯

2022-05-16 13:19:54 字數 2922 閱讀 7090

2018-09-19  20:14:51

import

sensor, image, time

import

carimport

json

import

time

from pyb import

uart

from pid import

pidsensor.reset()

#initialize the camera sensor.

sensor.set_pixformat(sensor.rgb565) #

use rgb565.

sensor.set_framesize(sensor.qqvga) #

use qqvga for speed.

sensor.skip_frames(30) #

let new settings take affect.

sensor.set_auto_whitebal(false) #

追蹤顏色需要關閉白平衡

sensor.set_auto_gain(false)#

掃碼需要關閉自動增益

clock = time.clock() #

tracks fps.

red_threshold = (13, 49, 18, 61, 6, 47) #

紅色閾值

size_threshold = 2000x_pid = pid(p=0.5, i=1, imax=100)

h_pid = pid(p=0.05, i=0.1, imax=50)

uart = uart(3, 115200)

ma_flag =0

ma =

'''#串列埠通訊:

測試json資料

data=

data_out = json.dumps(set(data))

uart.write(data_out +'\n')

uart.write("hello world!\r")

'''#

#####################

'''#掃碼反饋資訊

img.lens_corr(1.8) # 縮小視野

for code in img.find_qrcodes():

print(code)

'''def

find_ma():

global

ma_flag

ifma_flag :

print("

已完成掃碼。")

else

: ma =img.find_qrcodes()

ifma:

print("

發現***即將停車進行掃碼")

saoma()

ma_flag = 1

else

:

print("

正在尋找***。。。")

defsaoma():

img.lens_corr(1.8) #

strength of 1.8 is good for the 2.8mm lens.

for code in

img.find_qrcodes():

print

(code)

deffind_max(blobs):

max_size=0

for blob in

blobs:

if blob[2]*blob[3] >max_size:

max_blob=blob

max_size = blob[2]*blob[3]

return

max_blob

while

(true):

clock.tick()

#track elapsed milliseconds between snapshots().

img =sensor.snapshot()

find_ma()

'''blobs = img.find_blobs([red_threshold])

if blobs:

max_blob = find_max(blobs)

x_error = max_blob[5]-img.width()/2

h_error = max_blob[2]*max_blob[3]-size_threshold

# print("x error: ", x_error)

print("測試與arduino通訊")

###下面**為測試與arduino通訊傳送座標####

data=

for b in blobs:

# draw a rect around the blob.

img.draw_rectangle(b[0:4]) # rect

img.draw_cross(b[5], b[6]) # cx, cy

data_out = json.dumps(set(data))

uart.write(data_out +'\n')

###################################

img.draw_rectangle(max_blob[0:4]) # rect

img.draw_cross(max_blob[5], max_blob[6]) # cx, cy

x_output=x_pid.get_pid(x_error,1)

h_output=h_pid.get_pid(h_error,1)

print("h_output",h_output)

car.run(-h_output-x_output,-h_output+x_output)

else:

car.run(10,-10) #旋轉尋找小球

'''

第一次除錯python爬蟲

建立檔案 vi pic down.py 執行 pic down.py 報錯 permission denied 解決 chmod a x pic down.py 執行 pic down.py 報錯 pic down.py line 1 import command not found 解決 在頭部加...

visual studio第一次除錯遇到的問題

win32project3.exe win32 已載入 d software vs2013 vs2013 文件 win32project3 debug win32project3.exe 已載入符號。win32project3.exe win32 已載入 c windows syswow64 ntd...

第一次藍芽TWS除錯專案

長按兩秒開機,開機提示音 power on 紅藍燈雙閃 1 在對應的級板.件中,設定按鍵和led i o口 2 在對應級板.件中,增加中的巨集,方便操作 能量檢測 define bt coonect music pause voice info 60 20 連線上藍芽後,無播歌20分鐘後自動關機 上...