JAVA+OPENCV Color Recognition __java

Source: Internet
Author: User
            JAVA+OPENCV Color Recognition

Recently in the project involved in the image recognition, the use of third-party detection is OPENCV, in view of the online use of Java to do a very small amount of information, so I wrote this blog, I hope the students a little help later!
Note: Color extraction on the picture requires a higher, if your picture is more ambiguous (hundreds of KB, 2M is no problem), please do not waste time ,

This is written about the color of the extraction ——-original artwork:

here is the red extract:
1, get the Picture object mat
Mat hsv_image = new Mat (Mat.size (), Mat.type ());

1 Convert the format of the picture to HSV mode, originally RGB ***imgproc.cvtcolor (Mat, Hsv_image, IMGPROC.COLOR_BGR2HSV); * * Hue (H), saturation (S), lightness (V)
     The following can be used to extract the color of the int num_rows = Hsv_image.rows ();

     int num_col = Hsv_image.cols ();
                for (int i = 0; i < num_rows. i++) {for (int j = 0; J < Num_col; J +) {//Get each pixel
                double[] Clone = Hsv_image.get (i, J). Clone (); Double hun = clone[0]; HSV hun if (Hun >= 0 && Hun < 34) | | (Hun > 160 && Hun < 200)) {if (clone[1] > && clone[1] < () {if (clone[2) ; && Clone[2] > 90 {//Red range, all set to black, clone[
                                0] = 0;
                                CLONE[1] = 0;
                                CLONE[2] = 0;
                            Hsv_image.put (I, J, clone); } else {CLone[0] = 255;
                                CLONE[1] = 255;
                                CLONE[2] = 255;
                            Hsv_image.put (I, J, clone);
 }
                        }
     } }

Finally get a picture of the red number set to black, the border and so on all become white, (the above code to perform the effect is not a black box) black border is my additional effect, red color value H about 0 ~ 10 | | 165 ~ 180, please set the threshold according to the requirement

The color values extracted above can be set at your own discretion.

Basically is this, the typesetting effect is not good do not spray ha, thank you!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.