2023-12-11 21:45:06 +08:00
|
|
|
|
/*********************************************************************************************************************
|
2024-01-04 22:07:13 +08:00
|
|
|
|
* CH32V307VCT6 Opensourec Library 即(CH32V307VCT6 开源库)是一个基于官方 SDK 接口的第三方开源库
|
|
|
|
|
|
* Copyright (c) 2022 SEEKFREE 逐飞科技
|
|
|
|
|
|
*
|
|
|
|
|
|
* 本文件是 CH32V307VCT6 开源库的一部分
|
|
|
|
|
|
*
|
|
|
|
|
|
* CH32V307VCT6 开源库 是免费软件
|
|
|
|
|
|
* 您可以根据自由软件基金会发布的 GPL(GNU General Public License,即 GNU 通用公共许可证)的条款
|
|
|
|
|
|
* 即 GPL 的第 3 版(即 GPL3.0)或(您选择的)任何后来的版本,重新发布和/或修改它
|
|
|
|
|
|
*
|
|
|
|
|
|
* 本开源库的发布是希望它能发挥作用,但并未对其作任何的保证
|
|
|
|
|
|
* 甚至没有隐含的适销性或适合特定用途的保证
|
|
|
|
|
|
* 更多细节请参见 GPL
|
|
|
|
|
|
*
|
|
|
|
|
|
* 您应该在收到本开源库的同时收到一份 GPL 的副本
|
|
|
|
|
|
* 如果没有,请参阅<https://www.gnu.org/licenses/>
|
|
|
|
|
|
*
|
|
|
|
|
|
* 额外注明:
|
|
|
|
|
|
* 本开源库使用 GPL3.0 开源许可证协议 以上许可申明为译文版本
|
|
|
|
|
|
* 许可申明英文版在 libraries/doc 文件夹下的 GPL3_permission_statement.txt 文件中
|
|
|
|
|
|
* 许可证副本在 libraries 文件夹下 即该文件夹下的 LICENSE 文件
|
|
|
|
|
|
* 欢迎各位使用并传播本程序 但修改内容时必须保留逐飞科技的版权声明(即本声明)
|
|
|
|
|
|
********************************************************************************************************************/
|
2023-12-17 16:11:35 +08:00
|
|
|
|
#include "gl_headfile.h"
|
2024-01-04 22:07:13 +08:00
|
|
|
|
#include "by_rt_button.h"
|
2023-12-15 21:42:43 +08:00
|
|
|
|
#include "by_fan_control.h"
|
2024-01-08 22:30:20 +08:00
|
|
|
|
#include "./page/page.h"
|
2024-01-07 16:58:53 +08:00
|
|
|
|
#include "jj_blueteeth.h"
|
2024-01-08 22:30:20 +08:00
|
|
|
|
#include "jj_param.h"
|
|
|
|
|
|
#include "./page/page_ui_widget.h"
|
2024-01-08 22:08:43 +08:00
|
|
|
|
#include "by_buzzer.h"
|
2023-12-21 22:33:36 +08:00
|
|
|
|
|
2023-12-16 11:31:25 +08:00
|
|
|
|
int main(void)
|
2023-12-11 21:45:06 +08:00
|
|
|
|
{
|
2024-01-07 17:20:10 +08:00
|
|
|
|
|
2023-12-24 22:21:15 +08:00
|
|
|
|
clock_init(SYSTEM_CLOCK_120M);
|
2024-01-05 09:13:10 +08:00
|
|
|
|
system_delay_init();
|
2023-12-24 22:21:15 +08:00
|
|
|
|
debug_init();
|
2023-12-11 21:45:06 +08:00
|
|
|
|
mt9v03x_init();
|
2023-12-21 22:33:36 +08:00
|
|
|
|
ips200_init(IPS200_TYPE_SPI);
|
2023-12-13 21:54:20 +08:00
|
|
|
|
by_gpio_init();
|
|
|
|
|
|
by_exit_init();
|
2023-12-15 21:42:43 +08:00
|
|
|
|
by_pwm_init();
|
2024-01-07 16:58:53 +08:00
|
|
|
|
jj_bt_init();
|
2024-01-08 22:08:43 +08:00
|
|
|
|
by_buzzer_init();
|
2023-12-24 22:21:15 +08:00
|
|
|
|
// while (imu660ra_init())
|
|
|
|
|
|
// ;
|
2024-01-08 22:30:20 +08:00
|
|
|
|
jj_param_eeprom_init();
|
2023-12-21 22:33:36 +08:00
|
|
|
|
Page_Init();
|
2023-12-17 16:11:35 +08:00
|
|
|
|
|
2023-12-21 22:33:36 +08:00
|
|
|
|
while (1) {
|
2024-01-04 22:07:13 +08:00
|
|
|
|
|
2023-12-21 22:33:36 +08:00
|
|
|
|
Page_Run();
|
2024-01-07 16:58:53 +08:00
|
|
|
|
jj_bt_run();
|
2024-01-08 22:08:43 +08:00
|
|
|
|
queue_pop_read();
|
2024-01-04 22:07:13 +08:00
|
|
|
|
|
2023-12-17 16:11:35 +08:00
|
|
|
|
if (mt9v03x_finish_flag) {
|
2024-01-06 16:22:49 +08:00
|
|
|
|
// 该操作消耗大概 1970 个 tick,折合约 110us
|
2023-12-21 22:33:36 +08:00
|
|
|
|
memcpy(mt9v03x_image_copy[0], mt9v03x_image[0], (sizeof(mt9v03x_image_copy) / sizeof(uint8_t)));
|
2024-01-13 18:20:39 +08:00
|
|
|
|
//adaptiveThreshold((uint8_t*)mt9v03x_image_copy, (uint8_t*)mt9v03x_image_copy, 188, 120, 7, 17);
|
|
|
|
|
|
//ips200_show_gray_image(0, 0, mt9v03x_image_copy[0], MT9V03X_W, MT9V03X_H, MT9V03X_W, MT9V03X_H, 0);
|
2023-12-17 16:11:35 +08:00
|
|
|
|
mt9v03x_finish_flag = 0;
|
|
|
|
|
|
|
|
|
|
|
|
state_type = COMMON_STATE;
|
|
|
|
|
|
img_processing();
|
2024-01-13 18:20:39 +08:00
|
|
|
|
get_corners();
|
2023-12-17 16:11:35 +08:00
|
|
|
|
aim_distance = COMMON_AIM;
|
|
|
|
|
|
tracking();
|
2024-01-13 18:20:39 +08:00
|
|
|
|
ElementJudge();
|
|
|
|
|
|
ElementRun();
|
2023-12-17 16:11:35 +08:00
|
|
|
|
MidLineTrack();
|
|
|
|
|
|
|
2023-12-24 22:24:21 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2023-12-17 16:11:35 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2023-12-24 22:24:21 +08:00
|
|
|
|
void adaptiveThreshold(uint8_t* img_data, uint8_t* output_data, int width, int height, int block, uint8_t clip_value){
|
|
|
|
|
|
int half_block = block / 2;
|
|
|
|
|
|
for(int y=half_block; y<height-half_block; y++){
|
|
|
|
|
|
for(int x=half_block; x<width-half_block; x++){
|
2023-12-24 22:28:03 +08:00
|
|
|
|
// 计算局部阈值
|
2023-12-24 22:24:21 +08:00
|
|
|
|
int thres = 0;
|
|
|
|
|
|
for(int dy=-half_block; dy<=half_block; dy++){
|
|
|
|
|
|
for(int dx=-half_block; dx<=half_block; dx++){
|
|
|
|
|
|
thres += img_data[(x+dx)+(y+dy)*width];
|
2023-12-11 21:45:06 +08:00
|
|
|
|
}
|
2023-12-24 22:24:21 +08:00
|
|
|
|
}
|
|
|
|
|
|
thres = thres / (block * block) - clip_value;
|
2023-12-24 22:28:03 +08:00
|
|
|
|
// 进行二值化
|
2023-12-24 22:24:21 +08:00
|
|
|
|
output_data[x+y*width] = img_data[x+y*width]>thres ? 255 : 0;
|
2023-12-11 21:45:06 +08:00
|
|
|
|
}
|
2023-12-24 22:24:21 +08:00
|
|
|
|
}
|
2023-12-17 16:23:13 +08:00
|
|
|
|
}
|