Question

import cv2
import numpy as np

cap = cv2.VideoCapture(0)

while(1):

    # Take each frame
    _, frame = cap.read()

    # Convert BGR to HSV
    hsv = cv2.cvtColor(frame, cv2.COLOR_BGR2HSV)

    # define range of blue color in HSV
    lower_blue = np.array([110,50,50])
    upper_blue = np.array([130,255,255])

    # Threshold the HSV image to get only blue colors
    mask = cv2.inRange(hsv, lower_green, upper_green)

    # Bitwise-AND mask and original image
    res = cv2.bitwise_and(frame,frame, mask= mask)

    cv2.imshow('frame',frame)
    cv2.imshow('mask',mask)
    cv2.imshow('res',res)
    k = cv2.waitKey(5) & 0xFF
    if k == 27:
        break

cv2.destroyAllWindows()

Note: i'm new to open cv ,so please help guys!!!

In this program

  1. while reading a frame , why is there the symbol ' _, ' before frame

is it a syntax??

  1. The lowerbound and upper bound of blue color is specified. is that RGB values or BGR values or HSV values??

How can i find lower bound and upperbound of others colors like red,green?

Please explain the process of finding values of other colour ,i tried other colours but it gave me black screen output for hsv and res!!!

  1. Can some one change this program to detect red color or other color so i can know the difference?
Was it helpful?

Solution

  1. This is tuple unpacking; cap.read() returns two values, we assign the first to _ (convention for "we won't be using this") and the second to frame.
  2. The comment literally says "in hsv".
  3. You just need to specify your own bounds, or change the ones already there, and see the difference yourself. Use an HSV converter to see what colours you are using. If the colours within your range aren't in the image you process, it will be black.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top