当前位置:网站首页>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.
边栏推荐
- The perfect car for successful people: BMW X7! Superior performance, excellent comfort and safety
- Hmi-32- [motion mode] add light panel and basic information column
- [Yu Yue education] National Open University spring 2019 0505-22t basic nursing reference questions
- Character painting, I use characters to draw a Bing Dwen Dwen
- [understanding of opportunity -38]: Guiguzi - Chapter 5 flying clamp - warning one: there is a kind of killing called "killing"
- Last words record
- Flume配置4——自定义MYSQLSource
- spoon插入更新oracle数据库,插了一部分提示报错Assertion botch: negative time
- 看 TDengine 社区英雄线上发布会,听 TD Hero 聊开发者传奇故事
- SFTP cannot connect to the server # yyds dry goods inventory #
猜你喜欢
Scientific research: are women better than men?
Introduce reflow & repaint, and how to optimize it?
The perfect car for successful people: BMW X7! Superior performance, excellent comfort and safety
Tiny series rendering tutorial
Spark SQL learning bullet 2
"C zero foundation introduction hundred knowledge and hundred cases" (72) multi wave entrustment -- Mom shouted for dinner
【LeetCode】110. Balanced binary tree (2 brushes of wrong questions)
[技术发展-26]:新型信息与通信网络的数据安全
Azkaban安装部署
Naacl 2021 | contrastive learning sweeping text clustering task
随机推荐
The perfect car for successful people: BMW X7! Superior performance, excellent comfort and safety
Azkaban安装部署
Good documentation
[daily problem insight] Li Kou - the 280th weekly match (I really didn't know it could be so simple to solve other people's problems)
Using druid to connect to MySQL database reports the wrong type
Vb+access hotel service management system
Unpool(nn.MaxUnpool2d)
使用druid连接MySQL数据库报类型错误
Voice chip wt2003h4 B008 single chip to realize the quick design of intelligent doorbell scheme
The database and recharge are gone
Leetcode takes out the least number of magic beans
A label colorful navigation bar
Hmi-32- [motion mode] add light panel and basic information column
Which common ports should the server open
【LeetCode】111. Minimum depth of binary tree (2 brushes of wrong questions)
Write a thread pool by hand, and take you to learn the implementation principle of ThreadPoolExecutor thread pool
Six stone programming: advantages of automated testing
The most powerful new household god card of Bank of communications. Apply to earn 2100 yuan. Hurry up if you haven't applied!
[source code attached] Intelligent Recommendation System Based on knowledge map -sylvie rabbit
问题解决:AttributeError: ‘NoneType‘ object has no attribute ‘append‘