Ask Your Question
0

Opencv color ranges for hsv

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

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
1

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

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 = im_hsv.at<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 )
{
    namedWindow("hsv");
    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);
    waitKey();

    return 0;
}
edit flag offensive delete link more

Comments

@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 -0600 )edit
1

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 -0600 )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 -0600 )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 -0600 )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 -0600 )edit

Question Tools

1 follower

Stats

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

Seen: 3,072 times

Last updated: Nov 14 '16