当前位置:网站首页>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.
边栏推荐
- Which common ports should the server open
- [Yu Yue education] National Open University autumn 2018 8109-22t (1) monetary and banking reference questions
- d3js小记
- Eight days of learning C language - while loop (embedded) (single chip microcomputer)
- Structure of ViewModel
- Azkaban安装部署
- Yuan universe also "real estate"? Multiple second-hand trading websites block metauniverse keywords
- Design and practice of kubernetes cluster and application monitoring scheme
- Pytest (5) - assertion
- 返回二叉树中两个节点的最低公共祖先
猜你喜欢
openresty ngx_lua执行阶段
2021 Li Hongyi machine learning (2): pytorch
Exploration of short text analysis in the field of medical and health (I)
Avoid material "minefields"! Play with super high conversion rate
Write a thread pool by hand, and take you to learn the implementation principle of ThreadPoolExecutor thread pool
Design and practice of kubernetes cluster and application monitoring scheme
2021 Li Hongyi machine learning (3): what if neural network training fails
Hmi-31- [motion mode] solve the problem of picture display of music module
Spoon inserts and updates the Oracle database, and some prompts are inserted with errors. Assertion botch: negative time
Flume配置4——自定义MYSQLSource
随机推荐
Marubeni Baidu applet detailed configuration tutorial, approved.
Summary and practice of knowledge map construction technology
1.五层网络模型
Tiny series rendering tutorial
Can you really learn 3DMAX modeling by self-study?
Official announcement! The third cloud native programming challenge is officially launched!
Single line function*
2021 Li Hongyi machine learning (1): basic concepts
Prometheus monitors the correct posture of redis cluster
Open source SPL optimized report application coping endlessly
[source code attached] Intelligent Recommendation System Based on knowledge map -sylvie rabbit
[技术发展-26]:新型信息与通信网络的数据安全
Problem solving: attributeerror: 'nonetype' object has no attribute 'append‘
STL container
A label colorful navigation bar
The perfect car for successful people: BMW X7! Superior performance, excellent comfort and safety
Openresty ngx Lua Execution stage
Erreur de type de datagramme MySQL en utilisant Druid
A tab Sina navigation bar
【LeetCode】222. The number of nodes of a complete binary tree (2 mistakes)