当前位置: 首页 > news >正文

ubuntu22.04@laptop OpenCV Get Started: 002_reading_writing_videos

ubuntu22.04@laptop OpenCV Get Started: 002_reading_writing_videos

  • 1. 源由
  • 2. Read/Display/Write应用Demo
  • 3 video_read_from_file
    • 3.1 C++应用Demo
    • 3.2 Python应用Demo
    • 3.3 重点过程分析
      • 3.3.1 读取视频文件
      • 3.3.2 读取文件信息
      • 3.3.3 帧读取&显示
  • 4 video_read_from_image_sequence
    • 4.1 C++应用Demo
    • 4.2 Python应用Demo
    • 4.3 重点过程分析
  • 5 video_read_from_webcam
    • 5.1 C++应用Demo
    • 5.2 Python应用Demo
    • 5.3 重点过程分析
  • 6 video_write_from_webcam
    • 6.1 C++应用Demo
    • 6.2 Python应用Demo
    • 6.3 重点过程分析
      • 6.3.1 获取视频参数
      • 6.3.2 设置保存视频参数
      • 6.3.3 保存视频文件
  • 7 video_write_to_file
    • 7.1 C++应用Demo
    • 7.2 Python应用Demo
    • 7.3 重点过程分析
  • 8. 总结
  • 9. 参考资料

1. 源由

在OpenCV中对视频的读写操作与图像的读写操作非常相似。视频不过是一系列通常被称为帧的图像。所以,所需要做的就是在视频序列中的所有帧上循环,然后一次处理一帧。

接下来研读下:

  1. Read/Display/Write视频文件
  2. Read/Display/Write系列图片
  3. Read/Display/Write网络摄像头

2. Read/Display/Write应用Demo

002_reading_writing_videos是OpenCV读写、显示视频文件例程。

确认OpenCV安装路径:

$ find /home/daniel/ -name "OpenCVConfig.cmake"
/home/daniel/OpenCV/installation/opencv-4.9.0/lib/cmake/opencv4/
/home/daniel/OpenCV/opencv/build/OpenCVConfig.cmake
/home/daniel/OpenCV/opencv/build/unix-install/OpenCVConfig.cmake$ export OpenCV_DIR=/home/daniel/OpenCV/installation/opencv-4.9.0/lib/cmake/opencv4/

3 video_read_from_file

3.1 C++应用Demo

C++应用Demo工程结构:

002_reading_writing_videos/CPP/video_read_from_file$ tree .
.
├── CMakeLists.txt
├── Resources
│   └── Cars.mp4
└── video_read_from_file.cpp1 directory, 3 files

C++应用Demo工程编译执行:

$ cd video_read_from_file
$ mkdir build
$ cd build
$ cmake ..
$ cmake --build . --config Release
$ cd ..
$ ./build/video_read_from_file

3.2 Python应用Demo

Python应用Demo工程结构:

002_reading_writing_videos/Python$ tree . -L 2
.
├── requirements.txt
├── Resources
│   ├── Cars.mp4
│   └── Image_sequence
├── video_read_from_file.py
├── video_read_from_image_sequence.py
├── video_read_from_webcam.py
├── video_write_from_webcam.py
└── video_write_to_file.py2 directories, 7 files

Python应用Demo工程执行:

$ workoncv-4.9.0
$ python video_read_from_file.py

3.3 重点过程分析

3.3.1 读取视频文件

  • VideoCapture(path, apiPreference)

C++:

# Create a video capture object, in this case we are reading the video from a file
VideoCapture vid_capture("Resources/Cars.mp4");

Python:

# Create a video capture object, in this case we are reading the video from a file
vid_capture = cv2.VideoCapture('Resources/Cars.mp4')

3.3.2 读取文件信息

  • vid_capture.isOpened()
  • vid_capture.get()

C++:

if (!vid_capture.isOpened()){cout << "Error opening video stream or file" << endl;}
else{// Obtain fps and frame count by get() method and printint fps = vid_capture.get(5):cout << "Frames per second :" << fps;frame_count = vid_capture.get(7);cout << "Frame count :" << frame_count;}

Python:

if (vid_capture.isOpened() == False):print("Error opening the video file")
else:# Get frame rate informationfps = int(vid_capture.get(5))print("Frame Rate : ",fps,"frames per second")  # Get frame countframe_count = vid_capture.get(7)print("Frame count : ", frame_count)

3.3.3 帧读取&显示

  • vid_capture.read()
  • cv2.imshow()

C++:

while (vid_capture.isOpened())
{// Initialize frame matrixMat frame;// Initialize a boolean to check if frames are there or notbool isSuccess = vid_capture.read(frame);// If frames are present, show itif(isSuccess == true){//display framesimshow("Frame", frame);}// If frames are not there, close itif (isSuccess == false){cout << "Video camera is disconnected" << endl;break;}        
//wait 20 ms between successive frames and break the loop if key q is pressedint key = waitKey(20);if (key == 'q'){cout << "q key is pressed by the user. Stopping the video" << endl;break;}}

Python:

while(vid_capture.isOpened()):# vCapture.read() methods returns a tuple, first element is a bool # and the second is frameret, frame = vid_capture.read()if ret == True:cv2.imshow('Frame',frame)k = cv2.waitKey(20)# 113 is ASCII code for q keyif k == 113:breakelse:break

4 video_read_from_image_sequence

4.1 C++应用Demo

C++应用Demo工程结构:

002_reading_writing_videos/CPP/video_read_from_image_sequence$ tree . -L 2
.
├── CMakeLists.txt
├── Resources
│   └── Image_Sequence
└── video_read_from_image_sequence.cpp2 directories, 2 files

C++应用Demo工程编译执行:

$ cd video_read_from_image_sequence
$ mkdir build
$ cd build
$ cmake ..
$ cmake --build . --config Release
$ cd ..
$ ./build/video_read_is

4.2 Python应用Demo

Python应用Demo工程结构:

002_reading_writing_videos/Python$ tree . -L 2
.
├── requirements.txt
├── Resources
│   ├── Cars.mp4
│   └── Image_sequence
├── video_read_from_file.py
├── video_read_from_image_sequence.py
├── video_read_from_webcam.py
├── video_write_from_webcam.py
└── video_write_to_file.py2 directories, 7 files

Python应用Demo工程执行:

$ workoncv-4.9.0
$ python video_read_from_image_sequence.py

4.3 重点过程分析

读取系列照片文件

  • VideoCapture(path, apiPreference)

C++:

VideoCapture vid_capture("Resources/Image_sequence/Cars%04d.jpg");

Python:

vid_capture = cv2.VideoCapture('Resources/Image_sequence/Cars%04d.jpg')

注:Cars%04d.jpg: Cars0001.jpg, Cars0002.jpg, Cars0003.jpg, etc

5 video_read_from_webcam

5.1 C++应用Demo

C++应用Demo工程结构:

002_reading_writing_videos/CPP/video_read_from_webcam$ tree .
.
├── CMakeLists.txt
└── video_read_from_webcam.cpp0 directories, 2 files

C++应用Demo工程编译执行:

$ cd video_read_from_webcam
$ mkdir build
$ cd build
$ cmake ..
$ cmake --build . --config Release
$ cd ..
$ ./build/video_read_from_webcam

5.2 Python应用Demo

Python应用Demo工程结构:

002_reading_writing_videos/Python$ tree . -L 2
.
├── requirements.txt
├── Resources
│   ├── Cars.mp4
│   └── Image_sequence
├── video_read_from_file.py
├── video_read_from_image_sequence.py
├── video_read_from_webcam.py
├── video_write_from_webcam.py
└── video_write_to_file.py2 directories, 7 files

Python应用Demo工程执行:

$ workoncv-4.9.0
$ python video_read_from_webcam.py

5.3 重点过程分析

  • VideoCapture(path, apiPreference)

C++:

VideoCapture vid_capture(0);

Python:

vid_capture = cv2.VideoCapture(0)

注:cv2.CAP_DSHOW不要使用,有时会导致vid_capture.isOpened()返回false。

6 video_write_from_webcam

6.1 C++应用Demo

C++应用Demo工程结构:

002_reading_writing_videos/CPP/video_write_from_webcam$ tree .
.
├── CMakeLists.txt
└── video_write_from_webcam.cpp0 directories, 2 files

C++应用Demo工程编译执行:

$ cd video_write_from_webcam
$ mkdir build
$ cd build
$ cmake ..
$ cmake --build . --config Release
$ cd ..
$ ./build/video_write_from_webcam

6.2 Python应用Demo

Python应用Demo工程结构:

002_reading_writing_videos/Python$ tree . -L 2
.
├── requirements.txt
├── Resources
│   ├── Cars.mp4
│   └── Image_sequence
├── video_read_from_file.py
├── video_read_from_image_sequence.py
├── video_read_from_webcam.py
├── video_write_from_webcam.py
└── video_write_to_file.py2 directories, 7 files

Python应用Demo工程执行:

$ workoncv-4.9.0
$ python video_write_from_webcam.py

6.3 重点过程分析

6.3.1 获取视频参数

  • vid_capture.get()

C++:

// Obtain frame size information using get() method
Int frame_width = static_cast<int>(vid_capture.get(3));
int frame_height = static_cast<int>(vid_capture.get(4));
Size frame_size(frame_width, frame_height);
int fps = 20;

Python:

# Obtain frame size information using get() method
frame_width = int(vid_capture.get(3))
frame_height = int(vid_capture.get(4))
frame_size = (frame_width,frame_height)
fps = 20

6.3.2 设置保存视频参数

  • VideoWriter(filename, apiPreference, fourcc, fps, frameSize[, isColor])
  • filename: pathname for the output video file
  • apiPreference: API backends identifier
  • fourcc: 4-character code of codec, used to compress the frames fourcc
  • fps: Frame rate of the created video stream
  • frame_size: Size of the video frames
  • isColor: If not zero, the encoder will expect and encode color frames. Else it will work with grayscale frames (the flag is currently supported on Windows only).

C++:

//Initialize video writer object
VideoWriter output("Resources/output.avi", VideoWriter::fourcc('M', 'J', 'P', 'G'),frames_per_second, frame_size);

Python:

# Initialize video writer object
output = cv2.VideoWriter('Resources/output_video_from_file.avi', cv2.VideoWriter_fourcc('M','J','P','G'), 20, frame_size)

保存视频文件格式可以选择:

  • AVI: cv2.VideoWriter_fourcc(‘M’,‘J’,‘P’,‘G’)
  • MP4: cv2.VideoWriter_fourcc(*‘XVID’)

6.3.3 保存视频文件

  • output.write()

C++:

while (vid_capture.isOpened())
{// Initialize frame matrixMat frame;// Initialize a boolean to check if frames are there or notbool isSuccess = vid_capture.read(frame);// If frames are not there, close itif (isSuccess == false){cout << "Stream disconnected" << endl;break;}// If frames are presentif(isSuccess == true){//display framesoutput.write(frame);// display framesimshow("Frame", frame);// wait for 20 ms between successive frames and break        // the loop if key q is pressedint key = waitKey(20);if (key == ‘q’){cout << "Key q key is pressed by the user. Stopping the video" << endl;break;}}}

Python:

while(vid_capture.isOpened()):# vid_capture.read() methods returns a tuple, first element is a bool # and the second is frameret, frame = vid_capture.read()if ret == True:# Write the frame to the output filesoutput.write(frame)else:print(‘Stream disconnected’)break

7 video_write_to_file

7.1 C++应用Demo

C++应用Demo工程结构:

002_reading_writing_videos/CPP/video_write_to_file$ tree -L 2
.
├── CMakeLists.txt
├── Resources
│   └── Cars.mp4
└── video_write_to_file.cpp1 directory, 4 files

C++应用Demo工程编译执行:

$ cd video_write_to_file
$ mkdir build
$ cd build
$ cmake ..
$ cmake --build . --config Release
$ cd ..
$ ./build/video_write_to_file

7.2 Python应用Demo

Python应用Demo工程结构:

002_reading_writing_videos/Python$ tree . -L 2
.
├── requirements.txt
├── Resources
│   ├── Cars.mp4
│   └── Image_sequence
├── video_read_from_file.py
├── video_read_from_image_sequence.py
├── video_read_from_webcam.py
├── video_write_from_webcam.py
└── video_write_to_file.py2 directories, 7 files

Python应用Demo工程执行:

$ workoncv-4.9.0
$ python video_write_to_file.py

7.3 重点过程分析

整合了以下章节重点过程:

    1. video_read_from_file
    1. video_write_from_webcam

8. 总结

主要通过以下三个函数API实现:

  1. videoCapture():获取数据源
  2. read():读取数据
  3. imshow():显示图像
  4. write():保存数据

其他API函数:

  • isOpened() - 数据源打开是否成功过
  • get() - 获取数据源相关信息

9. 参考资料

【1】ubuntu22.04@laptop OpenCV Get Started
【2】ubuntu22.04@laptop OpenCV安装
【3】ubuntu22.04@laptop OpenCV定制化安装

相关文章:

ubuntu22.04@laptop OpenCV Get Started: 002_reading_writing_videos

ubuntu22.04laptop OpenCV Get Started: 002_reading_writing_videos 1. 源由2. Read/Display/Write应用Demo3 video_read_from_file3.1 C应用Demo3.2 Python应用Demo3.3 重点过程分析3.3.1 读取视频文件3.3.2 读取文件信息3.3.3 帧读取&显示 4 video_read_from_image_sequ…...

Elasticsearch(ES) 简述请求操作索引下文档 增删查改操作

上文 Elasticsearch(ES) 创建带有分词器规则的索引 带着大家创建了一个带有分词功能的索引 老规矩 我们启动一下ES服务 本文 我们就来说说 关于文档的操作 我们先来添加一个文档 就像数据库加一条数据一样 这里 并不需要指定什么表结构和数据结构 它的文档结构是无模式的 添…...

Chrome扩展开发纪要

1. 开发人员模式 以Edge(Chromium)为例, 可在管理扩展页, 在左侧开发人员模式打开, 只有此项开启后才能加载未压缩的扩展, 虽然也可以打包扩展, 但是浏览器会检测, 未上线的crx包是无法被安装的. 所以不打算上架的crx只能使用 加载解压缩的扩展 安装 2. 创建扩展 2.1 建立文…...

LeetCode-第28题-找出字符串中第一个匹配项的下标

1.题目描述 给你两个字符串 haystack 和 needle &#xff0c;请你在 haystack 字符串中找出 needle 字符串的第一个匹配项的下标&#xff08;下标从 0 开始&#xff09;。如果 needle 不是 haystack 的一部分&#xff0c;则返回 -1 。 2.样例描述 3.思路描述 可以让字符串 …...

分享90个行业PPT,总有一款适合您

分享90个行业PPT&#xff0c;总有一款适合您 90个行业PPT下载链接&#xff1a;https://pan.baidu.com/s/1bHvhk_42-IFAjNdjPPtMZw?pwd8888 提取码&#xff1a;8888 Python采集代码下载链接&#xff1a;采集代码.zip - 蓝奏云 学习知识费力气&#xff0c;收集整理更不易…...

【原创 附源码】Flutter海外登录--Tiktok登录最详细流程

最近接触了几个海外登录的平台&#xff0c;踩了很多坑&#xff0c;也总结了很多东西&#xff0c;决定记录下来给路过的兄弟坐个参考&#xff0c;也留着以后留着回顾。更新时间为2024年2月7日&#xff0c;后续集成方式可能会有变动&#xff0c;所以目前的集成流程仅供参考&#…...

国内chatGPT3.5升级到chatGPT4.0的教程(24年2月更新)

最新的充值方法看这里。 通过虚拟卡 WildCard 的方式来升级 GPT 4.0 最快了&#xff0c;大概2分钟就可以升级完成, 而且升级 GPT 4.0 价钱也不贵&#xff0c;虚拟卡一年10美元&#xff0c;GPT4 每个月也才 20美元。如果你觉得 GPT 4.0 对你可能有帮助&#xff0c;那就赶快来升级…...

【python量化交易】qteasy使用教程01 - 安装方法及初始化配置

qteasy教程1 - 安装方法及初始化配置 qteasy教程1 - 安装方法及初始配置qteasy安装前的准备工作1&#xff0c; 创建安装环境2&#xff0c;安装MySQL数据库 (可选)安装pymysql 3&#xff0c;创建tushare账号并获取API token (可选)4&#xff0c;安装TA-lib (可选)WindowsMac OSL…...

UML 2.5图形库

UML 2.5图形库 drawio是一款强大的图表绘制软件&#xff0c;支持在线云端版本以及windows, macOS, linux安装版。 如果想在线直接使用&#xff0c;则直接输入网址drawon.cn或者使用drawon(桌案), drawon.cn内部完整的集成了drawio的所有功能&#xff0c;并实现了云端存储&#…...

分享springboot框架的一个开源的本地开发部署教程(若依开源项目开发部署过程分享持续更新二开宝藏项目PostgresSQL数据库版)

1首先介绍下若依项目&#xff1a; 若依是一个基于Spring Boot和Spring Cloud技术栈开发的多租户权限管理系统。该开源项目提供了一套完整的权限管理解决方案&#xff0c;包括用户管理、角色管理、菜单管理、部门管理、岗位管理等功能。 若依项目采用前后端分离的架构&#xf…...

打卡今天学习 Linux

过年了&#xff0c;祝大家过年快乐 在今天的学习中&#xff0c;我们涉及了一些关键的 Linux 系统管理知识点&#xff0c;包括 systemctl、IP 地址配置、域名解析、映射的创建、软链接等。让我们简要回顾一下这些主题。 1. systemctl systemctl 是一个强大的 Linux 系统管理工…...

单片机精进之路-3流水灯

P1代表单片机的P1口的8个io的寄存器&#xff0c;使用_crol_函数&#xff1a;将 k进行1位左位移&#xff0c;并将值以unsigned char类型返回&#xff0c;再将K的值赋给P1&#xff0c;这样就点亮了P1口对应的IO为低电平的led灯。 //flow light and beep #include <reg51.h>…...

c# File.WriteAllLines 和 File.WriteAllText

File.WriteAllLines 和 File.WriteAllText 都是 C# 中用于写入文本文件的方法&#xff0c;但它们有一些区别。 1. File.WriteAllLines 方法&#xff1a; File.WriteAllLines 方法用于将字符串数组的内容按行写入文本文件。每个数组元素都被写入文件的一行&#xff0c;且方法会…...

linux系统定时任务管理

crontab使用 一、crontab简介 crontab 这个指令所设置的工作将会循环的一直进行下去&#xff01;可循环的时间为分钟、小时、每周、每月或每年等。crontab 除了可以使用指令执行外&#xff0c;亦可编辑 /etc/crontab 来支持。 至于让 crontab 可以生效的服务则是 crond 这个服…...

mysql的慢sql优化

为什么要优化慢sql &#xff1f; 慢sql会长时间占用 数据库连接数&#xff0c;如果项目中有大量的慢sql&#xff0c;那么可用的数据库连接数就会变少&#xff0c;进而会影响业务。 慢sql优化 优化慢sql&#xff0c;最常见的就是添加索引。查询语句中不要使用select *尽量减少…...

排序算法---插入排序

原创不易&#xff0c;转载请注明出处。欢迎点赞收藏~ 插入排序是一种简单直观的排序算法&#xff0c;它的基本思想是将待排序的元素分为已排序和未排序两部分&#xff0c;每次从未排序部分中选择一个元素插入到已排序部分的合适位置&#xff0c;直到所有元素都插入到已排序部分…...

迷你世界勒索病毒,你的文件被删了吗?

前言 笔者在某恶意软件沙箱平台分析样本的时候&#xff0c;发现了一款比较有意思的勒索病毒MiniWorld迷你世界勒索病毒&#xff0c;它的解密界面与此前的WannaCry勒索病毒的界面相似&#xff0c;应该是作者仿冒的WannaCry的UI&#xff0c;如下所示&#xff1a; 这款勒索病毒既…...

QT styleSheet——控件设置样式表

QT开发中&#xff0c;需要设置多种多样的控件表现形式&#xff0c;QT实现的styleSheet能够满足多种多样的场景&#xff0c;这里简单的记录下一些我常用的 设置透明背景&#xff0c;鼠标悬浮时&#xff0c;设置背景色&#xff1a; pushButton->setStyleSheet("QPushBu…...

Linux学习

1 Linux的目录结构介绍 bin存放常用的命令etc存放配置文件bootlinux启动的文件home存放用户lib存放动态库&#xff0c;给应用程序使用lostfound一般是空的&#xff0c;但系统异常关机会产生文件media自动挂载&#xff0c;如u盘&#xff0c;光盘mnt手动挂载&#xff0c;一般自己…...

MFC研发自验用例编写应注意哪些关键测试点

MFC&#xff08;Microsoft Foundation Classes&#xff09;是一个用于开发Windows应用程序的C类库。在MFC应用程序的研发过程中&#xff0c;自验用例&#xff08;自我验证测试用例&#xff09;的编写是非常重要的一环&#xff0c;它有助于确保代码的质量、稳定性和功能正确性。…...

基于Git与Markdown的文档即代码协作平台CORP实践指南

1. 项目概述&#xff1a;一个面向未来的开源协作平台 最近在开源社区里&#xff0c;一个名为“CORP”的项目引起了我的注意。这个项目全称是“CORP-md/CORP”&#xff0c;从名字上看&#xff0c;它似乎是一个与Markdown文档和协作相关的工具。作为一个长期在开源项目和团队协作…...

从嵌入式系统会议看技术生态构建:硬件开发与软件工程的融合实践

1. 从一场成功的会议到下一年的蓝图&#xff1a;嵌入式系统会议的幕后与启示刚结束的芝加哥嵌入式系统大会&#xff08;ESC Chicago&#xff09;被主办方评价为“一次巨大的成功”。作为一名在硬件开发与软件领域摸爬滚打了十几年的工程师&#xff0c;我深知这类行业顶级会议的…...

EchoType开源键盘固件:基于状态感知的智能输入引擎深度解析

1. 项目概述&#xff1a;从“EchoType”看开源键盘固件的深度定制最近在键盘客制化圈子里&#xff0c;一个名为“EchoType”的项目开始被一些资深玩家频繁提及。它的GitHub仓库地址是ljyou001/echotype&#xff0c;从名字上你就能猜到&#xff0c;这大概率是一个与键盘固件、打…...

哔哩下载姬DownKyi:B站视频下载的终极免费解决方案

哔哩下载姬DownKyi&#xff1a;B站视频下载的终极免费解决方案 【免费下载链接】downkyi 哔哩下载姬downkyi&#xff0c;哔哩哔哩网站视频下载工具&#xff0c;支持批量下载&#xff0c;支持8K、HDR、杜比视界&#xff0c;提供工具箱&#xff08;音视频提取、去水印等&#xff…...

scp 命令的使用方法 什么软件支持 .git bash xshell .openssh

scp 命令的使用方法 什么软件支持 .git bash xshell .openssh scp backup.sh deploy.sh rollback.sh userserver:/path/to/project/ 这个命令主要在 ‌Linux‌、‌macOS‌ 或 ‌Windows (10/11)‌ 的 ‌命令行终端&#xff08;Terminal / Command Prompt / PowerShell&#xff…...

AI智能体记忆系统设计:基于文件优先与智能压缩的生产级解决方案

1. 项目概述&#xff1a;一个为AI智能体设计的生产级记忆系统如果你正在构建一个需要长期记忆和上下文管理的AI智能体&#xff0c;比如一个能帮你写代码的编程助手&#xff0c;或者一个能处理复杂任务的自动化工作流&#xff0c;那么你肯定遇到过“上下文窗口”这个头疼的问题。…...

DocX入门指南:如何在不安装Word的情况下快速创建第一个Word文档

DocX入门指南&#xff1a;如何在不安装Word的情况下快速创建第一个Word文档 【免费下载链接】DocX Fast and easy to use .NET library that creates or modifies Microsoft Word files without installing Word. 项目地址: https://gitcode.com/gh_mirrors/doc/DocX Do…...

Helm模板智能助手:提升Kubernetes应用部署效率的VSCode插件

1. 为什么你需要一个Helm模板智能助手如果你和我一样&#xff0c;每天都在和Kubernetes的Helm Charts打交道&#xff0c;那你一定对编写templates/目录下那些.yaml文件又爱又恨。爱的是Helm的模板引擎确实强大&#xff0c;能把一堆重复的YAML配置抽象成可复用的模板&#xff1b…...

基于多平台行为数据构建AI Agent深度用户画像:Know Your Owner项目解析

1. 项目概述&#xff1a;从“你是谁”到“我懂你”的智能跨越在AI助手日益普及的今天&#xff0c;我们面临着一个核心矛盾&#xff1a;用户期望获得高度个性化的服务&#xff0c;而AI助手在初次接触时却对用户一无所知。传统的解决方案&#xff0c;比如让用户填写冗长的问卷&am…...

用100道题拿下你的算法面试(链表篇-7):复制带随机指针的链表

一、面试问题 给定一个链表的头节点&#xff0c;链表中每个节点都包含两个指针&#xff1a;一个指向下一个节点的 next 指针&#xff0c;以及一个指向链表中任意节点的 random 指针。请复制该链表&#xff0c;并返回新链表的头节点。 二、【朴素解法】使用哈希表 —— 时间复杂…...