This commit is contained in:
2024-01-16 20:09:12 +08:00
22 changed files with 568 additions and 81 deletions

View File

@@ -60,6 +60,8 @@ int main(void)
if (mt9v03x_finish_flag) {
// 该操作消耗大概 1970 个 tick折合约 110us
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;
state_type = COMMON_STATE;
@@ -70,8 +72,27 @@ int main(void)
ElementJudge();
ElementRun();
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;
}
}
}