虚拟机调用摄像头设备一直 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.mzph.cn/news/851348.shtml

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

相关文章

fs.1.10 ON rockylinux8 docker镜像制作

概述 freeswitch是一款简单好用的VOIP开源软交换平台。 rockylinux docker上编译安装fs1.10版本的流程记录。 环境 docker engine&#xff1a;Version 24.0.6 rockylinux docker&#xff1a;8 freeswitch&#xff1a;v1.10.7 手动模式 rockylinux准备 docker hub拉取r…

AI智能体做高考志愿填报分析

关注公众号&#xff0c;赠送AI/Python/Linux资料&#xff0c;对AI智能体有兴趣的朋友也可以添加一起交流 高考正在进行时&#xff0c;学生焦虑考试&#xff0c;家长们焦虑的则是高考志愿怎么填。毕竟一个好的学校&#xff0c;好的专业是进入社会的第一个敲门砖 你看张雪峰老师…

2024.6.10学习记录

1、代码随想录二刷 2、项目难点 review 3、计组复习

RabbitMQ-工作模式(Topics模式RPC模式Publisher Confirms模式)

文章目录 Topics模式topic代码示例 RPC模式客户端界面回调队列关联ID总结RPC代码示例 Publisher Confirms模式概述在通道上启用发布者确认单独发布消息批量发布消息异步处理发布者确认总结总体代码示例 更多相关内容可查看 Topics模式 在Topics中&#xff0c;发送的消息不能具…

目标检测算法YOLOv9简介

YOLOv9由Chien-Yao Wang等人于2024年提出&#xff0c;论文名为&#xff1a;《YOLOv9: Learning What You Want to Learn Using Programmable Gradient Information》&#xff0c;论文见&#xff1a;https://arxiv.org/pdf/2402.13616 &#xff1b;源码见: https://github.com/W…

一文带你轻松掌握Java数组定义和声明

哈喽&#xff0c;各位小伙伴们&#xff0c;你们好呀&#xff0c;我是喵手。运营社区&#xff1a;C站/掘金/腾讯云&#xff1b;欢迎大家常来逛逛 今天我要给大家分享一些自己日常学习到的一些知识点&#xff0c;并以文字的形式跟大家一起交流&#xff0c;互相学习&#xff0c;一…

Java_Map集合

认识Map集合 Map集合称为双列集合&#xff0c;格式&#xff1a;{key1value&#xff0c;key2value2,key3value3,…},一次需要存一对数据作为一个元素。 Map集合的每个元素“Keyvalue” 称为一个键值对/键值对对象/一个Entry对象&#xff0c;Map集合也被叫做“键值对集合” Map集…

Vue笔记(二)

Vue&#xff08;一&#xff09;&#xff1a;Vue笔记&#xff08;一&#xff09;-CSDN博客 综合案例&#xff1a;水果购物车 项目功能&#xff1a; 视频链接&#xff1a;034-水果购物车-基本渲染_哔哩哔哩_bilibili 目录结构&#xff1a; index.css .app-container {padding-…

已解决Error || RuntimeError: size mismatch, m1: [32 x 100], m2: [500 x 10]

已解决Error || RuntimeError: size mismatch, m1: [32 x 100], m2: [500 x 10] 原创作者&#xff1a; 猫头虎 作者微信号&#xff1a; Libin9iOak 作者公众号&#xff1a; 猫头虎技术团队 更新日期&#xff1a; 2024年6月6日 博主猫头虎的技术世界 &#x1f31f; 欢迎来…

第十一篇——信息增量:信息压缩中的保守主义原则

目录 一、背景介绍二、思路&方案三、过程1.思维导图2.文章中经典的句子理解3.学习之后对于投资市场的理解4.通过这篇文章结合我知道的东西我能想到什么&#xff1f; 四、总结五、升华 一、背景介绍 通过信息中的保守主义&#xff0c;我想到了现实中人的保守主义一样&#…

汇编语言作业(五)

目录 一、实验目的 二、实验内容 三、实验步骤以及结果 四、实验结果与分析 五、 实验总结 一、实验目的 1.熟悉掌握汇编语言的程序结构&#xff0c;能正确书写数据段、代码段等 2&#xff0c;利用debug功能&#xff0c;查看寄存器&#xff08;CS,IP,AX,DS..)及数据段的…

基于AI大文本模型的智慧对话开发设计及C#源码实现,实现智能文本改写与智慧对话

文章目录 1.AI 大模型发展现状2.基于AI服务的智慧对话开发2.1 大模型API选择2.2 基于C#的聊天界面开发2.3 星火大模型API接入2.4 优化开发界面与显示逻辑 3.源码工程Demo及相关软件下载参考文献 1.AI 大模型发展现状 端午假期几天&#xff0c;关注到国内的AI大模型厂商近乎疯狂…

计算机网络期末考试知识点(关键词:江中)

目录 大家端午节快乐呀&#xff01;又到了一年两度的期末考试月了&#xff0c;这里给大家整理了一些复习知识点&#xff0c;大家可以边吃粽子边复习&#xff0c;事半功倍哈哈哈。祝各位期末过&#xff01;过&#xff01;过&#xff01;。 1 第一章 计算机网络体系结构 计算机…

Kaggle -- Digit Recognizer 98.57%

使用卷积神经网络进行模型构建&#xff0c;代码如下&#xff1a; import pandas as pd import numpy as np import torch import torch.nn as nn import torch.optim as optim import torch.nn.functional as F from torch.utils.data import DataLoader, Dataset, random_spl…

【MySQL】聊聊唯一索引是如何加锁的

首先我们要明确&#xff0c;加锁的对象是索引&#xff0c;加锁的基本单位是next-key lock&#xff0c;由记录锁和间隙锁组成。next-key是前开后闭区间&#xff0c;间隙锁是前开后开区间。根据不同的查询条件next-key 可能会退化成记录锁或间隙锁。 在能使用记录锁或者间隙锁就…

电路防护-贴片陶瓷气体放电管

贴片陶瓷气体放电管 GDT工作原理GDT主要特性参数典型电路压敏电阻与 TVS 管的区别 GDT工作原理 陶瓷气体放电管是一种电子器件&#xff0c;其工作原理基于气体放电现象。这种管子的内部填充了一种特定的气体&#xff0c;通常是氖气或氩气。当管子两端施加足够的电压时&#xf…

vivado HW_ILA_DATA、HW_PROBE

HW_ILA_DATA 描述 硬件ILA数据对象是ILA调试核心上捕获的数据的存储库 编程到当前硬件设备上。upload_hw_ila_data命令 在从ila调试移动捕获的数据的过程中创建hw_ila_data对象 核心&#xff0c;hw_ila&#xff0c;在物理FPGA上&#xff0c;hw_device。 read_hw_ila_data命令还…

nginx优化与防盗链【☆☆☆】

目录 一、用户层面的优化 1、隐藏版本号 方法一&#xff1a;修改配置文件 方法二&#xff1a;修改源码文件&#xff0c;重新编译安装 2、修改nginx用户与组 3、配置nginx网页缓存时间 4、nginx的日志切割 5、配置nginx实现连接超时 6、更改nginx运行进程数 7、开启网…

1 c++多线程创建和传参

什么是进程&#xff1f; 系统资源分配的最小单位。 什么是线程&#xff1f; 操作系统调度的最小单位&#xff0c;即程序执行的最小单位。 为什么需要多线程&#xff1f; &#xff08;1&#xff09;加快程序执行速度和响应速度, 使得程序充分利用CPU资源。 &#xff08;2&…

Python 全栈体系【四阶】(五十八)

第五章 深度学习 十三、自然语言处理&#xff08;NLP&#xff09; 3. 文本表示 3.1 One-hot One-hot&#xff08;独热&#xff09;编码是一种最简单的文本表示方式。如果有一个大小为V的词表&#xff0c;对于第i个词 w i w_i wi​&#xff0c;可以用一个长度为V的向量来表示…