我正在玩ESP32-CAM。 我在这样的结构中将图像编码为jpg
typedef struct {
uint8_t * buf; /*!< Pointer to the pixel data */
size_t len; /*!< Length of the buffer in bytes */
size_t width; /*!< Width of the buffer in pixels */
size_t height; /*!< Height of the buffer in pixels */
pixformat_t format; /*!< Format of the pixel data */
struct timeval timestamp; /*!< Timestamp since boot of the first DMA buffer of the frame */
} camera_fb_t;
看起来原始图像数据似乎是一个uint8_t数组,这是很合理的。
我想通过Websocket连接发送此图像数据。二进制数据的发送函数具有以下语法
esp_websocket_client_send(client,(char *)fb->buf, 1000, portMAX_DELAY);
如果将指针格式从char更改为uint8_t,则会出现编译器错误。所以我正在使用上面的语法。似乎仍然可行,并且python websockets服务器接收某种数据。在python中,将数据打印到服务器终端后看起来像这样。
b'\xff\xd8\xff\xe0\x00\x10JFIF\x00\x01\x01\x0 etc.
我想知道是否以适当的数据格式发送二进制jpg数据?我的意思是,将uint8数组解释为char数组似乎有点奇怪。在发送之前,我应该对它进行编码吗?
答案 0 :(得分:0)
该“发送”功能不适用于二进制数据。
图像像素是二进制数据。
建议使用:
int esp_websocket_client_send_bin(esp_websocket_client_handle_t客户端,const char * data,int len,TickType_t超时)
还请注意:.jpg图片始终为512字节的倍数,因此长度应为512的倍数,而不是1000