国产精品天干天干,亚洲毛片在线,日韩gay小鲜肉啪啪18禁,女同Gay自慰喷水

歡迎光臨散文網(wǎng) 會員登陸 & 注冊

圖像處理顏色閾值(藍(lán)色分割)

2023-08-14 14:52 作者:一簾幽夢嘆清魂  | 我要投稿

HSV代碼

import CV2

import numpy as np


def on_trackbar(val):

? ? pass


# 創(chuàng)建滑動條窗口

CV2.namedWindow("Threshold Adjustments")


# 讀取原圖

image = CV2.imread("C:/Users/0.jpg")


# 獲得圖像的尺寸

height, width, _ = image.shape


# 將圖像轉(zhuǎn)換為HSV顏色空間

hsv_image = CV2.cvtColor(image, CV2.COLOR_BGR2HSV)


# 設(shè)定初始藍(lán)色的閾值范圍

init_lower_blue = [0, 0, 0]

init_upper_blue = [255, 255, 255]


# 創(chuàng)建滑動條,設(shè)置回調(diào)函數(shù)

CV2.createTrackbar("Lower H", "Threshold Adjustments", init_lower_blue[0], 179, on_trackbar)

CV2.createTrackbar("Lower S", "Threshold Adjustments", init_lower_blue[1], 255, on_trackbar)

CV2.createTrackbar("Lower V", "Threshold Adjustments", init_lower_blue[2], 255, on_trackbar)

CV2.createTrackbar("Upper H", "Threshold Adjustments", init_upper_blue[0], 179, on_trackbar)

CV2.createTrackbar("Upper S", "Threshold Adjustments", init_upper_blue[1], 255, on_trackbar)

CV2.createTrackbar("Upper V", "Threshold Adjustments", init_upper_blue[2], 255, on_trackbar)


while True:

? ? # 獲取滑動條的當(dāng)前值

? ? lower_hue = CV2.getTrackbarPos("Lower H", "Threshold Adjustments")

? ? lower_saturation = CV2.getTrackbarPos("Lower S", "Threshold Adjustments")

? ? lower_value = CV2.getTrackbarPos("Lower V", "Threshold Adjustments")

? ? upper_hue = CV2.getTrackbarPos("Upper H", "Threshold Adjustments")

? ? upper_saturation = CV2.getTrackbarPos("Upper S", "Threshold Adjustments")

? ? upper_value = CV2.getTrackbarPos("Upper V", "Threshold Adjustments")


? ? # 設(shè)定藍(lán)色的閾值范圍

? ? lower_blue = np.array([lower_hue, lower_saturation, lower_value])

? ? upper_blue = np.array([upper_hue, upper_saturation, upper_value])


? ? # 根據(jù)閾值范圍分割圖像

? ? mask = CV2.inRange(hsv_image, lower_blue, upper_blue)

? ? result = CV2.bitwise_and(image, image, mask=mask)


? ? # 顯示原圖和結(jié)果圖像

? ? CV2.imshow("Original Image", image)

? ? CV2.imshow("Result Image", result)


? ? # 按下ESC鍵退出循環(huán)

? ? key = CV2.waitKey(1) & 0xFF

? ? if key == 27:

? ? ? ? break


# 關(guān)閉窗口

CV2.destroyAllWindows()

Lab代碼

import CV2

import numpy as np


def on_trackbar(val):

? ? pass


# 創(chuàng)建滑動條窗口

CV2.namedWindow("Threshold Adjustments")


# 讀取原圖

image = CV2.imread("C:/Users/0.jpg")


# 獲得圖像的尺寸

height, width, _ = image.shape


# 將圖像轉(zhuǎn)換為LAB顏色空間

lab_image = CV2.cvtColor(image, CV2.COLOR_BGR2LAB)


# 設(shè)定初始藍(lán)色的閾值范圍

init_lower_blue = [0, 0, 0]

init_upper_blue = [255, 255, 255]


# 創(chuàng)建滑動條,設(shè)置回調(diào)函數(shù)

CV2.createTrackbar("Lower L", "Threshold Adjustments", init_lower_blue[0], 255, on_trackbar)

CV2.createTrackbar("Lower A", "Threshold Adjustments", init_lower_blue[1], 255, on_trackbar)

CV2.createTrackbar("Lower B", "Threshold Adjustments", init_lower_blue[2], 255, on_trackbar)

CV2.createTrackbar("Upper L", "Threshold Adjustments", init_upper_blue[0], 255, on_trackbar)

CV2.createTrackbar("Upper A", "Threshold Adjustments", init_upper_blue[1], 255, on_trackbar)

CV2.createTrackbar("Upper B", "Threshold Adjustments", init_upper_blue[2], 255, on_trackbar)


while True:

? ? # 獲取滑動條的當(dāng)前值

? ? lower_L = CV2.getTrackbarPos("Lower L", "Threshold Adjustments")

? ? lower_A = CV2.getTrackbarPos("Lower A", "Threshold Adjustments")

? ? lower_B = CV2.getTrackbarPos("Lower B", "Threshold Adjustments")

? ? upper_L = CV2.getTrackbarPos("Upper L", "Threshold Adjustments")

? ? upper_A = CV2.getTrackbarPos("Upper A", "Threshold Adjustments")

? ? upper_B = CV2.getTrackbarPos("Upper B", "Threshold Adjustments")


? ? # 設(shè)定藍(lán)色的閾值范圍

? ? lower_blue = np.array([lower_L, lower_A, lower_B])

? ? upper_blue = np.array([upper_L, upper_A, upper_B])


? ? # 根據(jù)閾值范圍分割圖像

? ? mask = CV2.inRange(lab_image, lower_blue, upper_blue)

? ? result = CV2.bitwise_and(image, image, mask=mask)


? ? # 顯示原圖和結(jié)果圖像

? ? CV2.imshow("Original Image", image)

? ? CV2.imshow("Result Image", result)


? ? # 按下ESC鍵退出循環(huán)

? ? key = CV2.waitKey(1) & 0xFF

? ? if key == 27:

? ? ? ? break


# 關(guān)閉窗口

CV2.destroyAllWindows()


圖像處理顏色閾值(藍(lán)色分割)的評論 (共 條)

分享到微博請遵守國家法律
长阳| 深圳市| 宁都县| 阳曲县| 云和县| 洪江市| 亳州市| 文安县| 盐城市| 略阳县| 利川市| 东乡| 五大连池市| 应城市| 赞皇县| 黄平县| 黄山市| 望谟县| 奉贤区| 湄潭县| 新河县| 策勒县| 梅州市| 仙桃市| 镇赉县| 鞍山市| 馆陶县| 通渭县| 曲靖市| 东兰县| 昭通市| 淅川县| 宁陵县| 商丘市| 漳浦县| 柳江县| 石柱| 溧水县| 广州市| 通江县| 达孜县|