虚拟机调用摄像头设备一直 select timeout问题的解决

在VMware里面调用v4l2-ctl捕获图像,或者opencv的VideoCapture(0)捕获图像,或者直接调用v4l2的函数,在streamon后,调用select读取数据,均会一直提示select timeout的问题,大概率是由于USB版本的兼容性造成的,做如下设置基本能够解决。

另外,附上一个完整的例子:

/**  V4L2 video capture example*** This program is a plus version of program provided with the V4L2 API* * dotphoenix@qq.com* */#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <assert.h>#include <getopt.h>             /* getopt_long() */#include <fcntl.h>              /* low-level i/o */
#include <unistd.h>
#include <errno.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <sys/time.h>
#include <sys/mman.h>
#include <sys/ioctl.h>
#include <stdarg.h>
#include <unistd.h>
#include <time.h>
#include <linux/videodev2.h>//gcc -g -Wall -o capture_v4l2 capture_v4l2.clogger//Synsynchronization is not considered///typedef struct {FILE * (*fopen)(char const * const filename, char const * const mode);int (*fprintf)(FILE *fp, char const * const fmt, ...);int (*vfprintf)(FILE *fp, char const * const fmt, va_list argp);int (*fclose)(FILE* fp);
} std_file_t;void std_file_init(std_file_t * const std_file) {std_file->fopen = fopen;std_file->fprintf = fprintf;std_file->vfprintf = vfprintf;std_file->fclose = fclose;
}typedef enum {OFF,DEBUG,INFO,WARNING,ERROR
} logger_level_t;typedef struct {logger_level_t level;int write_to_file ;FILE *fp;std_file_t *std_file;
} logger_t;static logger_t* logger;static void logger_format_current_time(char* ts) {time_t rawtime;struct tm *info;time( &rawtime );info = localtime( &rawtime );strftime(ts, 80, "%Y-%m-%d %H:%M:%S", info);
}static const char* logger_format_level(int level) {switch (level){case DEBUG:return "[DEBUG]";case INFO:return "[INFO]";case WARNING:return "[WARNING]";case ERROR:return "[ERROR]";                                        default:return "[UNKNOWN]";}
}void logger_log(logger_level_t const level, char const * const file, size_t const line, char const * const fmt, ...) {if (level < logger->level) {return;}char ts[64] = {0};logger_format_current_time(ts);logger->std_file->fprintf(logger->fp, "%s %s %s: %lu: ", logger_format_level(level), ts, file, line);va_list argp;va_start(argp, fmt);logger->std_file->vfprintf(logger->fp, fmt, argp);va_end(argp);    logger->std_file->fprintf(logger->fp, "\n");
}#define log_debug(...) logger_log(DEBUG, __FILE__, __LINE__, __VA_ARGS__)
#define log_info(...)  logger_log(INFO, __FILE__, __LINE__, __VA_ARGS__)
#define log_warn(...)  logger_log(WARNING, __FILE__, __LINE__, __VA_ARGS__)
#define log_error(...) logger_log(ERROR, __FILE__, __LINE__, __VA_ARGS__)static int logger_init(logger_level_t const level, char const * const filename, int const write_to_file
) {std_file_t* std_file = (std_file_t*)malloc(sizeof(std_file_t));logger = (logger_t*)malloc(sizeof(logger_t));std_file_init(std_file);logger->level = level;logger->write_to_file = write_to_file;logger->std_file = std_file;if (logger->write_to_file) {logger->fp = logger->std_file->fopen(filename, "a");if (logger->fp == NULL) {fprintf(stderr, "append log file %s failed, error %d, %s\n", filename, errno, strerror(errno));return -1;}} else {logger->fp = stderr;}char ts[128] = {0};logger_format_current_time(ts);strcat(ts, "   start new logger -------------------\n");log_warn(ts);return 0;
}void logger_uninit() {if(logger == NULL) {return;}if(logger->write_to_file) {if(logger->fp != NULL) {logger->std_file->fclose(logger->fp);logger->fp = NULL;}}free(logger->std_file);free(logger);
}//
#define CLEAR(x) memset(&(x), 0, sizeof(x))enum io_method_t {IO_METHOD_READ,IO_METHOD_MMAP,IO_METHOD_USERPTR,
};struct buffer_t {void   *start;size_t  length;
};static char            *dev_name;
static enum io_method_t   io_method =  IO_METHOD_MMAP;
static int              fd = -1;
struct buffer_t          *buffers;
static unsigned int     n_buffers;
static int              save_to_file = 1; //save to file
static int              force_format_yuyv = 1; //force to use yuyv format
static int              force_format_mjpeg = 0;//force to use mjpeg 
static int              frame_count = 30 * 2; //total save frame count
static int req_width = 640;
static int req_height = 480;
static int req_rate_numerator   = 30;
static int req_rate_denominator = 1;static int              frame_index = 0;static void errno_exit(const char *s)
{fprintf(stderr, "%s error %d, %s\n", s, errno, strerror(errno));log_error("%s error %d, %s\n", s, errno, strerror(errno));logger_uninit();exit(EXIT_FAILURE);
}static void general_exit_v(char const * const fmt, ...)
{char msg[512] = {0};va_list argp;va_start(argp, fmt);vsprintf(msg, fmt, argp);va_end(argp); strcat(msg, "\n");fprintf(stderr, "%s", msg);log_error(msg);logger_uninit();exit(EXIT_FAILURE);      
}static int xioctl(int fh, int request, void *arg)
{int r;do {r = ioctl(fh, request, arg);} while (-1 == r && EINTR == errno);return r;
}static void generate_save_to_fullpath(char* fullpath, const char*postfix, int file_index)
{char cwd[256] = {0};getcwd(cwd, 255);sprintf(fullpath, "%s/pictures/%06d.%s", cwd, file_index, postfix);
}static void process_image(const void *p, int size)
{frame_index++;//mark one frame on the consolefprintf(stderr, ".");fflush(stderr);if(save_to_file == 1) {char fullpath[128] = {0};if(force_format_mjpeg == 1) {generate_save_to_fullpath(fullpath, "jpg", frame_index);}else {generate_save_to_fullpath(fullpath, "yuyv", frame_index);}FILE *fp = fopen(fullpath, "wb");if(fp == NULL) {fprintf(stderr, "create file failed, file %s, error %d, %s\n", fullpath, errno, strerror(errno));log_error("create file failed, file %s, error %d, %s\n", fullpath, errno, strerror(errno));return;   } else {fwrite(p, size, 1, fp);fflush(fp);fclose(fp);log_debug("one frame coming and save to file, size=%d, path=%s \n", size, fullpath);}}else {log_debug("one frame coming and not save to file, size=%d \n", size);}}static int read_frame(void)
{struct v4l2_buffer buf;unsigned int i;switch (io_method) {case IO_METHOD_READ:if (-1 == read(fd, buffers[0].start, buffers[0].length)) {switch (errno) {case EAGAIN:return 0;case EIO:/* Could ignore EIO, see spec. *//* fall through */default:errno_exit("read");}}process_image(buffers[0].start, buffers[0].length);break;case IO_METHOD_MMAP:CLEAR(buf);buf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;buf.memory = V4L2_MEMORY_MMAP;if (-1 == xioctl(fd, VIDIOC_DQBUF, &buf)) {switch (errno) {case EAGAIN:return 0;case EIO:/* Could ignore EIO, see spec. *//* fall through */default:errno_exit("VIDIOC_DQBUF");}}assert(buf.index < n_buffers);process_image(buffers[buf.index].start, buf.bytesused);if (-1 == xioctl(fd, VIDIOC_QBUF, &buf))errno_exit("VIDIOC_QBUF");break;case IO_METHOD_USERPTR:CLEAR(buf);buf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;buf.memory = V4L2_MEMORY_USERPTR;if (-1 == xioctl(fd, VIDIOC_DQBUF, &buf)) {switch (errno) {case EAGAIN:return 0;case EIO:/* Could ignore EIO, see spec. *//* fall through */default:errno_exit("VIDIOC_DQBUF");}}for (i = 0; i < n_buffers; ++i)if (buf.m.userptr == (unsigned long)buffers[i].start&& buf.length == buffers[i].length)break;assert(i < n_buffers);process_image((void *)buf.m.userptr, buf.bytesused);if (-1 == xioctl(fd, VIDIOC_QBUF, &buf))errno_exit("VIDIOC_QBUF");break;}return 1;
}static void mainloop(void)
{unsigned int count;count = frame_count;while (count-- > 0) {for (;;) {fd_set fds;struct timeval tv;int r;FD_ZERO(&fds);FD_SET(fd, &fds);/* Timeout. */tv.tv_sec = 30;tv.tv_usec = 0;r = select(fd + 1, &fds, NULL, NULL, &tv);if (-1 == r) {if (EINTR == errno)continue;errno_exit("select");}if (0 == r) {general_exit_v("select timeout");}if (read_frame())break;/* EAGAIN - continue select loop. */}}
}static void stop_capturing(void)
{enum v4l2_buf_type type;switch (io_method) {case IO_METHOD_READ:/* Nothing to do. */break;case IO_METHOD_MMAP:case IO_METHOD_USERPTR:type = V4L2_BUF_TYPE_VIDEO_CAPTURE;if (-1 == xioctl(fd, VIDIOC_STREAMOFF, &type))errno_exit("VIDIOC_STREAMOFF");break;}
}static void start_capturing(void)
{unsigned int i;enum v4l2_buf_type type;switch (io_method) {case IO_METHOD_READ:/* Nothing to do. */break;case IO_METHOD_MMAP:for (i = 0; i < n_buffers; ++i) {struct v4l2_buffer buf;CLEAR(buf);buf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;buf.memory = V4L2_MEMORY_MMAP;buf.index = i;if (-1 == xioctl(fd, VIDIOC_QBUF, &buf))errno_exit("VIDIOC_QBUF");}type = V4L2_BUF_TYPE_VIDEO_CAPTURE;if (-1 == xioctl(fd, VIDIOC_STREAMON, &type))errno_exit("VIDIOC_STREAMON");log_info("%s stream on", dev_name);break;case IO_METHOD_USERPTR:for (i = 0; i < n_buffers; ++i) {struct v4l2_buffer buf;CLEAR(buf);buf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;buf.memory = V4L2_MEMORY_USERPTR;buf.index = i;buf.m.userptr = (unsigned long)buffers[i].start;buf.length = buffers[i].length;if (-1 == xioctl(fd, VIDIOC_QBUF, &buf))errno_exit("VIDIOC_QBUF");}type = V4L2_BUF_TYPE_VIDEO_CAPTURE;if (-1 == xioctl(fd, VIDIOC_STREAMON, &type))errno_exit("VIDIOC_STREAMON");log_info("%s stream on", dev_name);break;}
}static void uninit_device(void)
{unsigned int i;switch (io_method) {case IO_METHOD_READ:free(buffers[0].start);break;case IO_METHOD_MMAP:for (i = 0; i < n_buffers; ++i)if (-1 == munmap(buffers[i].start, buffers[i].length))errno_exit("munmap");break;case IO_METHOD_USERPTR:for (i = 0; i < n_buffers; ++i)free(buffers[i].start);break;}free(buffers);
}static void init_read(unsigned int buffer_size)
{buffers = calloc(1, sizeof(*buffers));if (!buffers) {general_exit_v("Out of memory");}buffers[0].length = buffer_size;buffers[0].start = malloc(buffer_size);if (!buffers[0].start) {general_exit_v("Out of memory");}log_info("initialize read&write method of %s successfully");
}static void init_mmap(void)
{struct v4l2_requestbuffers req;CLEAR(req);req.count = 8;req.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;req.memory = V4L2_MEMORY_MMAP;if (-1 == xioctl(fd, VIDIOC_REQBUFS, &req)) {if (EINVAL == errno) {general_exit_v("%s does not support ""memory mappingn", dev_name);} else {errno_exit("VIDIOC_REQBUFS");}}if (req.count < 2) {general_exit_v("Insufficient buffer_t memory on %s", dev_name);}buffers = calloc(req.count, sizeof(*buffers));if (!buffers) {general_exit_v("Out of memory");}for (n_buffers = 0; n_buffers < req.count; ++n_buffers) {struct v4l2_buffer buf;CLEAR(buf);buf.type        = V4L2_BUF_TYPE_VIDEO_CAPTURE;buf.memory      = V4L2_MEMORY_MMAP;buf.index       = n_buffers;if (-1 == xioctl(fd, VIDIOC_QUERYBUF, &buf))errno_exit("VIDIOC_QUERYBUF");buffers[n_buffers].length = buf.length;buffers[n_buffers].start =mmap(NULL /* start anywhere */,buf.length,PROT_READ | PROT_WRITE /* required */,MAP_SHARED /* recommended */,fd, buf.m.offset);if (MAP_FAILED == buffers[n_buffers].start)errno_exit("mmap");}log_info("initialize mmap method of %s successfully", dev_name);}static void init_userp(unsigned int buffer_size)
{struct v4l2_requestbuffers req;CLEAR(req);req.count  = 4;req.type   = V4L2_BUF_TYPE_VIDEO_CAPTURE;req.memory = V4L2_MEMORY_USERPTR;if (-1 == xioctl(fd, VIDIOC_REQBUFS, &req)) {if (EINVAL == errno) {general_exit_v("%s does not support user pointer i/o", dev_name);} else {errno_exit("VIDIOC_REQBUFS");}}buffers = calloc(4, sizeof(*buffers));if (!buffers) {general_exit_v("Out of memory");}for (n_buffers = 0; n_buffers < 4; ++n_buffers) {buffers[n_buffers].length = buffer_size;buffers[n_buffers].start = malloc(buffer_size);if (!buffers[n_buffers].start) {general_exit_v("Out of memory");}}log_info("initialize userp method of %s successfully", dev_name);}static int check_fmt(int fd, __u32 fmt) 
{struct v4l2_format v4l2_fmt;CLEAR(v4l2_fmt);v4l2_fmt.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;if (ioctl (fd, VIDIOC_G_FMT, &v4l2_fmt) == -1) {log_error("ERROR camera VIDIOC_G_FMT Failed.");return -1;}if (v4l2_fmt.fmt.pix.pixelformat == fmt) {return 1;}else {log_error("ERROR camera VIDIOC_S_FMT Failed, %u vs %u.", v4l2_fmt.fmt.pix.pixelformat, fmt);return -1;}
}static void init_device(void)
{struct v4l2_capability cap;struct v4l2_cropcap cropcap;struct v4l2_crop crop;struct v4l2_format fmt;struct v4l2_streamparm streamparm;unsigned int min;if (-1 == xioctl(fd, VIDIOC_QUERYCAP, &cap)) {if (EINVAL == errno) {general_exit_v("%s is no V4L2 device", dev_name);} else {errno_exit("VIDIOC_QUERYCAP");}}if (!(cap.capabilities & V4L2_CAP_VIDEO_CAPTURE)) {general_exit_v("%s is no video capture device",dev_name);}switch (io_method) {case IO_METHOD_READ:if (!(cap.capabilities & V4L2_CAP_READWRITE)) {general_exit_v("%s does not support read i/o",dev_name);}log_info("%s supports read and write", dev_name);break;case IO_METHOD_MMAP:case IO_METHOD_USERPTR:if (!(cap.capabilities & V4L2_CAP_STREAMING)) {general_exit_v("%s does not support streaming i/o",dev_name);}log_info("%s supports streaming", dev_name);break;}/* Select video input, video standard and tune here. */CLEAR(cropcap);cropcap.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;if (0 == xioctl(fd, VIDIOC_CROPCAP, &cropcap)) {crop.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;crop.c = cropcap.defrect; /* reset to default */if (-1 == xioctl(fd, VIDIOC_S_CROP, &crop)) {switch (errno) {case EINVAL:/* Cropping not supported. */break;default:/* Errors ignored. */break;}}} else {/* Errors ignored. */}CLEAR(streamparm);streamparm.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;if (-1 == xioctl(fd, VIDIOC_G_PARM, &streamparm))errno_exit("VIDIOC_G_PARM");if (streamparm.parm.capture.capability & V4L2_CAP_TIMEPERFRAME) {struct v4l2_fract *tpf = &(streamparm.parm.capture.timeperframe);// Swap numerator and denominator: rate is an inverted frame time :-)tpf->numerator = req_rate_denominator;tpf->denominator = req_rate_numerator;if (-1 == xioctl(fd, VIDIOC_S_PARM, &streamparm))errno_exit("VIDIOC_S_PARM");if (tpf->numerator != req_rate_denominator ||tpf->denominator != req_rate_numerator) {log_error( "the driver changed the time per frame from ""%d/%d to %d/%d failed",req_rate_denominator, req_rate_numerator,tpf->numerator, tpf->denominator);}else {log_info( "the driver changed the time per frame from ""%d/%d to %d/%d successfully",req_rate_denominator, req_rate_numerator,tpf->numerator, tpf->denominator);}} else {log_error("the driver does not allow to change time per frame");}CLEAR(fmt);fmt.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;if (force_format_yuyv) {fmt.fmt.pix.width       = req_width;fmt.fmt.pix.height      = req_height;fmt.fmt.pix.pixelformat = V4L2_PIX_FMT_YUYV;fmt.fmt.pix.field       = V4L2_FIELD_ANY;if (-1 == xioctl(fd, VIDIOC_S_FMT, &fmt))errno_exit("VIDIOC_S_FMT");assert(check_fmt(fd, V4L2_PIX_FMT_YUYV) == 1);log_info("set format of %s to %u successfully", dev_name, fmt.fmt.pix.pixelformat);/* Note VIDIOC_S_FMT may change width and height. */} else if (force_format_mjpeg) {fmt.fmt.pix.width       = req_width;fmt.fmt.pix.height      = req_height;fmt.fmt.pix.pixelformat = V4L2_PIX_FMT_MJPEG;fmt.fmt.pix.field       = V4L2_FIELD_ANY;if (-1 == xioctl(fd, VIDIOC_S_FMT, &fmt))errno_exit("VIDIOC_S_FMT");assert(check_fmt(fd, V4L2_PIX_FMT_MJPEG) == 1);log_info("set format of %s to %u successfully", dev_name, fmt.fmt.pix.pixelformat);/* Note VIDIOC_S_FMT may change width and height. */} else {/* Preserve original settings as set by v4l2-ctl for example */if (-1 == xioctl(fd, VIDIOC_G_FMT, &fmt))errno_exit("VIDIOC_G_FMT");log_info("format of %s is %u ", dev_name, fmt.fmt.pix.pixelformat);}/* Buggy driver paranoia. */min = fmt.fmt.pix.width * 2;if (fmt.fmt.pix.bytesperline < min)fmt.fmt.pix.bytesperline = min;min = fmt.fmt.pix.bytesperline * fmt.fmt.pix.height;if (fmt.fmt.pix.sizeimage < min)fmt.fmt.pix.sizeimage = min;switch (io_method) {case IO_METHOD_READ:init_read(fmt.fmt.pix.sizeimage);break;case IO_METHOD_MMAP:init_mmap();break;case IO_METHOD_USERPTR:init_userp(fmt.fmt.pix.sizeimage);break;}
}static void close_device(void)
{if (-1 == close(fd))errno_exit("close");fd = -1;
}static void open_device(void)
{struct stat st;if (-1 == stat(dev_name, &st)) {general_exit_v("Cannot identify device '%s': %d, %s",dev_name, errno, strerror(errno));}if (!S_ISCHR(st.st_mode)) {general_exit_v("%s is no device", dev_name);}fd = open(dev_name, O_RDWR /* required */ | O_NONBLOCK, 0);if (-1 == fd) {general_exit_v("Cannot open '%s': %d, %s",dev_name, errno, strerror(errno));}else {log_info("Open device %s successfully.", dev_name);}
}static void usage(FILE *fp, int argc, char **argv)
{fprintf(fp,"Usage: %s [options]\\n\\n""Version 1.3\\n""Options:\\n""-d | --device name   Video device name [%s]n""-h | --help          Print this messagen""-m | --mmap          Use memory mapped buffers [default]n""-r | --read          Use read() callsn""-u | --userp         Use application allocated buffersn""-s | --save          Save stream to file""-f | --format        Force format to 640x480 YUYVn""-c | --count         Number of frames to grab [%i]n""",argv[0], dev_name, frame_count);
}static const char short_options[] = "d:hmruofc:";static const struct option
long_options[] = {{ "device", required_argument, NULL, 'd' },{ "help",   no_argument,       NULL, 'h' },{ "mmap",   no_argument,       NULL, 'm' },{ "read",   no_argument,       NULL, 'r' },{ "userp",  no_argument,       NULL, 'u' },{ "save", no_argument,         NULL, 's' },{ "format", no_argument,       NULL, 'f' },{ "count",  required_argument, NULL, 'c' },{ 0, 0, 0, 0 }
};int main(int argc, char **argv)
{dev_name = "/dev/video0";char log_filename[256] = {0};char cwd[256] = {0};getcwd(cwd, 255);sprintf(log_filename, "%s/v4l2_log.txt", cwd);logger_init(DEBUG, log_filename, 1);for (;;) {int idx;int c;c = getopt_long(argc, argv,short_options, long_options, &idx);if (-1 == c)break;switch (c) {case 0: /* getopt_long() flag */break;case 'd':dev_name = optarg;break;case 'h':usage(stdout, argc, argv);exit(EXIT_SUCCESS);case 'm':io_method = IO_METHOD_MMAP;break;case 'r':io_method = IO_METHOD_READ;break;case 'u':io_method = IO_METHOD_USERPTR;break;case 's':save_to_file = 1;break;case 'j':force_format_mjpeg = 1;break;case 'n':force_format_yuyv = 1;break;case 'y':errno = 0;frame_count = strtol(optarg, NULL, 0);if (errno)errno_exit(optarg);break;default:usage(stderr, argc, argv);exit(EXIT_FAILURE);}}open_device();init_device();start_capturing();mainloop();stop_capturing();uninit_device();close_device();logger_uninit(&logger);return 0;
}

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.rhkb.cn/news/346033.html

如若内容造成侵权/违法违规/事实不符,请联系长河编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

每日5题Day21 - LeetCode 101 - 105

每一步向前都是向自己的梦想更近一步&#xff0c;坚持不懈&#xff0c;勇往直前&#xff01; 第一题&#xff1a;101. 对称二叉树 - 力扣&#xff08;LeetCode&#xff09; class Solution {public boolean isSymmetric(TreeNode root) {if(root null){return true;}Stack<…

类和对象(下+)_const成员、初始化列表、友元、匿名对象

类和对象&#xff08;下&#xff09; 文章目录 类和对象&#xff08;下&#xff09;前言一、const成员二、友元1.友元函数2.友元类 三、初始化列表四、explicit关键字五、匿名对象总结 前言 static成员、内部类、const成员、初始化列表、友元、匿名对象 一、const成员 将cons…

网络安全难学吗?2024该怎么系统学习网络安全?

学习网络安全需要循序渐进&#xff0c;由浅入深。很多人对网络安全进行了解以后&#xff0c;就打算开始学习网络安全&#xff0c;但是又不知道怎么去系统的学习。 网络安全本身的知识不难&#xff0c;但需要学习的内容有很多&#xff0c;其中包括Linux、数据库、渗透测试、等保…

excel拖拽怎么使单元格序号不递增

拖拽下来不仅不递增&#xff0c;而且右下角没有倒三角可以设置改变&#xff0c;&#xff08;即没有下图这个&#xff09; 则&#xff0c;可以采用以下方法 excel数值拖拽不递增还有一个更快更快捷的方法&#xff0c;这就运用到了excel快捷键&#xff0c;我们把鼠标放到单元格的…

康谋技术 | 自动驾驶:揭秘高精度时间同步技术(二)

在自动驾驶中&#xff0c;对车辆外界环境进行感知需要用到很多传感器的数据&#xff08;Lidar&#xff0c;Camera&#xff0c;GPS/IMU&#xff09;&#xff0c;如果计算中心接收到的各传感器消息时间不统一&#xff0c;则会造成例如障碍物识别不准等问题。 为了对各类传感器进…

consul做配置中心

1. 分布式配置中心 consul不仅可做注册中心&#xff0c;还可做配置中心 applicaiton.yml与bootstrap.yml: applicaiton.yml是用户级的资源配置项bootstrap.yml是系统级的&#xff0c;优先级更加高 Spring Cloud会创建一个“Bootstrap Context”&#xff0c;作为Spring应用…

ReactRouter——路由配置、路由跳转、带参跳转、新route配置项

目录 写在前面 (一)初步使用router 1.安装react-router-dom 2.创建router结构 3.嵌套路由 4.配置not found页面 (1)确切路由报错页面 (2)未配置路由报错页面 5.重定向 (二)路由跳转 1.组件跳转 2.NavLink 3.js跳转 (三)传递参数 1.searchParams(query)参数 2…

kafka集成SpringBoot api编写教程

1.新建项目 用的idea是20222.1.3版本&#xff0c;没有Spring Initializr 插件&#xff0c;不能直接创建springboot项目 可以在以下网址创建项目&#xff0c;下载后解压&#xff0c;然后用idea打开项目即可 1.1 在 https://start.spring.io/ 上创建项目 1.2上传到linux&#x…

10.2 Go Channel

&#x1f49d;&#x1f49d;&#x1f49d;欢迎莅临我的博客&#xff0c;很高兴能够在这里和您见面&#xff01;希望您在这里可以感受到一份轻松愉快的氛围&#xff0c;不仅可以获得有趣的内容和知识&#xff0c;也可以畅所欲言、分享您的想法和见解。 推荐:「stormsha的主页」…

Letcode-Top 100二叉树专题

94. 二叉树的中序遍历 方法一&#xff1a;递归法 /*** Definition for a binary tree node.* public class TreeNode {* int val;* TreeNode left;* TreeNode right;* TreeNode() {}* TreeNode(int val) { this.val val; }* TreeNode(int val, TreeN…

【python】在【机器学习】与【数据挖掘】中的应用:从基础到【AI大模型】

目录 &#x1f497;一、Python在数据挖掘中的应用&#x1f495; &#x1f496;1.1 数据预处理&#x1f49e; &#x1f496;1.2 特征工程&#x1f495; &#x1f497;二、Python在机器学习中的应用&#x1f495; &#x1f496;2.1 监督学习&#x1f49e; &#x1f496;2.2…

第1章Hello world 3/5:Cargo.lock:确保构建稳定可靠:运行第一个程序

讲动人的故事,写懂人的代码 1.6 Cargo.lock:确保构建稳定可靠 “看!”席双嘉一边指着屏幕一边说,“终端窗口提示符的颜色,从绿变黄了。这就意味着代码在上次提交后有点变化。” 赵可菲:“但是我们只是运行了程序,代码应该没动呀。” 席双嘉敲了下git status -uall,这…

计网总结☞网络层

.................................................. 思维导图 ........................................................... 【Wan口和Lan口】 WAN口&#xff08;Wide Area Network port&#xff09;&#xff1a; 1)用于连接外部网络&#xff0c;如互联…

SpringBoot学习笔记

总体思路&#xff1a;先写dao,再写service 1.https://start.spring.io 生成对应的模板 2.写TestCotroller类&#xff0c;类上写RestCotroller注解 3.TestCotroller类里写方法&#xff0c;方法上写GetMapping("/方法名")注解 4.不一定要写GetMapping,具体看做什么操…

MySQL从入门到高级 --- 15.优化 16.pymysql

文章目录 第十五章 && 第十六章&#xff1a;15.优化15.1 查询SQL执行效率15.2 定位低效率执行SQL15.3 explain分析执行计划 - 基本使用15.4 explain分析执行计划 - id15.5 explain分析执行计划 - select_type15.6 explain分析执行计划 - type15.7 explain分析执行计划 …

MySQL高性能(MySQL锁)

MySQL性能系列 MySQL锁 前言1. 死锁机制2. 思维导图与锁划分介绍3. 粒度划分锁3.1. 全局锁3.2. 页级锁&#xff08;Page-level locking&#xff09;3.3. 表级锁&#xff08;Tables-level lock&#xff09;○ 共享锁&#xff08;表级&#xff09;○ 排他锁&#xff08;表级&…

字节面试:CPU100% 如何处理?

尼恩说在前面 在40岁老架构师 尼恩的读者交流群(50)中&#xff0c;最近有小伙伴拿到了一线互联网企业如得物、阿里、滴滴、极兔、有赞、希音、百度、网易、美团的面试资格&#xff0c;遇到很多很重要的线上问题的场景题&#xff1a; 1.CPU100%&#xff0c;你是怎么处理的&…

jvm学习笔记(二) ----- 垃圾回收

GC 一、判定对象是否是垃圾1.引用计数法2.可达性分析算法 二、垃圾回收算法1.标记清除2.标记整理3. 复制4. 分代垃圾回收1.尝试在伊甸园分配2.大对象直接晋升至老年代3.多次存活的对象4.老年代连续空间不足&#xff0c;触发 Full GC 链接: jvm学习笔记(一) ----- JAVA 内存 链接…

C++程序设计:对数据文件的操作与文件流

姚老师小课堂开课啦&#xff01; 一、文件的分类&#xff1a; 1.ASCII码文件&#xff1a; ASCII文件使用方便&#xff0c;比较直观&#xff0c;便于阅读&#xff0c;便于对字符进行输入输出&#xff0c;但一般占用存储空间较多&#xff0c;而且需要花费转换时间&#xff08;二…

④-2单细胞学习-cellchat单数据代码补充版(通讯网络)

目录 通讯网络系统分析 ①社会网络分析 1&#xff0c;计算每个细胞群的网络中心性指标 2&#xff0c;识别细胞的信号流模式 ②非负矩阵分解&#xff08;NMF&#xff09;识别细胞的通讯模式 1&#xff0c;信号输出细胞的模式识别 2&#xff0c;信号输入细胞的模式识别 信…