add rfid and spec terrain process
This commit is contained in:
+15
@@ -0,0 +1,15 @@
|
||||
@echo off
|
||||
set /p message=请输入本次提交信息:
|
||||
|
||||
REM 将变更添加到暂存区
|
||||
git add track.py
|
||||
git add submit.bat
|
||||
|
||||
REM 提交变更并添加提交信息
|
||||
git commit -m "%message%"
|
||||
|
||||
REM 推送到远程仓库
|
||||
git push origin master
|
||||
|
||||
REM 等待用户手动关闭窗口
|
||||
pause
|
||||
@@ -110,7 +110,29 @@ def data_format_wrapper(down_center, state_crossing, deflection_angle):
|
||||
return bytes(send_data)
|
||||
|
||||
|
||||
def UsartSend(str_data, _img):
|
||||
def SendWhiteData(is_detect, detect_info=0x00):
|
||||
data = [0x55,0x02,0x80,
|
||||
0x02 if is_detect else 0x01,
|
||||
detect_info if is_detect else 0x00,0x00,0x00,0xBB]
|
||||
UsartSend(bytes(data))
|
||||
|
||||
def SendROIData(roi_data):
|
||||
data_1 = [0x55,0x02,0x81,
|
||||
0x01 if roi_data['left']['blob_flag'] else 0x00,
|
||||
0x01 if roi_data['right']['blob_flag'] else 0x00,
|
||||
0x01 if roi_data['up']['blob_flag'] else 0x00,
|
||||
0x00,0xBB]
|
||||
data_2 = [0x55,0x02,0x82,
|
||||
0x01 if roi_data['middle_up']['blob_flag'] else 0x00,
|
||||
0x01 if roi_data['middle_down']['blob_flag'] else 0x00,
|
||||
0x01 if roi_data['down']['blob_flag'] else 0x00,
|
||||
0x00,0xBB]
|
||||
UsartSend(bytes(data_1))
|
||||
time.sleep(1)
|
||||
UsartSend(bytes(data_2))
|
||||
|
||||
|
||||
def UsartSend(str_data):
|
||||
'''
|
||||
串口发送函数
|
||||
'''
|
||||
@@ -122,7 +144,7 @@ def UsartSend(str_data, _img):
|
||||
|
||||
#--------------定时器部分 START -------------------
|
||||
|
||||
is_need_send_data = True # 是否需要发送数据的信号标志
|
||||
is_need_send_data = False # 是否需要发送数据的信号标志
|
||||
def uart_time_trigger(tim):
|
||||
'''
|
||||
串口发送数据的定时器,定时器的回调函数
|
||||
@@ -176,8 +198,9 @@ time.sleep(1)
|
||||
|
||||
|
||||
# 直线灰度图颜色阈值
|
||||
LINE_COLOR_THRESHOLD = [(6, 65)]
|
||||
#LIGHT_LINE_COLOR_THRESHOLD = [(9, 88)]
|
||||
LINE_COLOR_THRESHOLD = [(6, 65)] #Dark
|
||||
WHITE_BLOCK_THRESHOLD = [(165, 255)]
|
||||
#LINE_COLOR_THRESHOLD = [(6, 120)] #Light
|
||||
#LINE_COLOR_THRESHOLD = [(0, 52, -19, 0, -1, 14)]
|
||||
|
||||
# 以实际空间坐标为基准,取样窗口
|
||||
@@ -229,10 +252,41 @@ def find_blobs_in_rois(img):
|
||||
if is_debug:
|
||||
img.draw_rectangle((x,y,width, height), color=(255))
|
||||
else:
|
||||
#blobs=canvas.find_blobs(LINE_COLOR_THRESHOLD, roi=roi, merge=True, pixels_area=10)
|
||||
blobs=canvas.find_blobs(LINE_COLOR_THRESHOLD, roi=roi, merge=True, pixels_area=10)
|
||||
continue
|
||||
return roi_blobs_result
|
||||
|
||||
|
||||
def find_white_blobs_in_rois(img):
|
||||
'''
|
||||
说明:在ROIS中寻找色块,获取ROI中色块的中心区域与是否有色块的信息
|
||||
'''
|
||||
global ROIS
|
||||
global is_debug
|
||||
canvas = img.copy()
|
||||
roi_blobs_result = {} # 在各个ROI中寻找色块的结果记录
|
||||
for roi_direct in ROIS.keys():
|
||||
roi_blobs_result[roi_direct] = {
|
||||
'cx':0,
|
||||
'cy':0,
|
||||
'w':0,
|
||||
'blob_flag': False
|
||||
}
|
||||
for roi_direct, roi in ROIS.items():
|
||||
blobs=canvas.find_blobs(WHITE_BLOCK_THRESHOLD, roi=roi, merge=True)
|
||||
if len(blobs) != 0:
|
||||
largest_blob = max(blobs, key=lambda b: b.pixels())
|
||||
if largest_blob.area() > 1000:
|
||||
x,y,width,height = largest_blob[:4]
|
||||
roi_blobs_result[roi_direct]['cx'] = largest_blob.cy()
|
||||
roi_blobs_result[roi_direct]['cy'] = largest_blob.cx()
|
||||
roi_blobs_result[roi_direct]['w'] = largest_blob.h()
|
||||
roi_blobs_result[roi_direct]['blob_flag'] = True
|
||||
if is_debug:
|
||||
img.draw_rectangle((x,y,width, height), color=(255))
|
||||
else:
|
||||
blobs=canvas.find_blobs(WHITE_BLOCK_THRESHOLD, roi=roi, merge=True, pixels_area=10)
|
||||
continue
|
||||
return roi_blobs_result
|
||||
|
||||
|
||||
@@ -277,6 +331,27 @@ def state_deflection_angle(roi_blobs_result):
|
||||
|
||||
#--------------直线与路口检测部分 END -------------------
|
||||
|
||||
#--------------RFID卡与特殊地形标志物检测 START -------------------
|
||||
|
||||
white_line_flag = 0
|
||||
|
||||
def rfid_and_spec_terrain_detect(roi_blobs_result):
|
||||
global white_line_flag
|
||||
if roi_blobs_result['up']['w'] > 100 and white_line_flag == 0:
|
||||
white_line_flag = 1;
|
||||
return False
|
||||
if roi_blobs_result['middle_up']['w'] > 100 and white_line_flag == 1:
|
||||
white_line_flag = 2;
|
||||
return False
|
||||
if roi_blobs_result['middle_down']['w'] > 100 and white_line_flag == 2:
|
||||
white_line_flag = 3;
|
||||
return False
|
||||
if roi_blobs_result['down']['w'] > 100 and white_line_flag == 3:
|
||||
white_line_flag = 0;
|
||||
return True
|
||||
|
||||
|
||||
#--------------RFID卡与特殊地形标志物检测 END -------------------
|
||||
|
||||
#--------------二维码识别部分 START -------------------
|
||||
|
||||
@@ -309,8 +384,6 @@ def QR_Check():
|
||||
last_cx = 0
|
||||
last_cy = 0
|
||||
Flag_track = False
|
||||
#调试,使设备始终处于巡线模式
|
||||
#Flag_track = True
|
||||
#将蓝灯引脚IO12配置到GPIO0,K210引脚支持任意配置
|
||||
fm.register(12, fm.fpioa.GPIO0)
|
||||
LED_B = GPIO(GPIO.GPIO0, GPIO.OUT) #构建LED对象
|
||||
@@ -322,6 +395,8 @@ while True:
|
||||
LED_B.value(0) #点亮LED
|
||||
# 拍摄图片
|
||||
img = sensor.snapshot()
|
||||
# 去除图像畸变
|
||||
img.lens_corr(DISTORTION_FACTOR)
|
||||
# 串口数据接收处理
|
||||
data = uart.read(8)
|
||||
if data is not None:
|
||||
@@ -340,8 +415,9 @@ while True:
|
||||
if(data[3] == 0x02):
|
||||
print("巡线")
|
||||
print("停止识别")
|
||||
Flag_track = False
|
||||
tim1.stop() # 停止定时器
|
||||
Flag_track = False
|
||||
time.sleep(1)
|
||||
if(data[3] == 0x03): # 舵机调整
|
||||
angle = data[5]
|
||||
# 判断舵机控制方向
|
||||
@@ -372,22 +448,26 @@ while True:
|
||||
QR_Flag = False
|
||||
|
||||
|
||||
# 去除图像畸变
|
||||
#img.lens_corr(DISTORTION_FACTOR)
|
||||
# 二维码识别
|
||||
#QR_Check()
|
||||
# 巡线
|
||||
if Flag_track:
|
||||
roi_blobs_result = find_blobs_in_rois(img)
|
||||
down_center, state_crossing, deflection_angle = state_deflection_angle(roi_blobs_result)
|
||||
LCDDrawTrackInfo(down_center, state_crossing, deflection_angle, img)
|
||||
if is_need_send_data:
|
||||
UsartSend(data_format_wrapper(down_center, state_crossing, deflection_angle))
|
||||
time.sleep_ms(10)
|
||||
if rfid_and_spec_terrain_detect(find_white_blobs_in_rois(img)):
|
||||
SendWhiteData(False)
|
||||
is_need_send_data = False
|
||||
|
||||
# 在LCD上显示
|
||||
#lcd.display(img)
|
||||
else:
|
||||
down_center, state_crossing, deflection_angle = state_deflection_angle(roi_blobs_result)
|
||||
if state_crossing:
|
||||
white_line_flag = 0
|
||||
LCDDrawTrackInfo(down_center, state_crossing, deflection_angle, img)
|
||||
if is_need_send_data:
|
||||
UsartSend(data_format_wrapper(down_center, state_crossing, deflection_angle))
|
||||
time.sleep_ms(10)
|
||||
is_need_send_data = False
|
||||
else:
|
||||
# 在LCD上显示
|
||||
lcd.display(img)
|
||||
#按键KEY按下。开启或关闭调试,并退出所有任务。
|
||||
if btn_debug.value() == 0:
|
||||
Flag_track = not Flag_track # 巡线任务退出
|
||||
|
||||
Reference in New Issue
Block a user