测试图像代码

This commit is contained in:
Glz
2023-12-24 22:24:21 +08:00
parent 240ada9388
commit eca0d27752
3 changed files with 57 additions and 30 deletions

10
.vscode/launch.json vendored
View File

@@ -5,13 +5,13 @@
"cwd": "${workspaceRoot}", "cwd": "${workspaceRoot}",
"type": "cortex-debug", "type": "cortex-debug",
"request": "launch", "request": "launch",
"name": "jlink", "name": "openocd",
"servertype": "jlink", "servertype": "openocd",
"interface": "swd",
"executable": "build\\Debug\\violet_firmware_zf.elf", "executable": "build\\Debug\\violet_firmware_zf.elf",
"runToEntryPoint": "main", "runToEntryPoint": "main",
"device": "null", "configFiles": [
"toolchainPrefix": "riscv-none-embed" "${workspaceFolder}/tools/wch-riscv.cfg"
]
} }
] ]
} }

View File

@@ -5,8 +5,8 @@
#define IMAGE_H (MT9V03X_H) #define IMAGE_H (MT9V03X_H)
#define IMAGE_W (MT9V03X_W) #define IMAGE_W (MT9V03X_W)
#define BEGINH_L (61) #define BEGINH_L (80)
#define BEGINH_R (61) #define BEGINH_R (80)
#define BEGINW_L (-18) #define BEGINW_L (-18)
#define BEGINW_R (-12) #define BEGINW_R (-12)
#define PT_MAXLEN (75) #define PT_MAXLEN (75)

View File

@@ -89,23 +89,29 @@ int frame_count = 0;
void img_processing(); void img_processing();
void get_corners(); void get_corners();
void adaptiveThreshold(uint8_t* img_data, uint8_t* output_data, int width, int height, int block, uint8_t clip_value);
int main(void) int main(void)
{ {
clock_init(SYSTEM_CLOCK_120M); // <20><>ʼ<EFBFBD><CABC>оƬʱ<C6AC><CAB1> <20><><EFBFBD><EFBFBD>Ƶ<EFBFBD><C6B5>Ϊ 120MHz clock_init(SYSTEM_CLOCK_120M); // <20><>ʼ<EFBFBD><CABC>оƬʱ<C6AC><CAB1> <20><><EFBFBD><EFBFBD>Ƶ<EFBFBD><C6B5>Ϊ 120MHz
debug_init(); // <20><><EFBFBD>ر<EFBFBD><D8B1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڳ<EFBFBD>ʼ<EFBFBD><CABC> MPU ʱ<><CAB1> <20><><EFBFBD>Դ<EFBFBD><D4B4><EFBFBD> debug_init(); // <20><><EFBFBD>ر<EFBFBD><D8B1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڳ<EFBFBD>ʼ<EFBFBD><CABC> MPU ʱ<><CAB1> <20><><EFBFBD>Դ<EFBFBD><D4B4><EFBFBD>
// mt9v03x_init(); //mt9v03x_init();
// system_delay_ms(2000);
ips200_init(IPS200_TYPE_SPI); ips200_init(IPS200_TYPE_SPI);
by_gpio_init(); mt9v03x_init();
by_exit_init(); // by_gpio_init();
by_pwm_init(); // by_exit_init();
cw_servo_init(); // by_pwm_init();
while (imu660ra_init()) // cw_servo_init();
; //printf("hello world\n");
// while (imu660ra_init())
// ;
system_delay_ms(2000); // system_delay_ms(2000);
gyroOffset_init(); // gyroOffset_init();
pit_ms_init(TIM6_PIT, 2); // pit_ms_init(TIM6_PIT, 2);
while (1) { while (1) {
// while (frame_count < 20) { // while (frame_count < 20) {
@@ -113,36 +119,57 @@ int main(void)
// 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, 8); // adaptiveThreshold((uint8_t*)mt9v03x_image_copy, (uint8_t*)mt9v03x_image_copy, 188, 120, 7, 8);
// //threshold((uint8_t*)mt9v03x_image_copy, (uint8_t*)mt9v03x_image_copy, MT9V03X_W, MT9V03X_H, 110); // //threshold((uint8_t*)mt9v03x_image_copy, (uint8_t*)mt9v03x_image_copy, MT9V03X_W, MT9V03X_H, 110);
// ips114_show_gray_image(0, 0, mt9v03x_image_copy[0], MT9V03X_W, MT9V03X_H, MT9V03X_W, MT9V03X_H, 0); // 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;
// frame_count++; // frame_count++;
// } // }
//} //}
if (mt9v03x_finish_flag) { if (mt9v03x_finish_flag) {
// ips114_show_gray_image(0, 0, mt9v03x_image[0], 188, 120, 188, 120,0);
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)));
// Img_Gray = mt9v03x_image; adaptiveThreshold((uint8_t*)mt9v03x_image_copy, (uint8_t*)mt9v03x_image_copy, 188, 120, 7, 17);
// mt9v03x_image_copy[0] = Img_Gray[0]; 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;
img_processing(); img_processing();
get_corners(); //get_corners();
aim_distance = COMMON_AIM; //aim_distance = COMMON_AIM;
tracking(); //tracking();
//printf("1\r\n");
//system_delay_ms(100);
ElementJudge(); //ElementJudge();
ElementRun(); //ElementRun();
MidLineTrack(); //MidLineTrack();
}
// // by_imu_data_get();
// // by_ips_show();
// // system_delay_ms(200);
}
}
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++){
// <20><><EFBFBD><EFBFBD><EFBFBD>ֲ<EFBFBD><D6B2><EFBFBD>ֵ
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;
// <20><><EFBFBD>ж<EFBFBD>ֵ<EFBFBD><D6B5>
output_data[x+y*width] = img_data[x+y*width]>thres ? 255 : 0;
} }
// by_imu_data_get();
by_ips_show();
system_delay_ms(200);
} }
} }