简体   繁体   English

(如何)在 opencv 和 python 的帮助下,我可以将 HSV 的 v 值标准化为 0 和 1 之间吗?

[英](How) can I normalize the HSV's v value to be between 0 and 1 with the help of opencv and python?

As I want to categorize and compare photos in terms of their brightness, I want to normalize the V values (HSV) to be between 0 and 1 - with 1 being the brightest.因为我想根据亮度对照片进行分类和比较,所以我想将 V 值 (HSV) 标准化为 0 和 1 之间 - 其中 1 是最亮的。 I use opencv with python.我使用 opencv 和 python。 Thank you in advance先感谢您

import cv2
import numpy as np

# Read an image
frame = cv2.imread("Path/to/img")
# Convert it to hsv
hsv = cv2.cvtColor(frame, cv.COLOR_BGR2HSV)
# Get the V channel
v=hsv[:,:,2]
# Convert it to float
v=v.astype(np.float32)
# Normalize to brightest value
v/=np.amax(v)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM