新手入门
- 积分
- 12
- 金钱
- 12
- 注册时间
- 2023-11-12
- 在线时间
- 5 小时
|
5金钱
最近根据原子哥的例程弄了一个摄像头图像采集和图像无线传输
为了提高传输速度,已经将esp8266的波特率改成了2mhz,且图像采集使用jpeg压缩格式
并选择了支持的最小图像大小,单个图像5-10kb,但是使用原子哥的网络摄像头软件测试的时候,画面依旧卡顿
希望大伙可以帮忙看看
- #include "demo.h"
- #include "./BSP/ATK_MC5640/atk_mc5640.h"
- #include "./BSP/ATK_MC5640/atk_mc5640_dcmi.h"
- #include "./BSP/ATK_MW8266D/atk_mw8266d.h"
- #include "./SYSTEM/usart/usart.h"
- #include "./SYSTEM/delay/delay.h"
- #include "./BSP/LED/led.h"
- #include "./BSP/KEY/key.h"
- #include "./BSP/LCD/lcd.h"
- #include "string.h"
- #define JPEG_OUTPUT_WIDTH 160 //320
- #define JPEG_OUTPUT_HEIGHT 120 //240
- #define JPEG_BUF_SIZE (20*1024)
- uint32_t g_jpeg_buf[JPEG_BUF_SIZE / sizeof(uint32_t)];
- #define DEMO_WIFI_SSID "Xiaomi 12S Pro"
- #define DEMO_WIFI_PWD "88888888"
- #define DEMO_TCP_SERVER_IP "192.168.37.84"
- #define DEMO_TCP_SERVER_PORT "8080"
- static void demo_show_ip(char *buf)
- {
- printf("IP: %s\r\n", buf);
- lcd_show_string(60, 151, 128, 16, 16, buf, BLUE);
- }
- static void Receivedata()
- {
- uint8_t *buf;
- buf = atk_mw8266d_uart_rx_get_frame();
- if (buf != NULL)
- {
- printf("%s", buf);
- atk_mw8266d_uart_rx_restart();
- }
- }
- void ErrLight(){
- while (1)
- {
- LED0_TOGGLE();
- delay_ms(200);
- }
- }
- void send_image_data_via_uart(const uint32_t *image_data, uint32_t length)
- {
- atk_mw8266d_uart_send_data((const uint8_t *)image_data, length);
- }
- void demo_run(void)
- {
- uint8_t *p_jpeg_buf;
- uint32_t jpeg_len;
- uint32_t jpeg_index;
- uint32_t jpeg_start_index;
- uint32_t jpeg_end_index;
-
- uint8_t ret;
- char ip_buf[16];
- ret = atk_mw8266d_init(2000000);//2000000 921600 115200
- if (ret != 0)
- {
- printf("ATK-MW8266D init failed!\r\n");
- ErrLight();
- }
-
- printf("Joining to AP...\r\n");
- //ret = atk_mw8266d_restore();
- ret += atk_mw8266d_at_test();
- ret += atk_mw8266d_set_mode(1);
- ret += atk_mw8266d_sw_reset();
- ret += atk_mw8266d_ate_config(0);
- ret += atk_mw8266d_join_ap(DEMO_WIFI_SSID, DEMO_WIFI_PWD);
- //ret += atk_mw8266d_changebaudrate(2000000);
- ret += atk_mw8266d_get_ip(ip_buf);
- if (ret != 0)
- {
- printf("Error to join ap!\r\n");
- ErrLight();
- }
- demo_show_ip(ip_buf);
-
- ret = atk_mw8266d_connect_tcp_server(DEMO_TCP_SERVER_IP, DEMO_TCP_SERVER_PORT);
- if (ret != 0){
- printf("Error to connect Service!\r\n");
- ErrLight();
- }
- atk_mw8266d_uart_rx_restart();
-
- ret = atk_mw8266d_enter_unvarnished();
- if (ret != 0){
- printf("Error to enter Unvarnished!\r\n");
- ErrLight();
- }
-
- ret = atk_mc5640_init();
- ret += atk_mc5640_set_output_format(ATK_MC5640_OUTPUT_FORMAT_JPEG);
- ret += atk_mc5640_auto_focus_init();
- ret += atk_mc5640_auto_focus_continuance();
- ret += atk_mc5640_set_light_mode(ATK_MC5640_LIGHT_MODE_ADVANCED_AWB);
- ret += atk_mc5640_set_color_saturation(ATK_MC5640_COLOR_SATURATION_4);
- ret += atk_mc5640_set_brightness(ATK_MC5640_BRIGHTNESS_4);
- ret += atk_mc5640_set_contrast(ATK_MC5640_CONTRAST_4);
- ret += atk_mc5640_set_hue(ATK_MC5640_HUE_6);
- ret += atk_mc5640_set_special_effect(ATK_MC5640_SPECIAL_EFFECT_NORMAL);
- ret += atk_mc5640_set_exposure_level(ATK_MC5640_EXPOSURE_LEVEL_5);
- ret += atk_mc5640_set_sharpness_level(ATK_MC5640_SHARPNESS_OFF);
- ret += atk_mc5640_set_mirror_flip(ATK_MC5640_MIRROR_FLIP_1);
- ret += atk_mc5640_set_test_pattern(ATK_MC5640_TEST_PATTERN_OFF);
- ret += atk_mc5640_set_output_size(JPEG_OUTPUT_WIDTH, JPEG_OUTPUT_HEIGHT);
- if (ret != 0)
- {
- printf("ATK-MC5640 init failed!\r\n");
- ErrLight();
- }
-
-
- while (1)
- {
- p_jpeg_buf = (uint8_t *)g_jpeg_buf;
- jpeg_len = JPEG_BUF_SIZE / (sizeof(uint32_t));
-
- memset((void *)g_jpeg_buf, 0, JPEG_BUF_SIZE);
-
- atk_mc5640_get_frame((uint32_t)g_jpeg_buf, ATK_MC5640_GET_TYPE_DTS_32B_INC, NULL);
-
- /*
- for (jpeg_start_index = UINT32_MAX, jpeg_index = 0; jpeg_index < JPEG_BUF_SIZE - 1; jpeg_index++)
- {
- if ((p_jpeg_buf[jpeg_index] == 0xFF) && (p_jpeg_buf[jpeg_index + 1] == 0xD8))
- {
- jpeg_start_index = jpeg_index;
- break;
- }
- }
- if (jpeg_start_index == UINT32_MAX)
- {
- continue;
- }
- */
-
- jpeg_start_index=0;
- for (jpeg_end_index = UINT32_MAX, jpeg_index = jpeg_start_index; jpeg_index < JPEG_BUF_SIZE - 1; jpeg_index++)
- {
- if ((p_jpeg_buf[jpeg_index] == 0xFF) && (p_jpeg_buf[jpeg_index + 1] == 0xD9))
- {
- jpeg_end_index = jpeg_index;
- break;
- }
- }
- if (jpeg_end_index == UINT32_MAX)
- {
- continue;
- }
- if(jpeg_end_index<=jpeg_start_index+10){
- continue;
- }
- jpeg_len = jpeg_end_index - jpeg_start_index + (sizeof(uint32_t) >> 1);
- send_image_data_via_uart(g_jpeg_buf, jpeg_len);
-
- Receivedata();
-
- //delay_ms(2);
- }
- }
复制代码
其中,atk_mw8266d_uart_send_data 函数是我根据atk_mw8266d_uart_printf函数改的,代码:
- void atk_mw8266d_uart_send_data(const uint8_t *data, uint16_t len)
- {
- HAL_UART_Transmit(&g_uart_handle, data, len, HAL_MAX_DELAY);
- }
复制代码
我还把发送缓冲区大小ATK_MW8266D_UART_TX_BUF_SIZE从默认的64改成了64000,但是不知道为什么摄像头软件调试卡顿明显
还有一个不明白的地方就是,esp8266可以正常连接到网络调试助手或者网络摄像头软件创建的tcp service,但是我自己用nodejs创建的tcp service,就无法连接上
已经确认node代码创建的tcp service没问题,这个service可以被网络调试助手作为client正常连接
这个是tcp service的代码:
- const net = require('net');
- let PORT = '8080';
- let HOST = '192.168.37.84';
- const server = net.createServer((socket) => {
- socket.on('data', (data) => {
- console.log('接收到的数据:', data.toString());
- });
- socket.on('end', () => {
- console.log('STM32已断开连接');
- });
- socket.on('error', (err) => {
- console.error('连接错误:', err);
- });
- });
- server.listen(PORT, HOST, () => {
- console.log(`服务器运行在 http://${HOST}:${PORT}`);
- });
复制代码
|
|