Ask Your Question

Opencv color ranges for hsv

asked 2016-11-14 05:03:09 -0500

Prototype gravatar image

What are the hsv ranges for the colors black,blue,red,green,orange,grey,yellow,purple,brown and white. I need to check if my hsv image is in this range and print the color. How do I find the ranges of these colors in hsv and if you have it ,please post it, thanks in advance.

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted

answered 2016-11-14 05:15:06 -0500

berak gravatar image

maybe some primitive color-picker might help you (just load an image from cmdline args, and click with left mouse)

#include "opencv2/opencv.hpp"
#include <iostream>
using namespace cv;
using namespace std;

Mat im_hsv;
void pick_color(int e, int x, int y, int s, void *)
    if (e==1) // left mouse down
        Vec3b p =<Vec3b>(y, x);
        cerr << int(p[0]) << " " << int(p[1]) << " " << int(p[2]) << endl;

// use like:  pick.exe my.png
int main( int argc, char** argv )
    setMouseCallback("hsv", pick_color);

    if (argc<2) return -1;
    Mat im_bgr = imread(argv[1]);
    if (im_bgr.empty()) return -2;

    cvtColor(im_bgr, im_hsv, COLOR_BGR2HSV);
    imshow("hsv", im_hsv);

    return 0;
edit flag offensive delete link more


@berak thanks. But how do I find the maximum and minimum range. For example, the maximum and minimum range for violent?

Prototype gravatar imagePrototype ( 2016-11-14 05:27:34 -0500 )edit

what you pick, is the center value, just add +- something, to get a range from this

berak gravatar imageberak ( 2016-11-14 05:31:00 -0500 )edit

@berak In my image I have both black and another color. How do I just access the color of the pixel which is not black?. I do not know the co-ordinates of the pixel?

Prototype gravatar imagePrototype ( 2016-11-15 08:20:26 -0500 )edit

@berak , I am terribly sorry to disturb you again , But the code you gave me has no ouput. I am new to opencv and I really want to learn it.

Prototype gravatar imagePrototype ( 2016-11-15 08:24:34 -0500 )edit

it just prints the color to console, wherever you click into the image window, that's it.

berak gravatar imageberak ( 2016-11-15 09:04:22 -0500 )edit

Question Tools

1 follower


Asked: 2016-11-14 05:03:09 -0500

Seen: 2,238 times

Last updated: Nov 14 '16