从 Python 应用程序打开 Windows 相机 [英] Open Windows Camera from Python application

查看:37
本文介绍了从 Python 应用程序打开 Windows 相机的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要打开 Windows 10 相机应用程序并可能在几秒钟后关闭它,以便我的相机能够正常工作.我已经阅读了我应该使用 os.subprocess.run() 的相关问题,但我不确定应该在那里输入什么.我看过有关通过在命令行中执行 start microsoft.windows.camera 从命令行打开相机的帖子,但它不起作用.有什么想法吗?

I need to open the Windows 10 camera app and possibly close it after a few seconds so that my camera will work the proper way. I've read in realted questions that I'm supposed to use os.subprocess.run() but I'm not sure what should go in there. I've seen posts about opening the Camera from the command line by doing start microsoft.windows.camera in the command line but it's not working. Any idea?

推荐答案

打开相机:

import subprocess,os
subprocess.run('start microsoft.windows.camera:', shell=True)

关闭相机:

subprocess.run('Taskkill /IM WindowsCamera.exe /F', shell=True)

如果它说它无法识别 - WindowsCamera.exe 在您的计算机命令提示符中键入 Tasklist 并在 .exe 之前查找您的相机的名称,然后将上述代码调整为您的相机名称.

If it says it doesn't recognise- WindowsCamera.exe Type Tasklist into your computers command prompt and look for what your camera is called before .exe then adapt the above code to your camera name.

将所有代码放在一起,以检查是否有效:

code all together, to check if works:

import subprocess,time,os
subprocess.run('start microsoft.windows.camera:', shell=True)
time.sleep(10)
subprocess.run('Taskkill /IM WindowsCamera.exe /F', shell=True)

这篇关于从 Python 应用程序打开 Windows 相机的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆