当前位置:网站首页>【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/
边栏推荐
- Talk about the implementation principle of feign
- Brief answer of Engineering Economics
- 3D intelligent factory process flow visualization interactive display application advantages
- Mqtt routine
- 平凡的快乐
- Stm32f103xx firmware function library-1
- owt-server源码剖析(三)--video模块分析之Mixer In
- CatchAdmin实战教程(四)Table组件相关功能实现
- Polygon point test
- 新版海螺影视主题模板M3.1全解密版本多功能苹果CMSv10后台自适应主题开源全解密版
猜你喜欢

Production scheme and advantages of online 3D digital exhibition hall

HTTP缓存

VR safety training of mine mining virtual reality improves employees' vigilance and protection awareness

Split, an avalanche caused by connection pool parameters

ES6 detailed quick start!

php 进程通信系列 (一) 命名管道

第八天笔记

自动分账系统哪家好?

Understanding service governance in distributed development

一文读懂Okaleido Tiger近期动态,挖掘背后价值与潜力
随机推荐
ECCV 2022 | AirDet:无需微调的小样本目标检测方法
PHP幸运抽奖系统带后台源码
一文搞懂 Redis 架构演化之路
Brief answer of Engineering Economics
用于校园流浪猫信息记录和分享的小程序源码/微信云开发中大猫谱小程序源码
Talk about 11 tips for interface performance optimization
Double write consistency of MySQL and redis
网络基础概论
2022/07/28 学习笔记 (day18) 常用API
In depth analysis - Pretreatment
《微信小程序-进阶篇》Lin-ui组件库源码分析-Button组件(二)
Flink内核源码(七)Flink SQL提交流程
QT screen adaptive automatic layout, drag the window to automatically grow larger and smaller (I)
time_ Wait and close_ Cause of wait
ROS2/ROS1开发过程中的一些记录
How to use RPA to achieve automatic customer acquisition?
3D intelligent factory process flow visualization interactive display application advantages
Split, an avalanche caused by connection pool parameters
线上3d数字展厅制作方案及优点
MPEG音频编码三十年