当前位置:网站首页>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.
边栏推荐
- GFS distributed file system
- [机缘参悟-38]:鬼谷子-第五飞箝篇 - 警示之一:有一种杀称为“捧杀”
- Acwing第 58 场周赛【完结】
- Elk log analysis system
- Idea inheritance relationship
- Missile interception -- UPC winter vacation training match
- The phenomenology of crypto world: Pioneer entropy
- SFTP cannot connect to the server # yyds dry goods inventory #
- Application and Optimization Practice of redis in vivo push platform
- Yuan universe also "real estate"? Multiple second-hand trading websites block metauniverse keywords
猜你喜欢

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

The most powerful new household god card of Bank of communications. Apply to earn 2100 yuan. Hurry up if you haven't applied!

Avoid material "minefields"! Play with super high conversion rate

Voice chip wt2003h4 B008 single chip to realize the quick design of intelligent doorbell scheme

Application and Optimization Practice of redis in vivo push platform

LeetCode 314. Binary tree vertical order traversal - Binary Tree Series Question 6

Apache build web host

Missile interception -- UPC winter vacation training match

"C zero foundation introduction hundred knowledge and hundred cases" (72) multi wave entrustment -- Mom shouted for dinner

Pytest (4) - test case execution sequence
随机推荐
ELFK部署
Hmi-32- [motion mode] add light panel and basic information column
Sqoop安装
Good documentation
Yolov5 model training and detection
TCP security of network security foundation
Pytest (4) - test case execution sequence
[Yu Yue education] National Open University spring 2019 0505-22t basic nursing reference questions
Open source SPL optimized report application coping endlessly
Azkaban安装部署
Serious bugs with lifted/nullable conversions from int, allowing conversion from decimal
The perfect car for successful people: BMW X7! Superior performance, excellent comfort and safety
丸子百度小程序详细配置教程,审核通过。
100 basic multiple choice questions of C language (with answers) 04
When the low alcohol race track enters the reshuffle period, how can the new brand break the three major problems?
Redis distributed lock, lock code logic
Hmi-30- [motion mode] the module on the right side of the instrument starts to write
Design of kindergarten real-time monitoring and control system
D3js notes
Kotlin - 协程 Coroutine