how to i specify the upper and the lower value of a color in HSV opencv python











up vote
0
down vote

favorite












I found way to convert RGB to HSV, but still I am unable to find the upper and lower value of color. How to do i calculate that?



I have to take out the pickachu from the image



enter image description here



and this my code till now



import cv2
import numpy as np

cap = cv2.VideoCapture(0)

while True:
_, frame = cap.read()
hsv = cv2.cvtColor(frame, cv2.COLOR_BGR2HSV)


lower_red = np.array([30,50,50])
upper_red = np.array([255,255,180]) #it is trial and error

mask = cv2.inRange(frame, lower_red, upper_red)
res = cv2.bitwise_and(frame, frame, mask= mask)

cv2.imshow('frame',frame)
cv2.imshow('mask',mask)
cv2.imshow('res',res)

k = cv2.waitKey(5) & 0xFF
if k == 27:
break
cv2.destroyAllWindows()
cap.release()


please help me










share|improve this question




















  • 1




    Possible duplicate of How to convert a single BGR array to HSV array in Python with OpenCV?
    – Dan Mašek
    Nov 12 at 8:57










  • so, what color do you want to extract? Yellow? That is around Hue = 60, so in openCV (at least C++, not sure about python) it is around hue = 30. Try lower = np.array([20,50,50]) upper = np.array([40,255,255])
    – Micka
    Nov 12 at 8:58










  • stackoverflow.com/users/2393191/micka thank you but still some above portion on the right side is till not visible
    – Tanay Kumar
    Nov 12 at 9:16












  • try allowing smaller saturation and value (2nd and 3rd param in lower range) and/or allow more hue variation.
    – Micka
    Nov 12 at 10:13










  • Possible duplicate of Choosing the correct upper and lower HSV boundaries for color detection with`cv::inRange` (OpenCV)
    – Silencer 金
    Nov 13 at 0:33















up vote
0
down vote

favorite












I found way to convert RGB to HSV, but still I am unable to find the upper and lower value of color. How to do i calculate that?



I have to take out the pickachu from the image



enter image description here



and this my code till now



import cv2
import numpy as np

cap = cv2.VideoCapture(0)

while True:
_, frame = cap.read()
hsv = cv2.cvtColor(frame, cv2.COLOR_BGR2HSV)


lower_red = np.array([30,50,50])
upper_red = np.array([255,255,180]) #it is trial and error

mask = cv2.inRange(frame, lower_red, upper_red)
res = cv2.bitwise_and(frame, frame, mask= mask)

cv2.imshow('frame',frame)
cv2.imshow('mask',mask)
cv2.imshow('res',res)

k = cv2.waitKey(5) & 0xFF
if k == 27:
break
cv2.destroyAllWindows()
cap.release()


please help me










share|improve this question




















  • 1




    Possible duplicate of How to convert a single BGR array to HSV array in Python with OpenCV?
    – Dan Mašek
    Nov 12 at 8:57










  • so, what color do you want to extract? Yellow? That is around Hue = 60, so in openCV (at least C++, not sure about python) it is around hue = 30. Try lower = np.array([20,50,50]) upper = np.array([40,255,255])
    – Micka
    Nov 12 at 8:58










  • stackoverflow.com/users/2393191/micka thank you but still some above portion on the right side is till not visible
    – Tanay Kumar
    Nov 12 at 9:16












  • try allowing smaller saturation and value (2nd and 3rd param in lower range) and/or allow more hue variation.
    – Micka
    Nov 12 at 10:13










  • Possible duplicate of Choosing the correct upper and lower HSV boundaries for color detection with`cv::inRange` (OpenCV)
    – Silencer 金
    Nov 13 at 0:33













up vote
0
down vote

favorite









up vote
0
down vote

favorite











I found way to convert RGB to HSV, but still I am unable to find the upper and lower value of color. How to do i calculate that?



I have to take out the pickachu from the image



enter image description here



and this my code till now



import cv2
import numpy as np

cap = cv2.VideoCapture(0)

while True:
_, frame = cap.read()
hsv = cv2.cvtColor(frame, cv2.COLOR_BGR2HSV)


lower_red = np.array([30,50,50])
upper_red = np.array([255,255,180]) #it is trial and error

mask = cv2.inRange(frame, lower_red, upper_red)
res = cv2.bitwise_and(frame, frame, mask= mask)

cv2.imshow('frame',frame)
cv2.imshow('mask',mask)
cv2.imshow('res',res)

k = cv2.waitKey(5) & 0xFF
if k == 27:
break
cv2.destroyAllWindows()
cap.release()


please help me










share|improve this question















I found way to convert RGB to HSV, but still I am unable to find the upper and lower value of color. How to do i calculate that?



I have to take out the pickachu from the image



enter image description here



and this my code till now



import cv2
import numpy as np

cap = cv2.VideoCapture(0)

while True:
_, frame = cap.read()
hsv = cv2.cvtColor(frame, cv2.COLOR_BGR2HSV)


lower_red = np.array([30,50,50])
upper_red = np.array([255,255,180]) #it is trial and error

mask = cv2.inRange(frame, lower_red, upper_red)
res = cv2.bitwise_and(frame, frame, mask= mask)

cv2.imshow('frame',frame)
cv2.imshow('mask',mask)
cv2.imshow('res',res)

k = cv2.waitKey(5) & 0xFF
if k == 27:
break
cv2.destroyAllWindows()
cap.release()


please help me







python opencv hsv






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 12 at 9:13









api55

6,47032443




6,47032443










asked Nov 12 at 8:52









Tanay Kumar

12




12








  • 1




    Possible duplicate of How to convert a single BGR array to HSV array in Python with OpenCV?
    – Dan Mašek
    Nov 12 at 8:57










  • so, what color do you want to extract? Yellow? That is around Hue = 60, so in openCV (at least C++, not sure about python) it is around hue = 30. Try lower = np.array([20,50,50]) upper = np.array([40,255,255])
    – Micka
    Nov 12 at 8:58










  • stackoverflow.com/users/2393191/micka thank you but still some above portion on the right side is till not visible
    – Tanay Kumar
    Nov 12 at 9:16












  • try allowing smaller saturation and value (2nd and 3rd param in lower range) and/or allow more hue variation.
    – Micka
    Nov 12 at 10:13










  • Possible duplicate of Choosing the correct upper and lower HSV boundaries for color detection with`cv::inRange` (OpenCV)
    – Silencer 金
    Nov 13 at 0:33














  • 1




    Possible duplicate of How to convert a single BGR array to HSV array in Python with OpenCV?
    – Dan Mašek
    Nov 12 at 8:57










  • so, what color do you want to extract? Yellow? That is around Hue = 60, so in openCV (at least C++, not sure about python) it is around hue = 30. Try lower = np.array([20,50,50]) upper = np.array([40,255,255])
    – Micka
    Nov 12 at 8:58










  • stackoverflow.com/users/2393191/micka thank you but still some above portion on the right side is till not visible
    – Tanay Kumar
    Nov 12 at 9:16












  • try allowing smaller saturation and value (2nd and 3rd param in lower range) and/or allow more hue variation.
    – Micka
    Nov 12 at 10:13










  • Possible duplicate of Choosing the correct upper and lower HSV boundaries for color detection with`cv::inRange` (OpenCV)
    – Silencer 金
    Nov 13 at 0:33








1




1




Possible duplicate of How to convert a single BGR array to HSV array in Python with OpenCV?
– Dan Mašek
Nov 12 at 8:57




Possible duplicate of How to convert a single BGR array to HSV array in Python with OpenCV?
– Dan Mašek
Nov 12 at 8:57












so, what color do you want to extract? Yellow? That is around Hue = 60, so in openCV (at least C++, not sure about python) it is around hue = 30. Try lower = np.array([20,50,50]) upper = np.array([40,255,255])
– Micka
Nov 12 at 8:58




so, what color do you want to extract? Yellow? That is around Hue = 60, so in openCV (at least C++, not sure about python) it is around hue = 30. Try lower = np.array([20,50,50]) upper = np.array([40,255,255])
– Micka
Nov 12 at 8:58












stackoverflow.com/users/2393191/micka thank you but still some above portion on the right side is till not visible
– Tanay Kumar
Nov 12 at 9:16






stackoverflow.com/users/2393191/micka thank you but still some above portion on the right side is till not visible
– Tanay Kumar
Nov 12 at 9:16














try allowing smaller saturation and value (2nd and 3rd param in lower range) and/or allow more hue variation.
– Micka
Nov 12 at 10:13




try allowing smaller saturation and value (2nd and 3rd param in lower range) and/or allow more hue variation.
– Micka
Nov 12 at 10:13












Possible duplicate of Choosing the correct upper and lower HSV boundaries for color detection with`cv::inRange` (OpenCV)
– Silencer 金
Nov 13 at 0:33




Possible duplicate of Choosing the correct upper and lower HSV boundaries for color detection with`cv::inRange` (OpenCV)
– Silencer 金
Nov 13 at 0:33

















active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53258628%2fhow-to-i-specify-the-upper-and-the-lower-value-of-a-color-in-hsv-opencv-python%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown






























active

oldest

votes













active

oldest

votes









active

oldest

votes






active

oldest

votes
















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.





Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


Please pay close attention to the following guidance:


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53258628%2fhow-to-i-specify-the-upper-and-the-lower-value-of-a-color-in-hsv-opencv-python%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

List item for chat from Array inside array React Native

Thiostrepton

Caerphilly