I'm new to pygame and never used it before and wanted to know how I can blit or display my webcam into the surface by using pygame and opencv but I keep getting the message:
Traceback (most recent call last): File "<filename>.py", line 51, in <module> mainWindow() File "<filename>.py", line 43, in mainWindow draw_window() File "<filename>.py", line 24, in draw_window WINDOW.blit(camera) TypeError: argument 1 must be pygame.Surface, not cv2.VideoCapture
import pygame
import cv2
pygame.init()
# setting the width and height of the window
WIDTH, HEIGHT = 1280, 720
WINDOW = pygame.display.set_mode((WIDTH, HEIGHT))
pygame.display.set_caption("name me")
# background color
color = (0, 0, 0)
# 0 is the built in webcam
camera = cv2.VideoCapture(0)
camera.set(cv2.CAP_PROP_FRAME_WIDTH, 700)
camera.set(cv2.CAP_PROP_FRAME_HEIGHT, 900)
def draw_window():
# background color
WINDOW.fill((color))
# display object onto the surface (screen)
WINDOW.blit(camera)
# update the display
pygame.display.update()
FPS = 30
def mainWindow():
# keeping the window open
run = True
clock = pygame.time.Clock()
while run:
# capping it at the set frame rate
clock.tick(FPS)
for event in pygame.event.get():
if event.type == pygame.QUIT:
run = False
draw_window()
# closing the window
pygame.quit()
# main #
mainWindow()