Skip to content

Lazy question! Is anyome here using simple "video capture" from a webcam? #206

Answered by villares
villares asked this question in Q&A
Discussion options

You must be logged in to vote

This seems to work...

import cv2
import numpy as np
#from PIL import Image
from py5 import create_image_from_numpy

cap = cv2.VideoCapture(0)

def setup():
    size(640, 480)

def draw():
    ret, frame = cap.read()
    #pil_img = Image.fromarray(frame)     # from npa to PIL.Image
    ## if you want to use PIL manipulation here
    #img_as_np_array = np.array(pil_img)  # back to npa
    img_as_np_array = frame
    gray = cv2.cvtColor(img_as_np_array, cv2.COLOR_BGR2GRAY)
    edges = cv2.Canny(gray, 100, 80)
    # blended_gray = cv2.addWeighted(gray, 0.6, edges, 0.4, 0)
    edges_rgb_npa = cv2.cvtColor(edges, cv2.COLOR_GRAY2BGR)
    blended_rgb_npa = cv2.addWeighted(img_as_np_array, 0.6,
 …

Replies: 1 comment 6 replies

Comment options

villares
Dec 7, 2022
Collaborator Author

You must be logged in to vote
6 replies
@villares
Comment options

villares Dec 8, 2022
Collaborator Author

@hx2A
Comment options

hx2A Dec 8, 2022
Maintainer

@villares
Comment options

villares Apr 14, 2023
Collaborator Author

@hx2A
Comment options

hx2A Apr 14, 2023
Maintainer

@villares
Comment options

villares Apr 14, 2023
Collaborator Author

Answer selected by villares
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants