LoginSignup
1
0

More than 3 years have passed since last update.

pythonでHSV値をOpenCV特有の値域に変換する関数

Posted at

はじめに

pythonで画像処理をする際に、OpenCVでHSVを扱うことがあると思います。
でも、OpenCVのHSVの値域って、一般的なHSVの値域とちょっと違います。

一般的な値域 OpenCVの値域
H 0~360 0~180
S 0~100 0~255
V 0~100 0~255

毎回自分で変換した値計算して扱うのは面倒なので、勝手に変換する関数を残しておきます。
(ホントになんてことない内容ですが…)

コード

hsvconv.py

def main():
    #一般的なHSV値を入れる
    h = XX
    s = XX
    v = XX

    #HSV値をOpenCV用に変換
    h = int(h/2)
    s = int(s*255/100)
    v = int(v*255/100)

    print('(h,s,v)=(',h,',',s,',',v,')')

if __name__ == '__main__':
    main()

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0