OpenCV - C++ - cv::Scalar

OpenCV - C++ - cv::Scalar

https://docs.opencv.org/4.2.0/dc/d84/group__core__basic.html

typedef Scalar_<double> cv::Scalar

Template class for a 4-element vector derived from Vec.
源自 Vec 的 4 元素向量的模板類。

Being derived from Vec<_Tp, 4>, Scalar_ and Scalar can be used just as typical 4-element vectors. In addition, they can be converted to/from CvScalar. The type Scalar is widely used in OpenCV to pass pixel values.
Vec<_Tp, 4> 派生而來,Scalar_ and Scalar 可以用作典型的 4 元素向量。另外,它們可以與 CvScalar 相互轉換。標量類型在 OpenCV 中廣泛用於傳遞像素值。

1. cv::Scalar - Open Declaration

template<typename _Tp> class Scalar_ : public Vec<_Tp, 4>
{
public:
    //! default constructor
    Scalar_();
    Scalar_(_Tp v0, _Tp v1, _Tp v2=0, _Tp v3=0);
    Scalar_(_Tp v0);

    Scalar_(const Scalar_& s);
    Scalar_(Scalar_&& s) CV_NOEXCEPT;

    Scalar_& operator=(const Scalar_& s);
    Scalar_& operator=(Scalar_&& s) CV_NOEXCEPT;

    template<typename _Tp2, int cn>
    Scalar_(const Vec<_Tp2, cn>& v);

    //! returns a scalar with all elements set to v0
    static Scalar_<_Tp> all(_Tp v0);

    //! conversion to another data type
    template<typename T2> operator Scalar_<T2>() const;

    //! per-element product
    Scalar_<_Tp> mul(const Scalar_<_Tp>& a, double scale=1 ) const;

    //! returns (v0, -v1, -v2, -v3)
    Scalar_<_Tp> conj() const;

    //! returns true iff v1 == v2 == v3 == 0
    bool isReal() const;
};

typedef Scalar_<double> Scalar;

2. Macros

#define CV_RGB(r, g, b) cv::Scalar((b), (g), (r), 0)

OpenCV color channel order is BGR[A]
OpenCV 顏色通道的順序爲 BGR [A]

3. Scalar(blue_component, green_component, red_component[,alpha_component])

Drawing functions work with matrices/images of arbitrary depth. The boundaries of the shapes can be rendered with antialiasing (implemented only for 8-bit images for now). All the functions include the parameter color that uses an RGB value (that may be constructed with the Scalar constructor) for color images and brightness for grayscale images. For color images, the channel ordering is normally Blue, Green, Red. This is what imshow, imread, and imwrite expect. So, if you form a color using the Scalar constructor, it should look like:
繪圖函數適用於任意深度的矩陣/圖像。可以使用抗鋸齒渲染形狀的邊界 (目前僅針對 8-bit 圖像實現)。所有功能都包括用於彩色圖像的 RGB 值參數 color (可以使用 Scalar 構造函數構造) 和用於灰度圖像的亮度。對於彩色圖像,通道順序通常爲 Blue, Green, Red。這正是 imshow, imread, and imwrite 的期望。因此,如果使用 Scalar 構造函數形成 color,則其外觀應類似於:

Scalar(blue_component, green_component, red_component[,alpha_component])

If you are using your own image rendering and I/O functions, you can use any channel ordering. The drawing functions process each channel independently and do not depend on the channel order or even on the used color space. The whole image can be converted from BGR to RGB or to a different color space using cvtColor.
如果使用自己的圖像渲染和 I/O 函數,則可以使用任何通道順序。繪圖函數獨立處理每個通道,並且不依賴於通道順序,甚至不依賴於所使用的色彩空間。整個圖像可以使用 cvtColorBGR 轉換爲 RGB 或不同的色彩空間。

If a drawn figure is partially or completely outside the image, the drawing functions clip it. Also, many drawing functions can handle pixel coordinates specified with sub-pixel accuracy. This means that the coordinates can be passed as fixed-point numbers encoded as integers. The number of fractional bits is specified by the shift parameter and the real point coordinates are calculated as Point(x,y)=>Point2f(x2shift,y2shift)\text{Point}(x, y) => \text{Point2f}(x ∗ 2^{-shift}, y ∗ 2^{-shift}). This feature is especially effective when rendering antialiased shapes.
如果繪製的圖形部分或全部位於圖像外部,則繪製功能會對其進行裁剪。同樣,許多繪圖功能可以處理以 sub-pixel 精度指定的像素座標。這意味着座標可以編碼爲整數的定點數傳遞。小數位數由 shift 參數指定,連同實點座標的計算方式爲 Point(x,y)=>Point2f(x2shift,y2shift)\text{Point}(x, y) => \text{Point2f}(x ∗ 2^{-shift}, y ∗ 2^{-shift})。渲染抗鋸齒形狀時,此功能特別有效。

The functions do not support alpha-transparency when the target image is 4-channel. In this case, the color[3] is simply copied to the repainted pixels. Thus, if you want to paint semi-transparent shapes, you can paint them in a separate buffer and then blend it with the main image.
當目標圖像爲 4 通道時,該功能不支持 alpha 透明。在這種情況下,僅將 color[3] 複製到重新繪製的像素。因此,如果要繪製半透明的形狀,可以在單獨的緩衝區中繪製它們,然後將其與主圖像混合。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章