hsv

OpenCV(Python3)_6(更改颜色空间)

匿名 (未验证) 提交于 2019-12-02 22:54:36
目标 在本教程中,您将学习如何将图像从一个色彩空间转换为另一个色彩空间,如BGR Gray,BGR HSV等。 除此之外,我们还将创建一个应用程序,用于在视频中提取彩色对象 您将学习以下函数: , 等 改变色彩空间 OpenCV中有150多种颜色空间转换方法。 但我们只会研究使用最广泛的两种,BGR Gray和BGR HSV。 对于颜色转换,我们使用函数cv.cvtColor(input_image,flag),其中flag确定转换的类型。 对于BGR 灰度转换,我们使用标志 cv.COLOR_BGR2GRAY 。 同样对于BGR HSV,我们使用标志 cv.COLOR_BGR2HSV 。 要获得其他标志,只需在Python终端中运行以下命令: import cv2 as cv flags = [i for i in dir(cv) if i.startswith('COLOR_')] print( flags ) 注意 : 对于HSV,色调范围为[0,179],饱和度范围为[0,255],值范围为[0,255]。 不同的软件使用不同比例。 因此,如果您正在比较OpenCV值与他们,您需要规范化这些范围。 对象跟踪 现在我们知道如何将BGR图像转换为HSV,我们可以使用它来提取有色物体。 在HSV中,表现颜色比在BGR色彩空间中更容易。 在我们的应用程序中,我们将尝试提取蓝色的对象

初识OpenCV-Python - 005: 识别视频中的蓝色

匿名 (未验证) 提交于 2019-12-02 22:51:30
此次主要学习了如何将BGR转成HSV,主要用到cv2.cvtColor()和cv2.inRange()函数来识别视频中的蓝色物体。 code: import cv2import numpy as npcap = cv2.VideoCapture(0)#开启相机while(1): _,frame = cap.read() hsv = cv2.cvtColor(frame, cv2.COLOR_BGR2HSV) #将BGR图转成HSV图 lower_blue = np.array([100,43,46]) #能识别的最小的蓝色 upper_blue = np.array([124,255,255]) #能识别的最大蓝色 mask = cv2.inRange(hsv,lower_red,upper_blue) #设置hsv的颜色范围 res = cv2.bitwise_and(frame,frame ,mask = mask) #使用and的方式,区分出蓝色 cv2.imshow('hsv',hsv) cv2.imshow('frame',frame) cv2.imshow('mask',mask) cv2.imshow('res',res) k = cv2.waitKey(5) &0xFF if k== 27: breakcv2.destroyAllWindows()code结果:

Exact Skin color HSV range

落爺英雄遲暮 提交于 2019-12-02 19:45:21
I have seen all questions on SO for range of HSV color space for skin But I can only figure out this Code - CvScalar hsv_min = cvScalar(0, 30, 60, 0); CvScalar hsv_max = cvScalar(20, 150, 255, 0); //range I am using is { 0,30,60,0 & 20,150,255,0 } cvCvtColor(src, hsv_image, CV_BGR2HSV); cvInRangeS (hsv_image, hsv_min, hsv_max, hsv_mask); cvDilate(hsv_mask,hsv_mask,0,1); cvErode(hsv_mask,hsv_mask,0,1); cvSmooth( hsv_mask, hsv_mask, CV_MEDIAN); Problem with this range ( { 0,30,60,0 & 20,150,255,0 } ) is it detects even red color and when you place your hand in red background it does not track

Convert HSV to RGB in MATLAB

限于喜欢 提交于 2019-12-02 13:34:29
I have [H,S,V] colour values. How can I convert them to [R,G,B] in MATLAB? I've tried with the algorithm but I'm having some problems. Can anyone help me with the code? Using the in-built hsv2rgb function... % Some colour in HSV, [Hue (0-360), Saturation (0-1), Value (0-1)] myHSV = [217, 0.4, 0.72]; % hsv2rgb takes Hue value in range 0-1, so... myHSV(1) = myHSV(1) / 360; % Convert to RGB with values in range (0-1) myRGBpct = hsv2rgb(myHSV); % Convert to RGB with values in range (0-255) myRGB255 = myRGBpct * 255; Putting all of this together, we can simply do myHSV = [217, 0.4, 0.72]; myRGB255

Converting image using matlab / octave from rgb to hsv back to rgb

有些话、适合烂在心里 提交于 2019-12-02 12:46:34
I'm trying to convert a color image from rgb to hsv (make changes) then back to rgb. As a test I made this code just to test how to go from rgb to hsv back to rgb but when I view the image it just shows up as black. What am I missing? *PS I'm using octave 3.8.1 which works like matlab Here are the octave 3.8.1 packages I have loaded: >>> pkg list Package Name | Version | Installation directory --------------+---------+----------------------- control *| 2.6.2 | /usr/share/octave/packages/control-2.6.2 general *| 1.3.4 | /usr/share/octave/packages/general-1.3.4 geometry *| 1.7.0 | /usr/share

How to set HSV color range in OpenCV?

我是研究僧i 提交于 2019-12-02 07:07:45
I have a phone and it's HSV histogram like blow,and I want to track this phone's movement.Based on it's histogram,I set image range like this: greenLower = (300, 0, 50) greenUpper = (50, 128,250 ) cv2.inRange(hsv, greenLower, greenUpper) But nothing got detected out when waving the phone,and I am pretty sure it is because color range is wrong,would you tell me how to get color rang setting right?Especially,when HUE values are between [300~50],should I set it to (50~300) or (300~50) due to HUE is a cirle. Phone HSV histogram: You have wrongly set the upper and lower bounds, they must be:

Read HSV value of pixel in opencv

别来无恙 提交于 2019-12-02 06:43:46
how would you go about reading the pixel value in HSV format rather than RGB? The code below reads the pixel value of the circles' centers in RGB format. Is there much difference when it comes to reading value in HSV? int main(int argc, char** argv) { //load image from directory IplImage* img = cvLoadImage("C:\\Users\\Nathan\\Desktop\\SnookerPic.png"); IplImage* gray = cvCreateImage(cvGetSize(img), IPL_DEPTH_8U, 1); CvMemStorage* storage = cvCreateMemStorage(0); //covert to grayscale cvCvtColor(img, gray, CV_BGR2GRAY); // This is done so as to prevent a lot of false circles from being detected

OpenCV (C++) - Set HSV values of a pixel

∥☆過路亽.° 提交于 2019-12-02 03:28:21
I have an RGB image that i converted to HSV and my goal is to set every pixel that doesn't meet a certain hue value (100) to black. So H = S = V = 0. I have this code: (frame3 is the HSV Mat image, hue = 100) for (int i = 0; i<frame3.rows; i++) { for (int j = 0; j<frame3.cols; j++) { Vec3b hsv = frame3.at<Vec3b>(i, j); int H = hsv.val[0]; //hue int S = hsv.val[1]; //saturation int V = hsv.val[2]; //value if (H != hue) { H = 0; S = 0; V = 0; } } } imshow("Processed Hue", frame3); } But when i run it nothing happens..the image stays the same. When i tried printing out the hsv.val[0] values to

Percentage to Hexcolor in PHP

 ̄綄美尐妖づ 提交于 2019-12-02 03:22:35
问题 I'd like to make a percentage into a hexidecimal color. Kind of how HSV color degrees work... I am using PHP. IE: 0% : RED (#FF0000) 8% : ORANGE (#FF7F00) 17% : YELLOW (#FFFF00) 25% : LIMEGREEN (#7FFF00) ... : ... 83% : MAGENTA (#FF00FF) 92% : ROSE (#FF007F) 100% : RED (#FF0000) 回答1: This little snippet would appear to do what you're trying to achieve http://bytes.com/topic/php/insights/890539-how-produce-first-pair-rgb-hex-color-value-percent-value function percent2Color($value,$brightness =

初识OpenCV-Python - 005: 识别视频中的蓝色

烂漫一生 提交于 2019-12-01 22:17:18
此次主要学习了如何将BGR转成HSV,主要用到cv2.cvtColor()和cv2.inRange()函数来识别视频中的蓝色物体。 code: import cv2import numpy as npcap = cv2.VideoCapture(0)#开启相机while(1): _,frame = cap.read() hsv = cv2.cvtColor(frame, cv2.COLOR_BGR2HSV) #将BGR图转成HSV图 lower_blue = np.array([100,43,46]) #能识别的最小的蓝色 upper_blue = np.array([124,255,255]) #能识别的最大蓝色 mask = cv2.inRange(hsv,lower_red,upper_blue) #设置hsv的颜色范围 res = cv2.bitwise_and(frame,frame ,mask = mask) #使用and的方式,区分出蓝色 cv2.imshow('hsv',hsv) cv2.imshow('frame',frame) cv2.imshow('mask',mask) cv2.imshow('res',res) k = cv2.waitKey(5) &0xFF if k== 27: breakcv2.destroyAllWindows()code结果: