Realize image color space conversion based on OpenCV in Python 3.6

This article mainly introduces OpenCV based on Python 3.6 to realize the conversion of image color space. This article introduces you in detail and has a certain reference value. Friends who need it can refer to it.

The color body of the picture in different color spaces is very different

#Color space conversion: the most common is the conversion between HSV and RGB, YUV and RGB

#Common color spaces are:

#RGB: Most commonly used

#HSV: Inscription of the specified color, used to find the expression of a specific color

#HIS:

#YCrCb: Used more in human skin color recognition

#YUV: More used in Android development

The following is a demonstration of all color spaces for the picture:

import cv2 as cv      ###导入openc包
def color_space_demo(image):
  gray = cv.cvtColor(image,cv.COLOR_BGR2GRAY)
  cv.imshow("gray",gray)
  hsv = cv.cvtColor(image,cv.COLOR_BGR2HSV)
  cv.imshow("hsv",hsv)
  yuv = cv.cvtColor(image,cv.COLOR_BGR2YUV)
  cv.imshow("yuv",yuv)
  Ycrcb = cv.cvtColor(image,cv.COLOR_BGR2YCrCb)
  cv.imshow("Ycrcb",Ycrcb)
  HIS = cv.cvtColor(image,cv.COLOR_BGR2HLS)
  cv.imshow("HIS",HIS)
print("--------hello python------------")
src=cv.imread("F:/shiyan/1.png")    ###读取F:/shiyan/1.png路径下的名为1格式为.png的图片
cv.namedWindow("input image",cv.WINDOW_AUTOSIZE)    ###给图片显示的窗口命名为input image
cv.imshow("input image",src)    ###显示图片
color_space_demo(src)
cv.waitKey(0)    ###等待下一步指令
cv.destroyAllWindows()    ###为了能正常关闭所有的绘图窗口。

Examples of pictures are as follows: 

The above is what the editor introduced to you to realize the conversion of image color space based on OpenCV in Python 3.6. I hope it will be helpful to you!

Finally, in fact, I am a python development engineer in the editor. I have compiled a set of the latest python system learning tutorials, including basic python scripts to web development, crawlers, data analysis, data visualization, machine learning, and interview collections. Those who want these materials can pay attention to the editor, add Q skirt 851211580 to pick up Python learning materials and learning videos, and online guidance from the Great God!

Guess you like

Origin blog.csdn.net/pyjishu/article/details/105412840