当前位置:   article > 正文

Python 实现摄像头功能_python (windows端) 不使用obs 等工具的情况下 实现虚拟摄像头

python (windows端) 不使用obs 等工具的情况下 实现虚拟摄像头

正确的程序如下所示:

#! /usr/bin/env python

# -*- coding: utf-8 -*-

 

from VideoCapture import Device

import time

import sys,pygame

 

pygame.init()

 

size = width,height = 620,485

speed = [2,2]

black = 0,0,0

 

pygame.display.set_caption('视频窗口')

screen = pygame.display.set_mode(size)

 

#抓去频率,抓去一次

sleep_time_long = 0.1

 

#初始化摄像头

cam = Device(devnum=0,showVideoWindow=0)

 

while 1:

    #抓图

   cam.saveSnapshot('test.jpg',timestamp=3,boldfont=1,quality=75)

    #加载图像

   image = pygame.image.load('test.jpg')

    #传送画面

   screen.blit(image,speed)

    #显示图像

   pygame.display.flip()

    #休眠一下,等待一分钟

   time.sleep(sleep_time_long)

 

 

以下为笔者所写程序:

#! /usr/bin/env python

# -*- coding: utf-8 -*-

 

from VideoCapture import DEVIDE

 

import time

import sys,pygame

 

[A1] 

size = width,height = 600,485

speed = [2,2[A2] ]

black[A3]  = (0,0,0)

 

pygame.display.set_Caption('视频窗口')

pygame[A4] .set_mode(size)

 

sleep_time_long=0.1

 

cam = DEVICE(devnum=0,VideoWindow=0)

 

while true:

   cam.saveSnapshot('test.jpg',timestamp=3,boldfont=1,quality=75)

   image = pygame.iamge.load('test.jpg')

   screen.blit[A5] ()

   pygame.display.flip()

time.sleep(sleep_time_long)

 

 

解释及延伸:

pygame.init

initializeall imported pygame modules
pygame.init():return (numpass, numfail)

Initialize all imported Pygamemodules. No exceptions will be raised if a module fails, but the total numberif successful and failed inits will be returned as a tuple. You can alwaysinitialize individual modules manually, but pygame.init is aconvenient way to get everything started. The init() functions forindividual modules will raise exceptions when they fail.

You may want to initalise thedifferent modules seperately to speed up your program or to not use things yourgame does not.

Itis safe to call this init() more than once: repeated calls willhave no effect. This is true even if you have pygame.quit –uninitializeall pygame modules– all the modules.

pygame.display.set_caption

set the current window caption
pygame.display.set_caption(title,icontitle=None): return None

If the display has a window title, thisfunction will change the name on the window. Some systems support an alternateshorter title to be used for minimized displays.

p

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/小丑西瓜9/article/detail/305648
推荐阅读
相关标签
  

闽ICP备14008679号