12、OpenCV4.4的图像物体跟踪

Parameters:
  • src – First source array.
  • lowerb – Inclusive lower boundary array or a scalar.
  • upperb – Inclusive upper boundary array or a scalar.
  • dst – Destination array of the same size as src and CV_8U type.

The function checks the range as follows:

  • For every element of a single-channel input array:

    \texttt{dst} (I)= \texttt{lowerb} (I)_0  \leq \texttt{src} (I)_0 \leq  \texttt{upperb} (I)_0

  • For two-channel arrays:

    \texttt{dst} (I)= \texttt{lowerb} (I)_0  \leq \texttt{src} (I)_0 \leq  \texttt{upperb} (I)_0  \land \texttt{lowerb} (I)_1  \leq \texttt{src} (I)_1 \leq  \texttt{upperb} (I)_1

  • and so forth.

That is, dst (I) is set to 255 (all 1 -bits) if src (I) is within the specified 1D, 2D, 3D, ... box and 0 otherwise.

When the lower and/or upper bounary parameters are scalars, the indexes (I) at lowerb and upperb in the above formulas should be omitted.

# -*- coding: UTF-8 -*-
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])
    '''
    第一个参数:hsv指的是原图

    第二个参数:lower_red指的是图像中低于这个lower_red的值,图像值变为0

    第三个参数:upper_red指的是图像中高于这个upper_red的值,图像值变为0

    而在lower_red~upper_red之间的值变成255
    '''
    mask = cv2.inRange(hsv, lower_blue, upper_blue)


    cv2.imshow('frame',frame)
    cv2.imshow('mask',mask)

    k = cv2.waitKey(5) & 0xFF
    if k == 27:
        break

cv2.destroyAllWindows()

 

 

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

sxj731533730

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值