简体   繁体   English

如何使用 python 从手机摄像头捕获图像?

[英]how to capture image from phone camera with python?

I need to capture the images from a phone camera using python and save the image on the PC in a given folder.我需要使用 python 从手机摄像头捕获图像,并将图像保存在 PC 上的给定文件夹中。 I found a way to do it with OpenCV and IPWebCam but unfortunately I cannot connect the PC and the phone on the same Wifi network.我找到了一种使用 OpenCV 和 IPWebCam 的方法,但不幸的是我无法在同一个 Wifi 网络上连接 PC 和手机。 Is there a workaround or an alternative that does not require for the devices to be connected to the same wifi?是否有不需要将设备连接到同一个 wifi 的解决方法或替代方法? I am using Windows and the phone is an Android我正在使用 Windows 手机是 Android

I put forward my solution.我提出了我的解决方案。 Of course, I cannot report the whole code of the idea as it would be impossible.当然,我不能报告这个想法的全部代码,因为这是不可能的。

  1. Create Server on your PC (Use the technology you prefer for Backend, for example Flask)在您的 PC 上创建服务器(使用您喜欢的后端技术,例如 Flask)
  2. Create route for retrieve images创建检索图像的路线
  3. Inside your app, when take photo send it to this route (the route save picture for you inside desidered folder)在您的应用程序中,拍照时将其发送到此路线(路线为您保存图片在所需文件夹中)

If you want such functionality to be usable with 4G outside the home, think about and consider the idea of a Real Server ( HETZNER SERVER CLOUD for example).如果您希望此类功能可用于家庭外的 4G,请考虑并考虑 Real Server(例如HETZNER SERVER CLOUD )的想法。 This way you make sure you contact a remote backend and it will be irrelevant whether you own 4G,5G or wifi.通过这种方式,您可以确保联系远程后端,无论您拥有 4G、5G 还是 wifi 都无关紧要。

If, on the other hand, you don't like the Server idea and want to force it onto your local computer but want to allow the fact that the cell phone doesn't have to be under the same local network that the PC is connected to, unfortunately, you would have to call your network provider and request a static IP (for an extra few pennies a month).另一方面,如果您不喜欢服务器的想法并希望将其强制安装到您的本地计算机上,但希望允许手机不必与 PC 连接在同一个本地网络下这一事实不幸的是,您将不得不致电您的网络提供商并请求 static IP(每月多花几美分)。 With the static IP you are reachable from the outside.使用 static IP,您可以从外部到达。 That's not the only step you have to do actually, because, you also have to enable portforward because you have to make sure that the call comes to the private IP assigned by your router.这不是您实际上必须做的唯一步骤,因为您还必须启用端口转发,因为您必须确保呼叫到达路由器分配的私有 IP。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM