Hi,我是二毛,一个在大城市漂泊的程序员

点击蓝字,一起变强

二毛是刚毕业的大学生,从学校这个象牙塔离开后独自一人来到大城市打拼,成为漂泊一族。

这些天他在找房的过程中,遇到过黑中介,走过潮湿阴暗的深巷子,看到过拥挤陈旧但却又贵的离谱的小黑屋...

就在他身心俱疲去看最后一套租房的时候,幸运之神眷顾了他,终于找到了本地房东出租的一套舒适阳光、价格良心的房了!二毛立刻高兴的签了这套租房。

今天是他搬进去的第一天...

欲知二毛将与二丫擦出怎么样的火花,且听下回分解。


    欢迎来到程序员二毛的世界,在这里你将走进程序员的生活,感受职场冷暖,体会生活感悟,并学习到有趣的编程技术。

    包括但不限于Linux、数据库、计算机网络、PHP、数据结构算法、设计模式、实用工具资源等。

    关注公众号《程序员二毛》,后台回复 1024 领取变强秘籍;点击“菜单栏-加群交流”可进入攻城狮交流群。

    聊技术,说认知,谈人生,也许吃瓜围观的你,离激情交流、碰撞思想,就差一句“PHP是世界上最好的语言”!

你“在看”我吗?

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
以下是一个用v4l2获取摄像头照片,udp实现传输功能的c语言代码: ```c #include <stdio.h> #include <stdlib.h> #include <string.h> #include <unistd.h> #include <fcntl.h> #include <errno.h> #include <sys/types.h> #include <sys/socket.h> #include <netinet/in.h> #include <arpa/inet.h> #include <linux/videodev2.h> #define CAMERA_DEVICE "/dev/video0" #define CAMERA_WIDTH 640 #define CAMERA_HEIGHT 480 #define CAMERA_FORMAT V4L2_PIX_FMT_YUYV #define UDP_PORT 8888 #define UDP_IP "127.0.0.1" int main(int argc, char *argv[]) { int camera_fd, udp_fd; struct v4l2_capability cap; struct v4l2_format fmt; struct v4l2_requestbuffers req; struct v4l2_buffer buf; struct sockaddr_in addr; char *buffer; int buffer_size; int i; // 打开摄像头设备 camera_fd = open(CAMERA_DEVICE, O_RDWR); if (camera_fd == -1) { perror("open camera device"); exit(EXIT_FAILURE); } // 查询摄像头设备属性 if (ioctl(camera_fd, VIDIOC_QUERYCAP, &cap) == -1) { perror("query camera device"); exit(EXIT_FAILURE); } // 设置摄像头格式 memset(&fmt, 0, sizeof(fmt)); fmt.type = V4L2_BUF_TYPE_VIDEO_CAPTURE; fmt.fmt.pix.width = CAMERA_WIDTH; fmt.fmt.pix.height = CAMERA_HEIGHT; fmt.fmt.pix.pixelformat = CAMERA_FORMAT; if (ioctl(camera_fd, VIDIOC_S_FMT, &fmt) == -1) { perror("set camera format"); exit(EXIT_FAILURE); } // 请求摄像头缓冲区 memset(&req, 0, sizeof(req)); req.count = 1; req.type = V4L2_BUF_TYPE_VIDEO_CAPTURE; req.memory = V4L2_MEMORY_MMAP; if (ioctl(camera_fd, VIDIOC_REQBUFS, &req) == -1) { perror("request camera buffer"); exit(EXIT_FAILURE); } // 映射摄像头缓冲区 buffer_size = fmt.fmt.pix.sizeimage; buffer = (char *)mmap(NULL, buffer_size, PROT_READ | PROT_WRITE, MAP_SHARED, camera_fd, 0); if (buffer == MAP_FAILED) { perror("map camera buffer"); exit(EXIT_FAILURE); } // 开始采集图像 memset(&buf, 0, sizeof(buf)); buf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE; buf.memory = V4L2_MEMORY_MMAP; buf.index = 0; if (ioctl(camera_fd, VIDIOC_QBUF, &buf) == -1) { perror("queue camera buffer"); exit(EXIT_FAILURE); } if (ioctl(camera_fd, VIDIOC_STREAMON, &buf.type) == -1) { perror("start camera stream"); exit(EXIT_FAILURE); } // 创建UDP套接字 udp_fd = socket(AF_INET, SOCK_DGRAM, 0); if (udp_fd == -1) { perror("create udp socket"); exit(EXIT_FAILURE); } // 设置UDP地址 memset(&addr, 0, sizeof(addr)); addr.sin_family = AF_INET; addr.sin_port = htons(UDP_PORT); addr.sin_addr.s_addr = inet_addr(UDP_IP); // 循环采集图像并发送到UDP套接字 for (i = 0; i < 100; i++) { // 从摄像头缓冲区中取出一帧图像 if (ioctl(camera_fd, VIDIOC_DQBUF, &buf) == -1) { perror("dequeue camera buffer"); exit(EXIT_FAILURE); } // 发送图像到UDP套接字 if (sendto(udp_fd, buffer, buffer_size, 0, (struct sockaddr *)&addr, sizeof(addr)) == -1) { perror("sendto udp socket"); exit(EXIT_FAILURE); } // 将图像放回摄像头缓冲区 if (ioctl(camera_fd, VIDIOC_QBUF, &buf) == -1) { perror("queue camera buffer"); exit(EXIT_FAILURE); } // 等待一段间 usleep(100000); } // 停止采集图像 if (ioctl(camera_fd, VIDIOC_STREAMOFF, &buf.type) == -1) { perror("stop camera stream"); exit(EXIT_FAILURE); } // 关闭UDP套接字 close(udp_fd); // 解除摄像头缓冲区映射 munmap(buffer, buffer_size); // 关闭摄像头设备 close(camera_fd); return 0; } ```
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值