Hellow there~
I'm working to make app.
This app need feature that detect Rubik's cube color(Realtime).
I'm using OpenCV to implement the feature.
I try to set up ROI and I detect color in ROI.
I know how to detect specific color.
I used inRange function on hsv channel image.
It's good working.
But now I don't know how to check color on specific region.
Forexample,
rubik's cube color array
(00)Red/(01)Blue/(02)Blue
(10)Green/(11)White/(12)Orange
(20)Yellow/(21)Blue/(22)White.
I want to know (0,0)'s color. It's red.
I use inRange function like this inRange((0,0)_image, lower_color, upper_color, color_mask).
Now how to check (0,0)_image's color what is?
How to know that is red?
Thank you for your attention.
Please let me know.
You should convert your image into HSV color space, where H stands for hue -- that's the color. Hue 0 is red, 0.3 is about green, 0.7 is like blue, you'll figure it out quite easily.
Related
I want to detect an Eye, I have some code where I can detect blue color object, so if I made changes(how I can?) then it would be possible for me to detect an eye. As the below color has its own specific range value so, if I specify the eye color HSV value then can I detect EYE with this method.
In this below code I am going to detect BLUE Color Object, please tell me that where I do changes in my code so that I could get EYE using Open CV.
IplImage* GetThresholdedImage(IplImage* img)
{
// Convert the image into an HSV image
IplImage* imgHSV = cvCreateImage(cvGetSize(img), 8, 3);
cvCvtColor(img, imgHSV, CV_BGR2HSV);
IplImage* imgThreshed = cvCreateImage(cvGetSize(img), 8, 1);
//For detecting BLUE color i have this HSV value,
cvInRangeS(imgHSV, cvScalar(112, 100, 100), cvScalar(124, 255, 255), imgThreshed);//this will not recognize the yellow color
cvReleaseImage(&imgHSV);
return imgThreshed;
}
Eye detection is much easier with Haar classifier.
link here
Such a simple method may work at extracting a blue object using some thresholding but even if it could be adapted using a different colour black? blue? green? Everyone has different eye colours. I don't see a non hacky method working for you using blob extraction like this based on a HSV threshold value. This method works well on large blocks of the same colour, i.e. removing a blue background.
Look more at shape, everyone has different coloured eyes but the shape is circular/ellipse ish. There are varients of the Hough Transform for detecting circles.
...the Hough transform has been extended to identifying positions of
arbitrary shapes, most commonly circles or ellipses.
In the Windows Api and GDI, you can use the default window background color for drawing buttons and stuff (that slight greyish color on Win98 , WinXP + Classic Theme etc. ).
What is the rgb value for that?
So I can emulate the exact color in Allegro using al_map_rgb( r, g, b) ?
It depends on the users settings.
You should use GetSysColor function to retrieve the DWORD value and then use GetRValue, GetGValue, and GetBValue to retrieve red, green and blue component values.
Although Bobrovsky's answer (use GetSysColor) is likely the right solution to the actual problem, if you want to know the default warm gray color regardless of the user's settings, it's R=212, G=208, B=200.
(The simple way to determine this was take a screenshot of a window, paste it into Paint, use the color picker tool on a bit of the default gray, and then open the "edit colors" dialog box to view the RGB values in it.)
I have a problem. I need to fill (or repaint) some pixels at image, stored in Image control. This is a png image. I mean, that all black pixels should be filled with, for example, red color. How can I do this? I thought I can access directly to pixels and using XOR change special bits, but I don't know how to do this. Or maybe there is an easier way?
The GetPixel and SetPixel methods should work for what you need.
This answer has a code sample that you should be able to adopt for your use.
Given a generated histogram that I got from an image I was wondering if there was any optimized way to generate a mask. Below I have added in 3 different images: the reference to use, the histogram data of the reference, and the main image that I would like to mask. I know that I could do this by each pixel and vary the color information by a certain percentage so that I would be able to get colors with lighting changes as well.
The basic idea is to find a color, given by the histogram data and within a certain range, and if it finds anything then to make it black. If it doesn't find anything then the color will be white.
Any advice would be greatly appreciated.
Reference image:
Histogram values:
Image to mask:
What you want is to mask a color in a certain range, this is what you should try with the code i posted here :
In my example, it is used to make it transparent, if you want to make it black, just skip the cvNot() step...
Making a color completely transparent in OpenCV
Hope it helped,
Julien
PS : i've just seen that you were the one who asked the question I answered about how to make a color transparent: the problem here is exactly the same... just adapt a lil bit the answer..
1) Convert your image RGB -> HSV : cvtColor()
2) Generate your histogram : calcHist()
3) Find the maximum in your Hue histogram : minMaxLoc()
4) Select thresholds around this maximum : your function
5) Use them to select only the color you want : inRange()
6) Put this mask in black : your function (a very simple way would be to remove all the RGB components on the mask) : your function
Try to use template matching approaches instead of histogram, for example, normalized cross correlation http://www.mathworks.com/products/demos/image/cross_correlation/imreg.html.
I have a basic png file with two colors in it, green and magenta. What I'm looking to do is to take all the magenta pixels and make them transparent so that I can merge the image into another image.
An example would be if I have an image file of a 2D character on a magenta background. I would remove all the magenta in the background so that it's transparent. From there I would just take the image of the character and add it as a layer in another image so it looks like the character has been placed in an environment.
Thanks in advance.
That's the code i would use,
First, load your image :
IplImage *myImage;
myImage = cvLoadImage("/path/of/your/image.jpg");
Then use a mask like this to select the color, you should refer to the documentation. In the following, I want to select a blue (don't forget that in OpenCV images are in BGR format, therefore 125,0,0 is a blue (it corresponds to the lower bound) and 255,127,127 is blue with a certain tolerance and is the upper bound.
I chose lower and upper bound with a tolerance to take all the blue of your image, but you can select whatever you want...
cvInRangeS(image,
cvScalar(125.0, 0.0, 0.0),
cvScalar(255.0, 127.0, 127.0),
mask
);
Now we have selected the mask, let's inverse it (as we don't want to keep the mask, but to remove it)
cvNot(mask, mask);
And then copy your image with the mask,
IplImage *myImageWithTransparency; //You may need to initialize it before
cvCopy(myImage,myImageWithTransparency,mask);
Hope it could help,
Please refer to the OpenCVDocumentation for further information
Here it is
Julien,