当前位置:网站首页>【OpenCV】使用OpenCV调用手机摄像头
【OpenCV】使用OpenCV调用手机摄像头
2022-07-29 02:16:00 【云朵先生_】
一、前言
Droidcam 是一款可以将手机变成网络摄像头的工具,我们可以利用 Droidcam 让 OpenCV 拥有调用手机摄像头的能力。

二、步骤
2.1 安装 DroidCam
在手机和电脑上分别安装 DroidCam 的客户端和服务端
下载地址:https://pan.baidu.com/s/1DrBn3P1Bx-SXa4d6oziifA?pwd=gr1o
提取码:gr1o
2.2 测试连接状态
手机和电脑需要连接同一个 Wifi(或电脑连接手机的热点)。
打开手机上的 DroidCam 服务端,使用电脑浏览器访问下面的网址

如果出现以下页面,表示 DroidCam 已安装成功,最后要退出浏览器。
同一时间只能有一个软件调用手机摄像头,如果不关闭浏览器,后面使用 OpenCV 调用手机摄像头将报错。

2.3 连接手机摄像头
此时手机已经成为了网络摄像头,可以通过下面的链接访问它的视频流
http://<IP>:<Port>/mjpegfeed?[分辨率]
- 分辨率可以选择
- 320x240
- 640x480
- 960x720
- 1280x720
- 1920x1080
注意:调用手机摄像头的期间不要退出手机上的 DroidCam。
例:手机端 DroidCam 截图如下,那么手机摄像头的视频流链接就是:
http://192.168.31.211:4747/mjpegfeed

此时就可以通过 OpenCV 调用手机摄像头
cap = cv2.VideoCapture("http://192.168.31.211:4747/mjpegfeed")
完整代码
''' Author: CloudSir @Github: https://github.com/CloudSir Date: 2022-05-13 10:24:00 LastEditTime: 2022-07-27 11:47:08 LastEditors: CloudSir Description: '''
import cv2
def get_DroidCam_url(ip, port=4747, res='480p'):
res_dict = {
'240p': '320x240',
'480p': '640x480',
'720p': '1280x720',
'1080p': '1920x1080',
}
url = f'http://{
ip}:{
port}/mjpegfeed?{
res_dict[res]}'
return url
# DroidCam 显示的IP地址、端口号和相机分辨率(可选 240p,480p,720p,1080p)
cap = cv2.VideoCapture(get_DroidCam_url('192.168.31.211', 4747, '720p'))
while True:
ret, frame = cap.read()
if ret:
cv2.imshow('image', frame)
key = cv2.waitKey(1)
# 按q退出程序
if key == ord('q'):
break
# 释放VideoCapture
cap.release()
# 销毁所有的窗口
cv2.destroyAllWindows()
三、参考资料
- 使用OpenCV读取DroidCam的摄像头数据(局域网内):https://www.jianshu.com/p/523867890957
- DroidCam - 让手机充当无线摄像头[Android] - 小众软件:https://www.appinn.com/droidcam-for-android/
边栏推荐
- Rust list (VEC) replication
- Explanation of engineering economics terms
- Three expiration strategies
- Time for white horses to pass the gap
- 【报错】node:internal/modules/cjs/loader:936 【解决方法】
- qt QStringList用法
- 6年测试经验,教大家测试~如何把控项目
- 一文搞懂 Redis 架构演化之路
- 无线振弦采集系统工作流程
- Split, an avalanche caused by connection pool parameters
猜你喜欢

h. 264 code stream explanation

Redis master-slave mode, sentinel cluster, fragment cluster

快速掌握Nodejs安装以及入门

第六天笔记

STM32F103 learn the steps and template fool tutorial of 1-keil5 project establishment

PHP幸运抽奖系统带后台源码

Exploration and practice of network security vulnerability management

Quickly master nodejs installation and getting started
![[error reporting] node:internal/modules/cjs/loader:936 [solution]](/img/73/849c58c814c1a47dff0cde0e365c75.png)
[error reporting] node:internal/modules/cjs/loader:936 [solution]

Mqtt routine
随机推荐
QT屏幕自适应自动布局,拖动窗口自动变大变小(一)
Kbxxxxx is not necessarily a patch, but also a description of a solution to a problem
NVIDIA-VPI(Vision Programming Interface)
Stm32f103xx firmware function library-1
别人的快乐
C language to achieve the three chess game
OSPF实验
owt-server源码剖析(四)--video模块分析之Mixer Out
Master-slave replication and its principle
Talk about the implementation principle of feign
Continuous learning / life long learning
第五天实验
Mqtt routine
I was stunned by this question that I browsed 746000 times
In depth analysis - Pretreatment
家庭亲戚关系计算器微信小程序源码
qt QStringList用法
矿山开采虚拟现实vr安全培训提升员工警惕性和防护意识
Rust list (VEC) replication
这个博主,qt归类比较全,有空去学习总结,记录一下。