Files
QD4C-firmware/app/main.c

95 lines
3.4 KiB
C
Raw Normal View History

2023-12-11 21:45:06 +08:00
/*********************************************************************************************************************
* CH32V307VCT6 Opensourec Library CH32V307VCT6 SDK
* Copyright (c) 2022 SEEKFREE
*
* CH32V307VCT6
*
* CH32V307VCT6
* GPLGNU 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
* 使
********************************************************************************************************************/
#include "gl_headfile.h"
#include "by_rt_button.h"
#include "by_fan_control.h"
#include "./page/page.h"
2024-01-07 16:58:53 +08:00
#include "jj_blueteeth.h"
#include "jj_param.h"
#include "./page/page_ui_widget.h"
2024-01-08 22:08:43 +08:00
#include "by_buzzer.h"
int main(void)
2023-12-11 21:45:06 +08:00
{
2024-01-07 17:20:10 +08:00
clock_init(SYSTEM_CLOCK_120M);
system_delay_init();
debug_init();
2023-12-11 21:45:06 +08:00
mt9v03x_init();
ips200_init(IPS200_TYPE_SPI);
2023-12-13 21:54:20 +08:00
by_gpio_init();
by_exit_init();
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();
// while (imu660ra_init())
// ;
jj_param_eeprom_init();
Page_Init();
while (1) {
Page_Run();
2024-01-07 16:58:53 +08:00
jj_bt_run();
2024-01-08 22:08:43 +08:00
queue_pop_read();
if (mt9v03x_finish_flag) {
2024-01-06 16:22:49 +08:00
// 该操作消耗大概 1970 个 tick折合约 110us
memcpy(mt9v03x_image_copy[0], mt9v03x_image[0], (sizeof(mt9v03x_image_copy) / sizeof(uint8_t)));
2023-12-24 22:24:21 +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);
mt9v03x_finish_flag = 0;
state_type = COMMON_STATE;
img_processing();
// get_corners();
aim_distance = COMMON_AIM;
tracking();
// ElementJudge();
// ElementRun();
MidLineTrack();
2023-12-24 22:24:21 +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: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: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
}
}