当前位置:网站首页>Openmv and k210 of the f question of the 2021 video game call the openmv API for line patrol, which is completely open source.
Openmv and k210 of the f question of the 2021 video game call the openmv API for line patrol, which is completely open source.
2022-07-01 01:16:00 【Mrli0530】
Record 201 Electric competition F The question is openmv Patrol the line , At that time, I borrowed the idea of an old brother on the Internet , I can't find the old brother , I'm sorry . I'm a rookie , If there is something wrong with the big guys, please point out .
One 、 Line patrol
1. principle
At first, I wanted to use openmv Inside the binary linear regression algorithm to do ](/img/e8/0140a3041ecf78826586ef8f60e099.png)
, But it will shake after encountering the intersection , Therefore, it adopts openMv It is directly used as a line patrol sensor .
2. Grayscale Sensor
Our common line patrol sensors are generally gray-scale line patrol , The specific principle will not be introduced ,
After that, the track is red , How to say that, so there is the following openmv Line patrol , Look at two
Two 、openmv Line patrol
openmv Who can't patrol , And there are routines on the official website , Some friends will say , But there must have been other controllers at that time , This thing , Tut tut Ze , There is no time for fun in four days and three nights , Let's be specific .
1.openmv Specific route finding scheme
Two communication schemes , It is recommended to use 2
1. Serial communication
To put it simply, put openmv Become a normal sensor , Well, post the code first
roi 1-7 It is the position that needs to be detected , Adjust it by yourself according to the installation position of your car .
import sensor, image, time
from pyb import UART
uart = UART(3, 115200)
#********** Color /ROI threshold **********#
THRESHOLD = ((50, 22, 26, 75, 17, 55)) # Grayscale threshold for dark things...
roi1=(32,100,10,10)
roi2=(96,100,10,10)
roi3=(160,100,10,10)
roi4=(224,100,10,10)
roi5=(288,100,10,10)
roi6=(132,100,10,10)
roi7=(192,100,10,10)
#************ Variable ************#
a_1=a_2=a_3=a_4=a_5=0
s1=s2=s3=0
#********** Camera parameters **********#
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_windowing([0,20,80,40])
sensor.set_auto_whitebal(False) # Create a clock object to track the FPS.
sensor.skip_frames(time = 2000) # WARNING: If you use QQVGA it may take seconds
#********** Detect the front horizontal line subfunction **********#
def tongji():
global a_1
global a_2
global a_3
global a_4
global a_5
global a_6
global a_7
#**********1**********#
statistics1=img.get_statistics(roi=(32,100,5,5))
color_l1=statistics1.l_mode()
print("color_l1:",color_l1)
if color_l1==100:
a_1=1
else:
a_1=0
#**********2**********#
statistics2=img.get_statistics(roi=(96,100,5,5))
color_l2=statistics2.l_mode()
print("color_l2:",color_l2)
if color_l2==100:
a_2=1
else:
a_2=0
#**********3**********#
statistics3=img.get_statistics(roi=(157,100,5,5))
color_l3=statistics3.l_mode()
print("color_l3:",color_l3)
if color_l3==100:
a_3=1
else:
a_3=0
#**********4**********#
statistics4=img.get_statistics(roi=(224,100,5,5))
color_l4=statistics4.l_mode()
print("color_l4:",color_l4)
if color_l4==100:
a_4=1
else:
a_4=0
#**********5**********#
statistics5=img.get_statistics(roi=(288,100,5,5))
color_l5=statistics5.l_mode()
print("color_l5:",color_l5)
if color_l5==100:
a_5=1
else:
a_5=0
#**********6**********#
statistics6=img.get_statistics(roi=(132,100,5,5))
color_l6=statistics6.l_mode()
print("color_l6:",color_l6)
if color_l6==100:
a_6=1
else:
a_6=0
#**********7**********#
statistics7=img.get_statistics(roi=(192,100,5,5))
color_l7=statistics7.l_mode()
print("color_l7:",color_l7)
if color_l7==100:
a_7=1
else:
a_7=0
#***** Send the 7 The value of a point *****# Be similar to 7 A sensor
print('1a'+str(a_1))
uart.write('1a'+str(a_1)+'\r'+'\n')
print("a_2:",a_2)
uart.write('2a'+str(a_2)+'\r'+'\n')
print("a_3:",a_3)
uart.write('3a'+str(a_3)+'\r'+'\n')
print("a_4:",a_4)
uart.write('4a'+str(a_4)+'\r'+'\n')
print("a_5:",a_5)
uart.write('5a'+str(a_5)+'\r'+'\n')
print("a_6:",a_6)
uart.write('6a'+str(a_6)+'\r'+'\n')
print("a_7:",a_7)
uart.write('7a'+str(a_7)+'\r'+'\n')
while(True):
img = sensor.snapshot().lens_corr(strength = 1.8, zoom = 1.0).binary([THRESHOLD])
img.draw_rectangle(roi1)
img.draw_rectangle(roi2)
img.draw_rectangle(roi3)
img.draw_rectangle(roi4)
img.draw_rectangle(roi5)
img.draw_rectangle(roi6)
img.draw_rectangle(roi7)
tongji()
s1=a_1+a_2+a_3+a_4+a_5+a_6+a_7
if s1>6:# At the same time 7 individual , It means to recognize the horizontal line
uart.write('s1')
else:
s2=a_1+a_2+a_3+a_6
if s2==5:
uart.write('s2') # Two kinds of T
s3=a_3+a_4+a_5+a_7
if s3==5:
uart.write('s3') # Two kinds of T
I believe you can understand this at a glance , Direct is to extract openmv The average color in the area where the camera acquires the image , It's white and red , See this for specific introduction Use statistics .
After that, I used 7 A place , Average distribution , Well, the more you use it, the smoother it will be , The more trouble .5 Send after simultaneous detection ’sss’, Why is 5 A? , Because the car may go askew , Write 5 It may be safer .
2.I/O mouth
The code detection part is all the same , Is to directly detect the red line and then openmv The pins are pulled up or down , Completely made into a universal color line patrol sensor , The whole code will not be posted , Let's make some changes ,I/O The code is here
from pyb import Pin
p_out = Pin('P7', Pin.OUT_PP)# Set up p_out Is the output pin
p_out.high()# Set up p_out Pin is high
p_out.low()# Set up p_out The pin is low
p_in = Pin('P7', Pin.IN, Pin.PULL_UP)# Set up p_in For input pins , And turn on the pull-up resistor
value = p_in.value() # get value, 0 or 1# Read in p_in Pin value
Is to put if It's OK to change it
2021/11/24 Mr.li to update
3、 ... and 、K210 call openmv api To patrol the line
forehead , Words K210 use openmv Of api It's very convenient and really fragrant. After all, it's one piece openmv You can buy two yuan at any price K210 了 , Without further ado, let's get to work
1. Update firmware
stay here Download tape openmv Word firmware 
Then the firmware is burned to the board
If you can't burn, please see here 
2. Program
import sensor,image,lcd
import KPU as kpu
from Maix import FPIOA
from Maix import GPIO
#**************** Camera parameter settings ************#
sensor.reset()
sensor.set_pixformat(sensor.RGB565)
sensor.set_framesize(sensor.QVGA)
sensor.set_hmirror(0)
sensor.set_vflip(0)
sensor.set_auto_gain(1,200)
sensor.run(1)
lcd.init(freq=15000000)
lcd.rotation(0)
sensor.skip_frames(time = 2000) # WARNING: If you use QQVGA it may take seconds
#********** Color /ROI threshold **********#
THRESHOLD = ((50, 22, 26, 75, 17, 55)) # Grayscale threshold for dark things...
roi1=(32,100,10,10)
roi2=(96,100,10,10)
roi3=(160,100,10,10)
roi4=(224,100,10,10)
roi5=(288,100,10,10)
roi6=(132,100,10,10)
roi7=(192,100,10,10)
#************ Variable ************#
a_1=a_2=a_3=a_4=a_5=0
s=0
#***********I/O To configure ***********#
fpioa = FPIOA()
fpioa.set_function(0,fpioa.GPIOHS1)
led0 = GPIO(GPIO.GPIOHS1,GPIO.OUT)
fpioa.set_function(1,fpioa.GPIOHS2)
led1 = GPIO(GPIO.GPIOHS2,GPIO.OUT)
fpioa.set_function(2,fpioa.GPIOHS3)
led2 = GPIO(GPIO.GPIOHS3,GPIO.OUT)
fpioa.set_function(3,fpioa.GPIOHS6)
led3 = GPIO(GPIO.GPIOHS6,GPIO.OUT)
fpioa.set_function(6,fpioa.GPIOHS7)
led6 = GPIO(GPIO.GPIOHS7,GPIO.OUT)
#*********** Statistics *************#
def tongji():
global a_1
global a_2
global a_3
global a_4
global a_5
global a_6
global a_7
#**********1**********#
statistics1=img.get_statistics(roi=(32,100,5,5))
color_l1=statistics1.l_mode()
print("color_l1:",color_l1)
if color_l1==100:
a_1=1
led0.value(1)
else:
a_1=0
led0.value(0)
#**********2**********#
statistics2=img.get_statistics(roi=(96,100,5,5))
color_l2=statistics2.l_mode()
print("color_l2:",color_l2)
if color_l2==100:
a_2=1
led1.value(1)
else:
a_2=0
led1.value(0)
#**********3**********#
statistics3=img.get_statistics(roi=(157,100,5,5))
color_l3=statistics3.l_mode()
print("color_l3:",color_l3)
if color_l3==100:
a_3=1
led2.value(1)
else:
a_3=0
led2.value(0)
#**********4**********#
statistics4=img.get_statistics(roi=(224,100,5,5))
color_l4=statistics4.l_mode()
print("color_l4:",color_l4)
if color_l4==100:
a_4=1
led3.value(1)
else:
a_4=0
led3.value(0)
#**********5**********#
statistics5=img.get_statistics(roi=(288,100,5,5))
color_l5=statistics5.l_mode()
print("color_l5:",color_l5)
if color_l5==100:
a_5=1
led6.value(1)
else:
a_5=0
led6.value(0)
while(True):
img = sensor.snapshot().binary([THRESHOLD])
img.draw_rectangle(roi1)
img.draw_rectangle(roi2)
img.draw_rectangle(roi3)
img.draw_rectangle(roi4)
img.draw_rectangle(roi5)
img.draw_rectangle(roi6)
img.draw_rectangle(roi7)
tongji()
s=a_1+a_2+a_3+a_4+a_5
if s>5:# At the same time 5 individual , It means to recognize the horizontal line
print('sss')
3. Use
Same as other sensors ,I/O Will be output , Adjust according to your car ROI
边栏推荐
- Double position relay dls-5/2 dc220v
- (学习力+思考力) x 行动力,技术人成长的飞轮效应总结
- Dls-42/6-4 dc110v double position relay
- [LeetCode] 爬楼梯【70】
- The longest selling mobile phone in China has been selling well since its launch, crushing iphone12
- 软硬件基础知识学习--小日记(1)
- Some views on libco
- ArrayList分析1-循环、扩容、版本
- Fluent JSON serialization deserialization
- 剑指 Offer 19. 正则表达式匹配
猜你喜欢

Can JDBC based on openjdk connect to MySQL?

Using C language to realize the exchange between the contents of two arrays (provided that the array is the same size)

Unhandled Exception: MissingPluginException(No implementation found for method launch on channel)

Exploring the road of steam education innovation in the Internet Era

Kongyiji's first question: how much do you know about service communication?

Pytorch installs and uses GPU acceleration

Vnctf 2022 cm CM1 re reproduction

【go】go 实现行专列 将集合进行转列

软硬件基础知识学习--小日记(1)

The longest selling mobile phone in China has been selling well since its launch, crushing iphone12
随机推荐
Pytorch installs and uses GPU acceleration
初识 Flutter 的绘图组件 — CustomPaint
Flutter Error: Cannot run with sound null safety, because the following dependencies don‘t support
Service
History of deep learning
Left join displays the specified value when the left join matching data is null
The question of IBL precomputation is finally solved
The longest selling mobile phone in China has been selling well since its launch, crushing iphone12
[LeetCode] 爬楼梯【70】
K210工地安全帽
leetcode 474. Ones and zeroes (medium)
Sword finger offer 18 Delete the node of the linked list
06.论Redis持久化的几种方式
Dls-42/6-4 dc110v double position relay
Cmu15445 (fall 2019) project 1 - buffer pool details
Gavin's insight on the transformer live broadcast course - rasa project's actual banking financial BOT Intelligent Business Dialogue robot system startup, language understanding, dialogue decision-mak
Chapter 53 overall understanding of procedures from the perspective of business logic implementation
Web interface testing of software testing
剑指 Offer 19. 正则表达式匹配
The communication mechanism and extension of Supervisor