【虚拟摄像机】akvcam安装以及使用初试

news/2024/11/15 8:35:51/

概述

今天逛网站了解到VCAM(虚拟摄像机),突发奇想在Linux验证下,是不是和我想的一样。经过测试,确定如此。

系统环境

Ubuntu 22.04
opencv-python 4.6.0

akvcam安装以及配置

请参考以下链接
Linux环境下配置虚拟摄像头akvcam

配置修改了一下,

# Virtual camera configuration file example.
#
# Please, read the instructions to the end.[Cameras]
# First at all you must define how many virtual cameras will be created.
cameras/size = 2# Then, define it's properties.
#
# A virtual camera can be of 2 types: 'capture' and 'output'.
# A 'capture' device will be seen as a normal webcam by any webcam capture
# program.
# A 'output' device will receive frames from a producer program and send it to
# one or many 'capture' devices.
#
# A camera can have also 3 capture/output modes: 'mmap', 'userptr' and 'rw'.
# 'mmap' is the most widely supported mode by far, enabling this is more than
# enough in most cases. 'rw' allow you to "echo" or "cat" frames as raw data
# directly to the device using the default frame format. Enabling 'rw' mode will
# disable emulated camera controls in the 'capture' device (brightness,
# contrast, saturation, etc.).
# A device can support all 3 modes at same time.
#
# 'formats' is a comma separated list of index in the format list bellow.
#
# It's also possible to set the device number by setting the 'videonr' property,
# if for example videonr=7 the the device will be created as "/dev/video7".
# If 'videonr' is already taken, negative or not set, the driver will assign the
# first free device number.
cameras/1/type = output
cameras/1/mode = mmap, userptr, rw
cameras/1/description = Virtual Camera (output device)
cameras/1/formats = 2
cameras/1/videonr = 7cameras/2/type = capture
cameras/2/mode = mmap, rw
cameras/2/description = Virtual Camera
cameras/2/formats = 1, 2[Formats]
# Define how many formats will be supported by the camera.
formats/size = 2# Now define the frame pixel formats, resolutions and frame rates supported by
# the camera.
#
# Supported capture formats:
#
#     RGB32
#     RGB24
#     RGB16
#     RGB15
#     BGR32
#     BGR24
#     UYVY
#     YUY2
#
# Supported output formats:
#
#     RGB24
#     BGR24
#
# YUY2 640x480 is one of the most widely supported formats in webcam capture
# programs. First format defined is the default frame format for
# 'capture'/'output'.
# 'width', 'height' and 'fps' are unsigned integers.
formats/1/format = YUY2, BGR24 #这句修改了
formats/1/width = 640
formats/1/height = 480
formats/1/fps = 30# The parameters can also be specified as a comma separated list, so it's
# possible to combine the parameters to define several formats in one group.
# 'fps' can also be defined as a fraction.
# The following lines will define 4 formats:
#
#     RGB24 640x480 20  FPS
#     RGB24 640x480 7.5 FPS
#     YUY2  640x480 20  FPS
#     YUY2  640x480 7.5 FPS
formats/2/format = RGB24, YUY2
formats/2/width = 640
formats/2/height = 480
formats/2/fps = 20/1, 15/2# Finally, to create a fully working virtual camera, you must connect one
# 'output' to one or many 'capture' devices.
# Connections are made by index, separated by a colon. The first index is the
# 'output' device, the following index are 'capture' devices.
[Connections]
connections/size = 1
connections/1/connection = 1:2# You can also define a default frame when a 'capture' device is not receiving
# any input. Only 24 bpp and 32 bpp BMP files are supported.
[General]
# 修改此处的图片路径,只能是BMP格式的图片
default_frame = /etc/akvcam/default_frame.bmp
# This config will take effect on modprobe/insmod.

虚拟摄像机工作流程

内容提供程序 ---> output device(/dev/video7) ---> capture device(/dev/video0) ---> 摄像机程序

测试代码

摄像机程序

#来源于网上
import cv2
camera = cv2.VideoCapture(0)
while True:(grabbed, frame) = camera.read()while not grabbed:continuecv2.imshow("capture", frame)# cv2.waitKey(0)  # 捕获并显示一帧,按键后捕获并显示新的一帧if cv2.waitKey(1) & 0xFF == ord('q'):break
cap.release()
cv2.destroyAllWindows()

内容提供程序

#基于网上程序修改
import cv2with open('/dev/video7', 'wb') as cameraf:capture = cv2.VideoCapture('testvideo.mp4')while True:ret, frame = capture.read()if not ret:breakimgResize=cv2.resize(frame,(640,480)) #调整下帧的分辨率,不然会出现花屏现象print(imgResize.shape)cv2.imshow('video', imgResize)cameraf.write(imgResize)if cv2.waitKey(50) == 27:breakcv2.waitKey(0)
cv2.destroyAllWindows()

Q&A

Q:insmod akvcam.ko的时候,提示Unknown symbol
A:

modinfo akvcam.ko | grep depends #显示相关依赖
depends:        videobuf2-v4l2,videodev,videobuf2-common,videobuf2-vmallocsudo modprobe videodev #加载依赖模块
sudo insmod akvcam.ko #加载akvcam模块,该模块加载的时候,配置一定要生成,不然不会生成虚拟设备

Q:写入数据,显示出来是花屏
A:经排查发现是帧图片的分辨率没设置对,设置正确分辨率即可

Q:写入数据,显示出来的视频,颜色不一致
A:还没有排查,有知道的小伙伴可以所下

Q:akvcam编译的时候,cmake和make能编译成功,但是安装指令都无法执行成功
A:最后自己手动载入对应摄像头

链接

Linux环境下配置虚拟摄像头akvcam


http://www.ppmy.cn/news/402022.html

相关文章

由于找不到wpcap.dll导致软件无法运行的解决办法,特此记录

由于找不到wpcap.dll导致软件无法运行的解决办法,特此记录提示 目录 前言 一、解决找不到wpcap.dll错误的办法 前言 今天在运行一个软件时弹出,找不到wpcap.dll,无法运行的弹出,目前已解决此问题,特此记录&#xff…

服务器在新加坡延迟,从国内访问新加坡服务器延迟多大?

新加坡作为东南亚的核心发达地区,很多国内企业在选择出海发展业务时,都会将这里作为首选地。在互联网行业也一样,我们在租用东南亚服务器时,也会以这一核心来选择,以此为核心辐射至周边地区。电商、海外代购是东南亚发…

TAB选择卡

选择卡 内容原理htmlcssscript 内容 1.选项卡由英雄联盟、DOTA、风暴英雄、apex四块组成; 2.未选择时,默认选中第一个标签页; 3.选择某一选项后,下方跳出对应游戏的相关介绍内容。 原理 js原理: 先获取元素然后for…

万字大章之HTML表单详解_ HTML篇_第九章

HTML篇_第九章、HTML表单 HTML篇_第九章、HTML表单一、HTML表单1.1表单的基本结构1.2表单的元素格式 二、文本域三、密码字段四、单选按钮五、多选框六、下拉列表框七、按钮7.1submit按钮7.2reset按钮7.3button按钮7.4图片按钮 八、多行文本域九、文件域十、搜索框十一、只读和…

HTML总结1(常用标签,表单标签为主)

目录 一、HTML简介 二、常用标签 三、表单标签 3.1form表单的常用属性 3.2input标签 3.3select标签 3.4textarea标签 3.5表单标签练习 一、HTML简介 html简介:HTML 的结构包括头部(Head)、主体(Body)两大部…

JavaScriptFoundation

JavaScriptFoundation 一. JavaScript简介1.1 JavaScript 是什么1.2 JavaScript 的作用1.2.1 网页特效1.2.2 表单验证1.2.3 数据交互1.2.4 服务器编程1.3 JavaScript 的组成1.3.1 ECMAScript1.3.1.1 规定了js基础语法核心知识1.3.2 Web APIs1.3.2.1 DOM 操作文档1.3.2.2 BOM 操…

HTML语法

标题标签 <h1> </h1>: 共有6个标题标签 例如4级标签: 三级标签例子 段落标签 <p> </p>:进行分段 换行标签&#xff08;单&#xff09; <br/>:另起一行 段落标签也会换行但是换行中间会有一段空隙&#xff0c;换行标签不会有空隙 文本格式化标…

HTML表单标签

HTML表单 <from>元素 HTML表单用于搜集不类型的用户输入。用<from>元素HTML定义表单 。 HTML 表单包含表单元素 表单元素是指不同类型的input元素、文本框、密码框、下拉列表框、单选按钮、提交按钮等等&#xff0c;一般由ingput、textarea、select标签构成&am…