Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to specify a color using Scalar class

I do not know how to specifiy a color using Scalar class in the below posted method?

Features2d.drawKeypoints(mKeyPoints_0, mKeyPoints_0, outImage, Scalar color, Features2d.DRAW_RICH_KEYPOINTS);
like image 668
user2121 Avatar asked Mar 27 '15 13:03

user2121


People also ask

Is color a scalar?

Color data holds the RGB values that define the color of the pixels in a texture. Scalar data on the other hand, defines properties of the texture such as shader inputs that define bumpiness, roughness or shininess. Essentially, color data exists to be seen, scalar data is used to calculate.

What is scalar OpenCV?

ScalarRepresents a 4-element vector. The type Scalar is widely used in OpenCV for passing pixel values. In this tutorial, we will use it extensively to represent BGR color values (3 parameters). It is not necessary to define the last argument if it is not going to be used.

How do you draw a circle in OpenCV C++?

A circle has a center and a radius. To draw a circle using OpenCV, we have to define the center and the radius. In OpenCV we have to include <imgproc. hpp> header because 'circle()' function is defined in this header.


1 Answers

Usage of Scalar to specify color, depends on the Mat type. Attempting to store/draw Red color on a grayscale Mat will fail.

  • Type CV_8UC1- grayscale image

    //8 bits per pixel and so range of [0:255]. 
    Scalar color = new Scalar( 255 )
    //For type: 16UC1, range of [0:65535]. For 32FC1 range is [0.0f:1.0f] 
    
  • Type CV_8UC3 - 3 channel color image

    // BLUE: color ordering as BGR
    Scalar color = new Scalar( 255, 0, 0 ) 
    
  • Type CV_8UC4 - color image with transparency

    //Transparent GREEN: BGRA with alpha range - [0 : 255]
    Scalar color = new Scalar( 0, 255, 0, 128 ) 
    

In the question, the first parameter to drawKeyPoints should be your source image(Mat) and not keypoints. The code would have compiled because MatOfKeyPoint is derived from Mat

like image 185
kiranpradeep Avatar answered Sep 25 '22 01:09

kiranpradeep