我正在使用网络摄像头从程序中捕获图像。当我在计算机上本地运行时,本地笔记本电脑的网络摄像头被打开。但是当我在服务器中部署代码时.... Webcam无法打开。
是否要打开服务器系统的网络摄像头?
我正在使用以下代码打开相机
vel_left = 4
vel_right = -4
run = True
while run:
# Handle the events.
for event in pygame.event.get():
if event.type == pygame.QUIT:
run = False
keys = pygame.key.get_pressed()
# Update the player coordinates.
if keys[pygame.K_LEFT] and player.left > 0:
player.x -= vel
if keys[pygame.K_RIGHT] and player.right < 1200:
player.x += vel
if keys[pygame.K_UP] and player.top > 0:
player.y -= vel
if keys[pygame.K_DOWN] and player.bottom < 600:
player.y += vel
# Game logic for walls and moving objects
for wall in walls:
# Check if the player rect collides with a wall rect.
if player.colliderect(wall):
print("Game over")
# Set this variable to True if the direction should be inverted.
invert_left = False
for object in movingobjectsleft:
if player.colliderect(object):
print("Game over")
object.x += vel_left # Move the object.
# Check if the object has left the area.
if object.right > 600 or object.left < 320:
# Invert the direction after the loop.
invert_left = True
if invert_left: # Invert the direction.
vel_left = -vel_left
# Now do the same for the right objects.
invert_right = False
for object in movingobjectsright:
if player.colliderect(object):
print("Game over")
object.x += vel_right
if object.right > 600 or object.left < 320:
invert_right = True
if invert_right:
vel_right = -vel_right
答案 0 :(得分:0)
我相信您的代码是由Servlet或相关API调用的,后者是服务器端的实现,仅适用于特定的服务器。但是,如果您必须访问客户端Cams并将其通过系统发送,则必须使用JS或Type脚本(例如:Angular,任何基于Js的框架)来实现相同的功能。
下面我分享了如何在Angular中进行讨论: How do I get a webcam working with AngularJS?
希望这会有所帮助!