inrange函数 python_为什么OpenCV的inRange函数不将我的HSV图像转换成二进制?

好吧,我在@Miki的帮助下在评论中找到了解决方案。在

代码几乎没有变化:lowerb = np.array([lH, lS, lV], np.uint8)

upperb = np.array([uH, uS, uV], np.uint8)

还有

^{pr2}$

上述代码更改解决了这个问题。在

完整的工作代码如下import serial

import numpy as np

import cv2

# dummy function

def nothing(x):

pass

# Track bar window

cv2.namedWindow('thresh')

# Track bars

cv2.createTrackbar('lH','thresh', 0, 180, nothing)

cv2.createTrackbar('lS', 'thresh', 0, 255, nothing)

cv2.createTrackbar('lV', 'thresh', 0, 255, nothing)

cv2.createTrackbar('uH', 'thresh', 0, 180, nothing)

cv2.createTrackbar('uS', 'thresh', 0, 255, nothing)

cv2.createTrackbar('uV', 'thresh', 0, 255, nothing)

# capture video

cap = cv2.VideoCapture(0)

while True:

# Read from camera

source, frame = cap.read()

if not source:

break

# converting image color to HSV color space

cv2.cvtColor(frame, cv2.COLOR_RGB2HSV, frame, 0)

# Getting values from track bars

lH = cv2.getTrackbarPos('lH', 'thresh')

uH = cv2.getTrackbarPos('uH', 'thresh')

lS = cv2.getTrackbarPos('lS', 'thresh')

uS = cv2.getTrackbarPos('uS', 'thresh')

lV = cv2.getTrackbarPos('lV', 'thresh')

uV = cv2.getTrackbarPos('uV', 'thresh')

lowerb = np.array([lH, lS, lV], np.uint8)

upperb = np.array([uH, uS, uV], np.uint8)

frame = cv2.inRange(frame, lowerb, upperb)

cv2.flip(frame, 1, frame)

cv2.imshow('thresh', frame)

if cv2.waitKey(1) & 0xFF == ord('q'):

break

cap.release()

cv2.destroyAllWindows()

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值