当前位置:网站首页>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.
边栏推荐
- Icu4c 70 source code download and compilation (win10, vs2022)
- openresty ngx_ Lua execution phase
- Application and Optimization Practice of redis in vivo push platform
- Practical case of SQL optimization: speed up your database
- [Yu Yue education] National Open University spring 2019 0505-22t basic nursing reference questions
- A label colorful navigation bar
- The database and recharge are gone
- The phenomenology of crypto world: Pioneer entropy
- Acwing第 58 场周赛【完结】
- College Students' innovation project management system
猜你喜欢

The perfect car for successful people: BMW X7! Superior performance, excellent comfort and safety

Naacl 2021 | contrastive learning sweeping text clustering task

Yolov5 model training and detection

The perfect car for successful people: BMW X7! Superior performance, excellent comfort and safety

Character painting, I use characters to draw a Bing Dwen Dwen

8. Commodity management - commodity classification

Chinese natural language processing, medical, legal and other public data sets, sorting and sharing

Pytest (5) - assertion

A tab Sina navigation bar

Write a thread pool by hand, and take you to learn the implementation principle of ThreadPoolExecutor thread pool
随机推荐
丸子百度小程序详细配置教程,审核通过。
Advanced learning of MySQL -- Application -- Introduction
Breaking the information cocoon - my method of actively obtaining information - 3
Good documentation
d3js小记
Leetcode takes out the least number of magic beans
Problem solving: attributeerror: 'nonetype' object has no attribute 'append‘
Cut! 39 year old Ali P9, saved 150million
Pytest (4) - test case execution sequence
Video display and hiding of imitation tudou.com
Apache build web host
Official announcement! The third cloud native programming challenge is officially launched!
openresty ngx_lua執行階段
【微服务|SCG】Filters的33种用法
Yyds dry goods inventory intelligent fan based on CC2530 design
Single line function*
Icu4c 70 source code download and compilation (win10, vs2022)
The perfect car for successful people: BMW X7! Superior performance, excellent comfort and safety
【LeetCode】501. Mode in binary search tree (2 wrong questions)
Missile interception -- UPC winter vacation training match