Home>

The red color described on paper with a white to gray background is detected.
Currently, the color-detected rectangular image is converted into a histogram for judgment, but sufficient results have not been obtained.

1. 1. I want to judge the color of the contents of the extraction range in the color-detected rectangular image.
2. How can I get each HSV value of each part by color judgment?

In the HSV filter, the range above the white line (hue is in the red range) is set.

What you write on the paper can be red pencils, ballpoint pens, felt-tip pens, etc.
It is not possible to detect in the image of "red!"
Color judgment is performed on the detection result, and
If the yellow circles at both ends (where black and white are strong) are extracted,
I don't want to exclude it.



Histogram the extracted image as shown in the figure as it is
Red is judged from the maximum value (Y coordinate) and position (X coordinate) of each color in the range excluding the first and last parts. * The X coordinate occurs behind other colors.



However, while I want to detect it, an image with a histogram like the one above may also be detected, which is a problem because it cannot be determined by the above method.

The image (rectangle) detected there is not the same, but the actual content of the contour
I would like to process it, but I was able to get the outline, but I do not know what to do after that.

I would appreciate it if you could teach me the applicable methods and methods.

Corresponding source code
// HSV settings
// 20, 255, 220
// 200, 64, 30
// Histogram calculation
Mat b_hist = new Mat ();
Mat g_hist = new Mat ();
Mat r_hist = new Mat ();
Cv2.CalcHist (new Mat [] {img}, new int [] {0}, null, b_hist, 1, new int [] {256}, new Rangef [] {new Rangef (0, 256)});
Cv2.CalcHist (new Mat [] {img}, new int [] {1}, null, g_hist, 1, new int [] {256}, new Rangef [] {new Rangef (0, 256)});
Cv2.CalcHist (new Mat [] {img}, new int [] {2}, null, r_hist, 1, new int [] {256}, new Rangef [] {new Rangef (0, 256)});
// Histogram extraction
//Normalization
Cv2.Normalize (b_hist, b_hist, 0, histImage.Height, NormTypes.MinMax);
Cv2.Normalize (g_hist, g_hist, 0, histImage.Height, NormTypes.MinMax);
Cv2.Normalize (r_hist, r_hist, 0, histImage.Height, NormTypes.MinMax);
Development environment

C # (visualstudio2015), OpenCV (OpenCVSharp3 v4.0.0.20181129)

  • Answer # 1

    Yellow circles on both ends (where black and white are strong)

    In terms of HSV color space, I think it's a place where S and V are small.
    (Before the process of looking at the histogram of R, G, B) First of all, it would be better to directly apply the threshold to S and V.


    Regarding the story ...

    HSV filter

    I read that it is a word that refers to such processing, but is it different ...?
    Well, even if that "HSV filter" can't handle S and V,
    OpenCVcvtColorI think it would be good to calculate the HSV value of each pixel for each function and see what the S and V values ​​are in the actual data.
    That is,

    H is within the range of "red"

    S is above a certain threshold

    V is also above another threshold

    Is it possible to leave only the pixels that you want to keep by extracting the pixels?