This commit is contained in:
Glz
2024-01-08 20:20:44 +08:00

View File

@@ -42,7 +42,9 @@ int main(void)
// while (imu660ra_init()) // while (imu660ra_init())
// ; // ;
Page_Init(); // system_delay_ms(2000);
// gyroOffset_init();
// pit_ms_init(TIM6_PIT, 2);
while (1) { while (1) {
@@ -50,6 +52,8 @@ int main(void)
if (mt9v03x_finish_flag) { if (mt9v03x_finish_flag) {
// 该操作消耗大概 1970 个 tick折合约 110us // 该操作消耗大概 1970 个 tick折合约 110us
memcpy(mt9v03x_image_copy[0], mt9v03x_image[0], (sizeof(mt9v03x_image_copy) / sizeof(uint8_t))); memcpy(mt9v03x_image_copy[0], mt9v03x_image[0], (sizeof(mt9v03x_image_copy) / sizeof(uint8_t)));
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; mt9v03x_finish_flag = 0;
state_type = COMMON_STATE; state_type = COMMON_STATE;
@@ -60,6 +64,27 @@ int main(void)
// ElementJudge(); // ElementJudge();
// ElementRun(); // ElementRun();
MidLineTrack(); MidLineTrack();
}
}
}
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++){
// 计算局部阈值
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];
}
}
thres = thres / (block * block) - clip_value;
// 进行二值化
output_data[x+y*width] = img_data[x+y*width]>thres ? 255 : 0;
} }
} }
} }