opencv 通过颜色提取显示屏数字
生活随笔
收集整理的這篇文章主要介紹了
opencv 通过颜色提取显示屏数字
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
hsv原理
hsv2
import cv2 import numpy as npdef Process(img):# 高斯平滑gaussian = cv2.GaussianBlur(img, (3, 3), 0, 0, cv2.BORDER_DEFAULT)# 中值濾波median = cv2.medianBlur(gaussian, 5)# Sobel算子# 梯度方向: x # sobel = cv2.Sobel(median, cv2.CV_8U, 1, 0, ksize=3) ## # 二值化 # ret, binary = cv2.threshold(sobel, 170, 255, cv2.THRESH_BINARY) ## # 核函數 # element1 = cv2.getStructuringElement(cv2.MORPH_RECT, (9, 1)) # element2 = cv2.getStructuringElement(cv2.MORPH_RECT, (9, 7)) ## # 膨脹 # dilation = cv2.dilate(binary, element2, iterations=1) # # 腐蝕 # erosion = cv2.erode(dilation, element1, iterations=1) # # 膨脹 # dilation2 = cv2.dilate(erosion, element2, iterations=3)return median frame = cv2.imread('cc.jpeg')frame=Process(frame) cv2.imshow("MyWindow", frame) hsv = cv2.cvtColor(frame, cv2.COLOR_BGR2HSV) # 將讀取的BGR轉換為HSV lower1 = np.array([35, 43, 46]) # 所要檢測的像素范圍 upper1 = np.array([77, 255, 255]) # 此處檢測綠色區域lower = np.array([165, 43, 46]) # 所要檢測的像素范圍 upper = np.array([173, 255, 255]) # 此處檢測綠色區域 mask = cv2.inRange(hsv, lowerb=lower, upperb=upper) mask1 = cv2.inRange(hsv, lowerb=lower1, upperb=upper1)cv2.imshow("mask", mask) cv2.imwrite('red.jpg', mask) cv2.imwrite('blue.jpg', mask1) #success, frame = cameraCapture.read() #frame = cv2.flip(frame, 1) #cv2.imshow("img", img) cv2.waitKey(0)總結
以上是生活随笔為你收集整理的opencv 通过颜色提取显示屏数字的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: opencv画直线,矩形
- 下一篇: opencv otsu二值化