【问题标题】:camera suddenly close when i run the code运行代码时相机突然关闭
【发布时间】:2021-02-23 07:52:56
【问题描述】:

我正在尝试使用 python 从默认相机进行颜色检测,为此我使用 OpenCV 和 NumPy。我的程序突然关闭了相机。

这是我正在尝试运行的代码:

import cv2
import numpy as np

pict=cv2.VideoCapture(0)

while True:
    ret,frame=pict.read()
    _hsv=cv2.cvtColor(frame,cv2.COLOR_BGR2HSV)

    low_red= np.array([347,100,100])
    high_red=np.array([0,100.100])
    red_mask=cv2.inRange(_hsv, low_red, high_red)

    cv2.imshow("Kamera", frame)
    cv2.imshow("Kamera HSV", red_mask)

    if cv2.waitKey(1)== 27 :
        break

    pict.release()
    cv2.destroyAllWindows()

【问题讨论】:

标签: python opencv


【解决方案1】:

完成这项任务分为三个阶段:

  1. 首先您需要制作颜色边界
low_red = np.array([347, 100, 100])  # lower boundry
high_red = np.array([0, 100, 100])   # upper boundry
  1. 颜色检测
red_mask = cv2.inRange(_hsv, low_red, high_red)  # finding the mask
output = cv2.bitwise_and(_hsv, _hsv, mask=red_mask) # applying the mask with `hsv` image
  1. 水平堆叠。
final = np.hstack([_hsv, output])  # horizontally stacking
cv2.imshow("Imshow", final) 

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-07-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多