Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

There is nothing wrong with your code. I will fix for you to get better result for Canny. Because I'm using 4K UHD monitor. You can select range between 100 to 250 or slightly lower or higher for 1080P. The values for red is right colour. But depending on various red colour.

import cv2
import numpy as np

cap = cv2.VideoCapture(0)

while True:
    _, frame =
    hsv = cv2.cvtColor(frame, cv2.COLOR_BGR2HSV)

    lower_red = np.array([0, 0, 220])
    upper_red = np.array([180, 255, 255])

    mask = cv2.inRange(hsv, lower_red, upper_red)
    res = cv2.bitwise_and(frame, frame, mask= mask)

    edges = cv2.Canny(frame, 125, 200)
    cv2.imshow('Edges', edges) 

    cv2.imshow('Original', frame)
    cv2.imshow('Red', res) 

    k = cv2.waitKey(5)
    if k == 27: