当前位置:网站首页>Use UDP to send a JPEG image, and UPD will convert it into the mat format of OpenCV after receiving it
Use UDP to send a JPEG image, and UPD will convert it into the mat format of OpenCV after receiving it
2022-07-05 02:43:00 【DSZS123】
Because the project needs to use udp Receive one jpeg The picture file of , And then use opencv Show it .
udp recvfrom after , It's a one-dimensional array .
because jpeg Is a compressed image file , Use it directly opencv Turn this one-dimensional array into Mat The format is incorrect .
resolvent :
The sender needs to use imencode function .
The receiving end needs to use imdecode function .
Now write only the receiver . The code is as follows :
int udp_socket_fd = socket(AF_INET,SOCK_DGRAM,0);
if(udp_socket_fd < 0 )
{
perror("creat socket fail\n");
return -1;
}
struct sockaddr_in local_addr = {0};
local_addr.sin_family = AF_INET; // Use IPv4 agreement
local_addr.sin_port = htons(12349); // Network communication uses big end format
local_addr.sin_addr.s_addr = INADDR_ANY;// Let the system detect the local network card , Auto bind local IP
ret = bind(udp_socket_fd,(struct sockaddr*)&local_addr,sizeof(local_addr));
if(ret < 0)
{
perror("bind fail:");
close(udp_socket_fd);
return -1;
}
else
{
printf("recv ready!!!\n");
}
struct sockaddr_in src_addr = {0}; // For storing each other ( The sender of the message ) Of IP Address information
socklen_t len = sizeof(src_addr); // The size of the address information
char buf[1024*100] = {0};// Message buffer
ret = recvfrom(udp_socket_fd, buf, sizeof(buf), 0, (struct sockaddr *)&src_addr, &len);
if(ret == -1)
{
}
vector<unsigned char> buff;
for(int i=0;i<ret;i++)
{
buff.push_back(buf[i]);
}
cv::Mat show=imdecode(buff,CV_LOAD_IMAGE_COLOR);This code bit sends the received buf Array (jpep The picture data of ), Turn into Mat show.
边栏推荐
- 问题解决:AttributeError: ‘NoneType‘ object has no attribute ‘append‘
- 【微服务|SCG】Filters的33种用法
- February database ranking: how long can Oracle remain the first?
- LeetCode --- 1071. Great common divisor of strings problem solving Report
- 打破信息茧房-我主动获取信息的方法 -#3
- Erreur de type de datagramme MySQL en utilisant Druid
- Linux安装Redis
- D3js notes
- 返回二叉树中两个节点的最低公共祖先
- Apache build web host
猜你喜欢

Icu4c 70 source code download and compilation (win10, vs2022)

A label making navigation bar

Design and implementation of campus epidemic prevention and control system based on SSM

Exploration of short text analysis in the field of medical and health (I)

Missile interception -- UPC winter vacation training match

this+闭包+作用域 面试题

Apache Web page security optimization
![Hmi-32- [motion mode] add light panel and basic information column](/img/9c/0b25c0a41758652848aed2a269880f.jpg)
Hmi-32- [motion mode] add light panel and basic information column

Openresty ngx Lua Execution stage

2021 Li Hongyi machine learning (2): pytorch
随机推荐
【LeetCode】106. Construct binary tree from middle order and post order traversal sequence (wrong question 2)
Six stone programming: advantages of automated testing
Good documentation
Redis distributed lock, lock code logic
Comparison of advantages and disadvantages between platform entry and independent deployment
When the low alcohol race track enters the reshuffle period, how can the new brand break the three major problems?
D3js notes
Design of KTV intelligent dimming system based on MCU
[uc/os-iii] chapter 1.2.3.4 understanding RTOS
Hmi-31- [motion mode] solve the problem of picture display of music module
Yyds dry goods inventory intelligent fan based on CC2530 design
Exploration of short text analysis in the field of medical and health (II)
Design and implementation of campus epidemic prevention and control system based on SSM
GFS distributed file system
Avoid material "minefields"! Play with super high conversion rate
【LeetCode】222. The number of nodes of a complete binary tree (2 mistakes)
Application and Optimization Practice of redis in vivo push platform
【LeetCode】111. Minimum depth of binary tree (2 brushes of wrong questions)
[Yu Yue education] National Open University spring 2019 0505-22t basic nursing reference questions
Zabbix