在python3下使用OpenCV 抓取網路攝影機映像提取藍色

來源:互聯網
上載者:User

標籤:wait   logs   and   array   one   pen   www   res   image   

工作中需要對網路攝影機進行調試, Python平台大大提高調試效率.

從網找到段代碼, 可以從網路攝影機映像中摳出藍色.

import cv2
import numpy as np

cap  = cv2.VideoCapture(0)
for i in range(0, 19):
     print(cap.get(i))
while(1):
     ret, frame = cap.read()
     hsv = cv2.cvtColor(frame, cv2.COLOR_BGR2HSV)

    lower_blue = np.array([100, 47, 47])
     upper_blue = np.array([124, 255,255])

    mask = cv2.inRange(hsv, lower_blue, upper_blue) #藍色掩模

    res = cv2.bitwise_and(frame, frame, mask = mask)

    cv2.imshow(u"Capture", frame)
     cv2.imshow(u"mask", mask)
     cv2.imshow(u"res", res)

    key = cv2.waitKey(1)
     if key & 0xff == ord(‘q‘) or key == 27:
         print(frame.shape,ret)
         break
cap.release()
cv2.destroyAllWindows()

 

以下是從wangyblzu部落格截下來的HSV顏色分量範圍

https://www.cnblogs.com/wangyblzu/p/5710715.html

 

三張結果圖

Technorati Tags: Python3,opencv

在python3下使用OpenCV 抓取網路攝影機映像提取藍色

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.